mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-21 01:41:31 +00:00
Cleanup
This commit is contained in:
parent
ee0141f82d
commit
6209ae68a8
@ -29,7 +29,6 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.ComposeView
|
import androidx.compose.ui.platform.ComposeView
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
@ -80,8 +79,6 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
|
|
||||||
private var timestamp: Long = 0L
|
private var timestamp: Long = 0L
|
||||||
|
|
||||||
var messageRecord: MessageRecord? = null
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var storage: Storage
|
lateinit var storage: Storage
|
||||||
|
|
||||||
@ -165,24 +162,22 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
|
|
||||||
timestamp = intent.getLongExtra(MESSAGE_TIMESTAMP, -1L)
|
timestamp = intent.getLongExtra(MESSAGE_TIMESTAMP, -1L)
|
||||||
|
|
||||||
messageRecord =
|
val messageRecord =
|
||||||
DatabaseComponent.get(this).mmsSmsDatabase().getMessageForTimestamp(timestamp) ?: run {
|
DatabaseComponent.get(this).mmsSmsDatabase().getMessageForTimestamp(timestamp) ?: run {
|
||||||
finish()
|
finish()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val error = DatabaseComponent.get(this).lokiMessageDatabase()
|
val error = DatabaseComponent.get(this).lokiMessageDatabase()
|
||||||
.getErrorMessage(messageRecord!!.getId())
|
.getErrorMessage(messageRecord.getId())
|
||||||
|
|
||||||
viewModel.setMessageRecord(messageRecord, error)
|
viewModel.setMessageRecord(messageRecord, error)
|
||||||
|
|
||||||
title = resources.getString(R.string.conversation_context__menu_message_details)
|
title = resources.getString(R.string.conversation_context__menu_message_details)
|
||||||
|
|
||||||
setContentView(ComposeView(this).apply {
|
ComposeView(this)
|
||||||
setContent {
|
.apply { setContent { MessageDetailsScreen() } }
|
||||||
MessageDetailsScreen()
|
.let(::setContentView)
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -255,20 +250,36 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
) {
|
) {
|
||||||
Attachments(attachments) { onClickImage(it) }
|
Attachments(attachments) { onClickImage(it) }
|
||||||
if (sent != null || received != null || senderInfo != null) CellWithPaddingAndMargin {
|
MetaDataCell(messageDetails)
|
||||||
|
Buttons(
|
||||||
|
error != null,
|
||||||
|
onReply,
|
||||||
|
onResend,
|
||||||
|
onDelete,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun MetaDataCell(
|
||||||
|
messageDetails: MessageDetails,
|
||||||
|
) {
|
||||||
|
if (messageDetails.sent != null || messageDetails.received != null || messageDetails.senderInfo != null) CellWithPaddingAndMargin {
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
|
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||||
sent?.let { titledText(it) }
|
messageDetails.sent?.let { TitledText(it) }
|
||||||
received?.let { titledText(it) }
|
messageDetails.received?.let { TitledText(it) }
|
||||||
error?.let {
|
messageDetails.error?.let {
|
||||||
titledText(
|
TitledText(
|
||||||
it,
|
it,
|
||||||
valueStyle = LocalTextStyle.current.copy(color = colorDestructive)
|
valueStyle = LocalTextStyle.current.copy(color = colorDestructive)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
senderInfo?.let {
|
messageDetails.senderInfo?.let {
|
||||||
titledView("From:") {
|
TitledView("From:") {
|
||||||
Row {
|
Row {
|
||||||
sender?.let {
|
messageDetails.sender?.let { sender ->
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(60.dp)
|
.width(60.dp)
|
||||||
@ -276,20 +287,14 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
) {
|
) {
|
||||||
AndroidView(
|
AndroidView(
|
||||||
factory = {
|
factory = {
|
||||||
ProfilePictureView(it).apply {
|
ProfilePictureView(it).apply { update(sender) }
|
||||||
update(
|
|
||||||
sender
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier.width(46.dp).height(46.dp)
|
||||||
.width(46.dp)
|
|
||||||
.height(46.dp)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Column {
|
Column {
|
||||||
titledText(
|
TitledText(
|
||||||
it,
|
it,
|
||||||
valueStyle = LocalTextStyle.current.copy(fontFamily = FontFamily.Monospace)
|
valueStyle = LocalTextStyle.current.copy(fontFamily = FontFamily.Monospace)
|
||||||
)
|
)
|
||||||
@ -299,15 +304,6 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Buttons(
|
|
||||||
messageDetails.error != null,
|
|
||||||
onReply,
|
|
||||||
onResend,
|
|
||||||
onDelete,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -347,13 +343,13 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
fun Attachments(attachments: List<Attachment>, onClick: (Slide) -> Unit) {
|
fun Attachments(attachments: List<Attachment>, onClick: (Slide) -> Unit) {
|
||||||
val slide = attachments.firstOrNull()?.slide ?: return
|
val slide = attachments.firstOrNull()?.slide ?: return
|
||||||
when {
|
when {
|
||||||
slide.hasImage() -> ImageAttachments(attachments) { onClick(it) }
|
slide.hasImage() -> Carousel(attachments, onClick)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class,)
|
@OptIn(ExperimentalFoundationApi::class,)
|
||||||
@Composable
|
@Composable
|
||||||
fun ImageAttachments(attachments: List<Attachment>, onClick: (Slide) -> Unit) {
|
fun Carousel(attachments: List<Attachment>, onClick: (Slide) -> Unit) {
|
||||||
val imageAttachments = attachments.filter { it.slide.hasImage() }
|
val imageAttachments = attachments.filter { it.slide.hasImage() }
|
||||||
val pagerState = rememberPagerState { imageAttachments.size }
|
val pagerState = rememberPagerState { imageAttachments.size }
|
||||||
|
|
||||||
@ -361,7 +357,7 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
Row {
|
Row {
|
||||||
CarouselPrevButton(pagerState)
|
CarouselPrevButton(pagerState)
|
||||||
Box(modifier = Modifier.weight(1f)) {
|
Box(modifier = Modifier.weight(1f)) {
|
||||||
CellPager(pagerState, imageAttachments) { onClick(it) }
|
CellPager(pagerState, imageAttachments, onClick)
|
||||||
HorizontalPagerIndicator(pagerState)
|
HorizontalPagerIndicator(pagerState)
|
||||||
ExpandButton(modifier = Modifier.align(Alignment.BottomEnd).padding(8.dp))
|
ExpandButton(modifier = Modifier.align(Alignment.BottomEnd).padding(8.dp))
|
||||||
}
|
}
|
||||||
@ -415,14 +411,14 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
maxItemsInEachRow = 2
|
maxItemsInEachRow = 2
|
||||||
) {
|
) {
|
||||||
it.forEach { titledText(it, Modifier.weight(1f)) }
|
it.forEach { TitledText(it, Modifier.weight(1f)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun titledText(
|
fun TitledText(
|
||||||
titledText: TitledText,
|
titledText: TitledText,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
valueStyle: TextStyle = LocalTextStyle.current
|
valueStyle: TextStyle = LocalTextStyle.current
|
||||||
@ -434,7 +430,7 @@ class MessageDetailActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun titledView(title: String, modifier: Modifier = Modifier, content: @Composable () -> Unit) {
|
fun TitledView(title: String, modifier: Modifier = Modifier, content: @Composable () -> Unit) {
|
||||||
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||||
Title(title)
|
Title(title)
|
||||||
content()
|
content()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user