From fbb217273919e493ae655d03ef2419820ac26b6a Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 21 Jul 2023 11:50:42 +0930 Subject: [PATCH] Fix buttons --- .../conversation/v2/MessageDetailActivity.kt | 6 +-- .../v2/MessageDetailsViewModel.kt | 48 ++++++++++--------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt index 0ce83f9afa..61732827f3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt @@ -80,8 +80,6 @@ import javax.inject.Inject @AndroidEntryPoint class MessageDetailActivity : PassphraseRequiredActionBarActivity() { - private var timestamp: Long = 0L - @Inject lateinit var storage: Storage @@ -101,7 +99,7 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() { title = resources.getString(R.string.conversation_context__menu_message_details) - intent.getLongExtra(MESSAGE_TIMESTAMP, -1L).let(viewModel::setMessageTimestamp) + viewModel.timestamp = intent.getLongExtra(MESSAGE_TIMESTAMP, -1L) ComposeView(this) .apply { setContent { MessageDetailsScreen() } } @@ -135,7 +133,7 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() { } private fun setResultAndFinish(code: Int) { - Bundle().apply { putLong(MESSAGE_TIMESTAMP, timestamp) } + Bundle().apply { putLong(MESSAGE_TIMESTAMP, viewModel.timestamp) } .let(Intent()::putExtras) .let { setResult(code, it) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailsViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailsViewModel.kt index 7f97645b69..a73fe41139 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailsViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailsViewModel.kt @@ -46,32 +46,34 @@ class MessageDetailsViewModel @Inject constructor( private val event = Channel() val eventFlow = event.receiveAsFlow() - fun setMessageTimestamp(timestamp: Long) { - val record = mmsSmsDatabase.getMessageForTimestamp(timestamp) + var timestamp: Long = 0L + set(value) { + field = value + val record = mmsSmsDatabase.getMessageForTimestamp(timestamp) - if (record == null) { - viewModelScope.launch { event.send(Event.Finish) } - return + if (record == null) { + viewModelScope.launch { event.send(Event.Finish) } + return + } + + val mmsRecord = record as? MmsMessageRecord + + state.value = record.run { + val slides = mmsRecord?.slideDeck?.slides ?: emptyList() + + MessageDetailsState( + attachments = slides.map(::Attachment), + record = record, + sent = dateSent.let(::Date).toString().let { TitledText(R.string.message_details_header__sent, it) }, + received = dateReceived.let(::Date).toString().let { TitledText(R.string.message_details_header__received, it) }, + error = lokiMessageDatabase.getErrorMessage(id)?.let { TitledText(R.string.message_details_header__error, it) }, + senderInfo = individualRecipient.run { name?.let { TitledText(it, address.serialize()) } }, + sender = individualRecipient, + thread = threadDb.getRecipientForThreadId(threadId)!!, + ) + } } - val mmsRecord = record as? MmsMessageRecord - - state.value = record.run { - val slides = mmsRecord?.slideDeck?.slides ?: emptyList() - - MessageDetailsState( - attachments = slides.map(::Attachment), - record = record, - sent = dateSent.let(::Date).toString().let { TitledText(R.string.message_details_header__sent, it) }, - received = dateReceived.let(::Date).toString().let { TitledText(R.string.message_details_header__received, it) }, - error = lokiMessageDatabase.getErrorMessage(id)?.let { TitledText(R.string.message_details_header__error, it) }, - senderInfo = individualRecipient.run { name?.let { TitledText(it, address.serialize()) } }, - sender = individualRecipient, - thread = threadDb.getRecipientForThreadId(threadId)!!, - ) - } - } - private val Slide.details: List get() = listOfNotNull( fileName.orNull()?.let { TitledText(R.string.message_details_header__file_id, it) },