Fix buttons

This commit is contained in:
andrew 2023-07-21 11:50:42 +09:30
parent d0415c5bf1
commit fbb2172739
2 changed files with 27 additions and 27 deletions

View File

@ -80,8 +80,6 @@ import javax.inject.Inject
@AndroidEntryPoint @AndroidEntryPoint
class MessageDetailActivity : PassphraseRequiredActionBarActivity() { class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
private var timestamp: Long = 0L
@Inject @Inject
lateinit var storage: Storage lateinit var storage: Storage
@ -101,7 +99,7 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
title = resources.getString(R.string.conversation_context__menu_message_details) 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) ComposeView(this)
.apply { setContent { MessageDetailsScreen() } } .apply { setContent { MessageDetailsScreen() } }
@ -135,7 +133,7 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
} }
private fun setResultAndFinish(code: Int) { private fun setResultAndFinish(code: Int) {
Bundle().apply { putLong(MESSAGE_TIMESTAMP, timestamp) } Bundle().apply { putLong(MESSAGE_TIMESTAMP, viewModel.timestamp) }
.let(Intent()::putExtras) .let(Intent()::putExtras)
.let { setResult(code, it) } .let { setResult(code, it) }

View File

@ -46,32 +46,34 @@ class MessageDetailsViewModel @Inject constructor(
private val event = Channel<Event>() private val event = Channel<Event>()
val eventFlow = event.receiveAsFlow() val eventFlow = event.receiveAsFlow()
fun setMessageTimestamp(timestamp: Long) { var timestamp: Long = 0L
val record = mmsSmsDatabase.getMessageForTimestamp(timestamp) set(value) {
field = value
val record = mmsSmsDatabase.getMessageForTimestamp(timestamp)
if (record == null) { if (record == null) {
viewModelScope.launch { event.send(Event.Finish) } viewModelScope.launch { event.send(Event.Finish) }
return 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<TitledText> private val Slide.details: List<TitledText>
get() = listOfNotNull( get() = listOfNotNull(
fileName.orNull()?.let { TitledText(R.string.message_details_header__file_id, it) }, fileName.orNull()?.let { TitledText(R.string.message_details_header__file_id, it) },