Handle app locking for threads too

This commit is contained in:
Ensar Sarajčić 2023-06-30 10:55:30 +02:00
parent ae2e480876
commit 8675de70c2
2 changed files with 61 additions and 17 deletions

View File

@ -445,6 +445,7 @@ class MainActivity : SimpleActivity() {
val conversation = any as Conversation
putExtra(THREAD_ID, conversation.threadId)
putExtra(THREAD_TITLE, conversation.title)
putExtra(WAS_PROTECTION_HANDLED, wasProtectionHandled)
startActivity(this)
}
}

View File

@ -101,6 +101,7 @@ class ThreadActivity : SimpleActivity() {
private var loadingOlderMessages = false
private var allMessagesFetched = false
private var oldestMessageDate = -1
private var wasProtectionHandled = false
private var isScheduledMessage: Boolean = false
private var scheduledMessage: Message? = null
@ -136,30 +137,25 @@ class ThreadActivity : SimpleActivity() {
intent.getStringExtra(THREAD_TITLE)?.let {
thread_toolbar.title = it
}
wasProtectionHandled = intent.getBooleanExtra(WAS_PROTECTION_HANDLED, false)
bus = EventBus.getDefault()
bus!!.register(this)
handlePermission(PERMISSION_READ_PHONE_STATE) { granted ->
if (granted) {
setupButtons()
setupConversation()
setupCachedMessages {
val searchedMessageId = intent.getLongExtra(SEARCHED_MESSAGE_ID, -1L)
intent.removeExtra(SEARCHED_MESSAGE_ID)
if (searchedMessageId != -1L) {
val index = threadItems.indexOfFirst { (it as? Message)?.id == searchedMessageId }
if (index != -1) {
thread_messages_list.smoothScrollToPosition(index)
}
}
setupThread()
setupScrollFab()
}
if (savedInstanceState == null) {
if (!wasProtectionHandled) {
handleAppPasswordProtection {
wasProtectionHandled = it
if (it) {
loadConversation()
} else {
finish()
}
}
} else {
loadConversation()
}
}
setupAttachmentPickerView()
setupKeyboardListener()
@ -221,6 +217,29 @@ class ThreadActivity : SimpleActivity() {
bus?.unregister(this)
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putBoolean(WAS_PROTECTION_HANDLED, wasProtectionHandled)
}
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
wasProtectionHandled = savedInstanceState.getBoolean(WAS_PROTECTION_HANDLED, false)
if (!wasProtectionHandled) {
handleAppPasswordProtection {
wasProtectionHandled = it
if (it) {
loadConversation()
} else {
finish()
}
}
} else {
loadConversation()
}
}
private fun refreshMenuItems() {
val firstPhoneNumber = participants.firstOrNull()?.phoneNumbers?.firstOrNull()?.value
thread_toolbar.menu.apply {
@ -546,6 +565,30 @@ class ThreadActivity : SimpleActivity() {
}
}
private fun loadConversation() {
handlePermission(PERMISSION_READ_PHONE_STATE) { granted ->
if (granted) {
setupButtons()
setupConversation()
setupCachedMessages {
val searchedMessageId = intent.getLongExtra(SEARCHED_MESSAGE_ID, -1L)
intent.removeExtra(SEARCHED_MESSAGE_ID)
if (searchedMessageId != -1L) {
val index = threadItems.indexOfFirst { (it as? Message)?.id == searchedMessageId }
if (index != -1) {
thread_messages_list.smoothScrollToPosition(index)
}
}
setupThread()
setupScrollFab()
}
} else {
finish()
}
}
}
private fun setupConversation() {
ensureBackgroundThread {
conversation = conversationsDB.getConversationWithThreadId(threadId)