Exit on pressing Back

This commit is contained in:
Agnieszka C 2021-10-19 16:33:49 +02:00
parent cce617b12f
commit 21365e3b96
4 changed files with 22 additions and 4 deletions

View File

@ -23,10 +23,7 @@ import com.simplemobiletools.smsmessenger.adapters.ConversationsAdapter
import com.simplemobiletools.smsmessenger.dialogs.ExportMessagesDialog
import com.simplemobiletools.smsmessenger.dialogs.ImportMessagesDialog
import com.simplemobiletools.smsmessenger.extensions.*
import com.simplemobiletools.smsmessenger.helpers.EXPORT_MIME_TYPE
import com.simplemobiletools.smsmessenger.helpers.MessagesExporter
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
import com.simplemobiletools.smsmessenger.helpers.THREAD_TITLE
import com.simplemobiletools.smsmessenger.helpers.*
import com.simplemobiletools.smsmessenger.models.Conversation
import com.simplemobiletools.smsmessenger.models.Events
import kotlinx.android.synthetic.main.activity_main.*
@ -84,6 +81,11 @@ class MainActivity : SimpleActivity() {
override fun onResume() {
super.onResume()
if (intent.getBooleanExtra(EXIT, false)) {
finish()
return
}
if (storedTextColor != config.textColor) {
(conversations_list.adapter as? ConversationsAdapter)?.updateTextColor(config.textColor)
}

View File

@ -179,6 +179,18 @@ class ThreadActivity : SimpleActivity() {
finish()
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_BACK && intent.getBooleanExtra(FROM_NOTIFICATION, false)) {
val intent = Intent(this@ThreadActivity, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
putExtra(EXIT, true)
}
startActivity(intent)
finish()
}
return super.onKeyDown(keyCode, event)
}
private fun setupCachedMessages(callback: () -> Unit) {
ensureBackgroundThread {
messages = try {

View File

@ -711,6 +711,7 @@ fun Context.showMessageNotification(address: String, body: String, threadId: Lon
val intent = Intent(this, ThreadActivity::class.java).apply {
putExtra(THREAD_ID, threadId)
putExtra(FROM_NOTIFICATION, true)
}
val pendingIntent = PendingIntent.getActivity(this, threadId.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT)

View File

@ -26,6 +26,9 @@ const val EXPORT_FILE_EXT = ".json"
const val IMPORT_SMS = "import_sms"
const val IMPORT_MMS = "import_mms"
const val EXIT = "EXIT"
const val FROM_NOTIFICATION = "FROM_NOTIFICATION"
private const val PATH = "com.simplemobiletools.smsmessenger.action."
const val MARK_AS_READ = PATH + "mark_as_read"
const val REPLY = PATH + "reply"