mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 22:03:54 +00:00
Add click listeners
This commit is contained in:
parent
ac476f4382
commit
676c29ca60
@ -1,5 +1,7 @@
|
|||||||
package org.thoughtcrime.securesms.conversation.v2
|
package org.thoughtcrime.securesms.conversation.v2
|
||||||
|
|
||||||
|
import android.accounts.AccountManager
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
@ -10,7 +12,6 @@ import androidx.compose.foundation.layout.Row
|
|||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.Divider
|
import androidx.compose.material.Divider
|
||||||
@ -31,9 +32,12 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
|
import org.session.libsession.utilities.Address
|
||||||
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||||
import org.thoughtcrime.securesms.database.Storage
|
import org.thoughtcrime.securesms.database.Storage
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||||
|
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
||||||
import org.thoughtcrime.securesms.ui.AppTheme
|
import org.thoughtcrime.securesms.ui.AppTheme
|
||||||
import org.thoughtcrime.securesms.ui.Cell
|
import org.thoughtcrime.securesms.ui.Cell
|
||||||
import org.thoughtcrime.securesms.ui.CellWithPadding
|
import org.thoughtcrime.securesms.ui.CellWithPadding
|
||||||
@ -46,22 +50,53 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MessageDetailActivity: PassphraseRequiredActionBarActivity() {
|
class MessageDetailActivity: PassphraseRequiredActionBarActivity() {
|
||||||
|
|
||||||
|
private var timestamp: Long = 0L
|
||||||
|
|
||||||
var messageRecord: MessageRecord? = null
|
var messageRecord: MessageRecord? = null
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var storage: Storage
|
lateinit var storage: Storage
|
||||||
|
|
||||||
// region Settings
|
|
||||||
companion object {
|
companion object {
|
||||||
// Extras
|
// Extras
|
||||||
const val MESSAGE_TIMESTAMP = "message_timestamp"
|
const val MESSAGE_TIMESTAMP = "message_timestamp"
|
||||||
|
|
||||||
|
const val ON_REPLY = 1
|
||||||
|
const val ON_RESEND = 2
|
||||||
|
const val ON_DELETE = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
val viewModel = MessageDetailsViewModel()
|
||||||
|
|
||||||
|
class MessageDetailsViewModel: ViewModel() {
|
||||||
|
|
||||||
|
fun setMessageRecord(value: MessageRecord?) {
|
||||||
|
_details.value = value?.run {
|
||||||
|
MessageDetails(
|
||||||
|
sent = dateSent.let(::Date).toString().let { TitledText("Sent:", it) },
|
||||||
|
received = dateReceived.let(::Date).toString().let { TitledText("Received:", it) },
|
||||||
|
user = null
|
||||||
|
)
|
||||||
|
} ?: MessageDetails()
|
||||||
|
}
|
||||||
|
|
||||||
|
private var _details = MutableLiveData(MessageDetails())
|
||||||
|
val details: LiveData<MessageDetails> = _details
|
||||||
}
|
}
|
||||||
// endregion
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) {
|
override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) {
|
||||||
super.onCreate(savedInstanceState, ready)
|
super.onCreate(savedInstanceState, ready)
|
||||||
|
|
||||||
val timestamp = intent.getLongExtra(MESSAGE_TIMESTAMP, -1L)
|
timestamp = intent.getLongExtra(MESSAGE_TIMESTAMP, -1L)
|
||||||
|
|
||||||
|
val author = Address.fromSerialized(TextSecurePreferences.getLocalNumber(this)!!)
|
||||||
|
messageRecord = DatabaseComponent.get(this).mmsSmsDatabase().getMessageFor(timestamp, author) ?: run {
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel.setMessageRecord(messageRecord)
|
||||||
|
|
||||||
title = resources.getString(R.string.conversation_context__menu_message_details)
|
title = resources.getString(R.string.conversation_context__menu_message_details)
|
||||||
|
|
||||||
@ -72,15 +107,25 @@ class MessageDetailActivity: PassphraseRequiredActionBarActivity() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessageDetailsViewModel: ViewModel() {
|
@Composable
|
||||||
private val _details = MutableLiveData(MessageDetails())
|
private fun MessageDetailsScreen() {
|
||||||
val details: LiveData<MessageDetails> = _details
|
val details by viewModel.details.observeAsState(MessageDetails())
|
||||||
|
MessageDetails(
|
||||||
|
details,
|
||||||
|
onReply = { setResultAndFinish(ON_REPLY) },
|
||||||
|
onResend = { setResultAndFinish(ON_RESEND) },
|
||||||
|
onDelete = { setResultAndFinish(ON_DELETE) }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
private fun setResultAndFinish(code: Int) {
|
||||||
private fun MessageDetailsScreen(viewModel: MessageDetailsViewModel = MessageDetailsViewModel()) {
|
setResult(code)
|
||||||
val details by viewModel.details.observeAsState(MessageDetails())
|
|
||||||
MessageDetails(details)
|
Bundle().apply { putLong(MESSAGE_TIMESTAMP, timestamp) }
|
||||||
|
.let(Intent()::putExtras)
|
||||||
|
.let { setResult(RESULT_OK, it) }
|
||||||
|
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
data class TitledText(val title: String, val value: String)
|
data class TitledText(val title: String, val value: String)
|
||||||
@ -111,7 +156,12 @@ class MessageDetailActivity: PassphraseRequiredActionBarActivity() {
|
|||||||
|
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun MessageDetails(messageDetails: MessageDetails) {
|
fun MessageDetails(
|
||||||
|
messageDetails: MessageDetails,
|
||||||
|
onReply: () -> Unit = {},
|
||||||
|
onResend: () -> Unit = {},
|
||||||
|
onDelete: () -> Unit = {},
|
||||||
|
) {
|
||||||
messageDetails.apply {
|
messageDetails.apply {
|
||||||
AppTheme {
|
AppTheme {
|
||||||
Column(
|
Column(
|
||||||
@ -150,14 +200,15 @@ class MessageDetailActivity: PassphraseRequiredActionBarActivity() {
|
|||||||
}
|
}
|
||||||
Cell {
|
Cell {
|
||||||
Column {
|
Column {
|
||||||
ItemButton("Reply", R.drawable.ic_message_details__reply)
|
ItemButton("Reply", R.drawable.ic_message_details__reply, onClick = onReply)
|
||||||
Divider()
|
Divider()
|
||||||
ItemButton("Resend", R.drawable.ic_message_details__refresh)
|
ItemButton("Resend", R.drawable.ic_message_details__refresh, onClick = onResend)
|
||||||
Divider()
|
Divider()
|
||||||
ItemButton(
|
ItemButton(
|
||||||
"Delete",
|
"Delete",
|
||||||
R.drawable.ic_message_details__trash,
|
R.drawable.ic_message_details__trash,
|
||||||
colors = destructiveButtonColors()
|
colors = destructiveButtonColors(),
|
||||||
|
onClick = onDelete
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,13 +28,14 @@ fun ItemButton(
|
|||||||
text: String,
|
text: String,
|
||||||
@DrawableRes icon: Int,
|
@DrawableRes icon: Int,
|
||||||
colors: ButtonColors = transparentButtonColors(),
|
colors: ButtonColors = transparentButtonColors(),
|
||||||
|
onClick: () -> Unit
|
||||||
) {
|
) {
|
||||||
TextButton(
|
TextButton(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(60.dp),
|
.height(60.dp),
|
||||||
colors = colors,
|
colors = colors,
|
||||||
onClick = {},
|
onClick = onClick,
|
||||||
shape = RectangleShape,
|
shape = RectangleShape,
|
||||||
) {
|
) {
|
||||||
Box(modifier = Modifier
|
Box(modifier = Modifier
|
||||||
|
Loading…
x
Reference in New Issue
Block a user