2020-05-11 08:19:26 +02:00
|
|
|
package org.thoughtcrime.securesms.loki.utilities
|
2019-12-16 21:13:10 +01:00
|
|
|
|
2021-06-25 08:30:23 +02:00
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.app.Activity
|
|
|
|
import android.content.Context
|
2019-12-17 15:15:13 +01:00
|
|
|
import android.content.Intent
|
2021-06-25 08:30:23 +02:00
|
|
|
import android.os.Bundle
|
2020-09-18 08:54:40 +02:00
|
|
|
import android.view.View
|
2020-08-19 02:06:26 +02:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2020-09-18 08:54:40 +02:00
|
|
|
import androidx.appcompat.widget.Toolbar
|
2019-12-16 21:13:10 +01:00
|
|
|
import network.loki.messenger.R
|
2020-09-18 08:54:40 +02:00
|
|
|
import org.thoughtcrime.securesms.BaseActionBarActivity
|
2021-07-09 07:13:43 +02:00
|
|
|
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
2019-12-16 21:13:10 +01:00
|
|
|
|
2020-09-18 08:54:40 +02:00
|
|
|
fun BaseActionBarActivity.setUpActionBarSessionLogo(hideBackButton: Boolean = false) {
|
|
|
|
val actionbar = supportActionBar!!
|
|
|
|
|
|
|
|
actionbar.setDisplayShowHomeEnabled(false)
|
|
|
|
actionbar.setDisplayShowTitleEnabled(false)
|
|
|
|
actionbar.setDisplayHomeAsUpEnabled(false)
|
|
|
|
actionbar.setHomeButtonEnabled(false)
|
|
|
|
|
|
|
|
actionbar.setCustomView(R.layout.session_logo_action_bar_content)
|
|
|
|
actionbar.setDisplayShowCustomEnabled(true)
|
|
|
|
|
|
|
|
val rootView: Toolbar = actionbar.customView!!.parent as Toolbar
|
|
|
|
rootView.setPadding(0,0,0,0)
|
|
|
|
rootView.setContentInsetsAbsolute(0,0);
|
|
|
|
|
|
|
|
val backButton = actionbar.customView!!.findViewById<View>(R.id.back_button)
|
|
|
|
if (hideBackButton) {
|
|
|
|
backButton.visibility = View.GONE
|
|
|
|
} else {
|
|
|
|
backButton.visibility = View.VISIBLE
|
|
|
|
backButton.setOnClickListener {
|
|
|
|
onSupportNavigateUp()
|
|
|
|
}
|
|
|
|
}
|
2019-12-17 15:15:13 +01:00
|
|
|
}
|
|
|
|
|
2020-03-17 01:43:12 +01:00
|
|
|
val AppCompatActivity.defaultSessionRequestCode: Int
|
|
|
|
get() = 42
|
|
|
|
|
2020-01-08 05:16:34 +01:00
|
|
|
fun AppCompatActivity.push(intent: Intent, isForResult: Boolean = false) {
|
|
|
|
if (isForResult) {
|
2020-03-17 01:43:12 +01:00
|
|
|
startActivityForResult(intent, defaultSessionRequestCode)
|
2020-01-08 05:16:34 +01:00
|
|
|
} else {
|
|
|
|
startActivity(intent)
|
|
|
|
}
|
2019-12-17 15:15:13 +01:00
|
|
|
overridePendingTransition(R.anim.slide_from_right, R.anim.fade_scale_out)
|
2020-01-08 05:16:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun AppCompatActivity.show(intent: Intent, isForResult: Boolean = false) {
|
|
|
|
if (isForResult) {
|
2020-03-17 01:43:12 +01:00
|
|
|
startActivityForResult(intent, defaultSessionRequestCode)
|
2020-01-08 05:16:34 +01:00
|
|
|
} else {
|
|
|
|
startActivity(intent)
|
|
|
|
}
|
|
|
|
overridePendingTransition(R.anim.slide_from_bottom, R.anim.fade_scale_out)
|
2021-06-25 08:30:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface ActivityDispatcher {
|
|
|
|
companion object {
|
|
|
|
const val SERVICE = "ActivityDispatcher_SERVICE"
|
|
|
|
@SuppressLint("WrongConstant")
|
|
|
|
fun get(context: Context) = context.getSystemService(SERVICE) as? ActivityDispatcher
|
|
|
|
}
|
2021-06-28 01:59:33 +02:00
|
|
|
fun dispatchIntent(body: (Context)->Intent?)
|
2021-07-09 07:13:43 +02:00
|
|
|
fun showDialog(baseDialog: BaseDialog, tag: String? = null)
|
2019-12-16 21:13:10 +01:00
|
|
|
}
|