session-android/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/MessageDetailActivity.kt

200 lines
7 KiB
Kotlin
Raw Normal View History

2021-07-13 08:22:10 +02:00
package org.thoughtcrime.securesms.conversation.v2
import android.os.Bundle
import android.view.View
2023-06-29 04:07:55 +02:00
import androidx.annotation.DrawableRes
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Card
import androidx.compose.material.Divider
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.google.accompanist.themeadapter.appcompat.AppCompatTheme
import dagger.hilt.android.AndroidEntryPoint
2021-07-13 08:22:10 +02:00
import network.loki.messenger.R
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.database.Storage
2021-07-13 08:22:10 +02:00
import org.thoughtcrime.securesms.database.model.MessageRecord
Paged conversation recycler, update compile sdk version 31 (#1049) * Update build tools * Update appcompat version * Update dependencies * feat: add paging into conversation recycler and queries to fetch data off-thread * refactor: wip for updating paged results and bucketing messages / fetching enough to display * fix: currently works for scrolling and possibly refreshing? need scroll to message and auto scroll down on insert (at bottom) * fix: search and scrolling to X message works now * build: increase version code and name * fix: re-add refresh, remove the outdated comment * refactor: lets see if 25 size pages increases performance :eyes: * feat: add in some equals overrides for mms records to refresh if media has finished DLing * feat: add scroll to bottom for new messages if we are at the end of the chat * build: update build numbers * fix: update AGP and fix compile errors for sdk version 31 * feat: add log for loki-avatar and loki-fs on upload types and responses * feat: increase build number to match latest installed version * feat: changing props and permission checks for call service * fix: possible service exception when no call ID remote foreground service not terminated * revert: google services version * fix: re-add paging dependency * feat: adding new last seen function and figuring out the last seen for recycler adapter * build: update version names and codes for deploy * refactor: undo the new adapter and query changes to use previous cursor logic. revert this commit to enable new paged adapter * fix: use author's address in typist equality and hashcode for set inclusion * refactor: refactor the select contacts activity * refactor: refactor the select contacts activity * build: update version code * fix: hide all other bound views if deleted * refactor: change voice message tint, upgrade build number * fix: message detail showing up properly * revert: realise copy public key is actually not allowed if open group participant * fix: copy session ID, message detail activity support re-enabled * build: update build version code * build: remove version name * build: update build code * feat: google services version minimum compatible * fix: selection for re-created objects not properly highlighting * fix: foreground CENTER_INSIDE instead of just CENTER for scaletype * build: update version code * fix: don't show error if no error * build: update version code * fix: clear error messages if any on successful send Co-authored-by: charles <charles@oxen.io>
2022-12-19 01:29:05 +01:00
import java.util.*
import javax.inject.Inject
2021-07-13 08:22:10 +02:00
@AndroidEntryPoint
2021-07-13 08:22:10 +02:00
class MessageDetailActivity: PassphraseRequiredActionBarActivity() {
var messageRecord: MessageRecord? = null
@Inject
lateinit var storage: Storage
2021-07-13 08:22:10 +02:00
// region Settings
companion object {
// Extras
const val MESSAGE_TIMESTAMP = "message_timestamp"
}
// endregion
override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) {
super.onCreate(savedInstanceState, ready)
2023-06-29 04:07:55 +02:00
2021-07-13 08:22:10 +02:00
val timestamp = intent.getLongExtra(MESSAGE_TIMESTAMP, -1L)
2023-06-29 04:07:55 +02:00
title = resources.getString(R.string.conversation_context__menu_message_details)
setContentView(createComposeView())
}
private fun createComposeView(): ComposeView = ComposeView(this).apply {
id = View.generateViewId()
setContent {
MessageDetails()
}
2023-06-29 04:07:55 +02:00
}
data class TitledText(val title: String, val value: String)
@OptIn(ExperimentalLayoutApi::class)
@Preview
@Composable
fun MessageDetails() {
val fileDetails = listOf(
TitledText("File Id:", "1237896548514214124235985214"),
TitledText("File Type:", ".PNG"),
TitledText("File Size:", "6mb"),
TitledText("Resolution:", "550x550"),
TitledText("Duration:", "N/A"),
)
val sent = TitledText("Sent:", "6:12 AM Tue, 09/08/2022 ")
val received = TitledText("Received:", "6:12 AM Tue, 09/08/2022 ")
val user = TitledText("Connor", "d4f1g54sdf5g1d5f4g65ds4564df65f4g65d54gdfsg")
AppCompatTheme {
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(16.dp)) {
CardWithPadding {
FlowRow(
verticalArrangement = Arrangement.spacedBy(16.dp),
maxItemsInEachRow = 2
) {
fileDetails.forEach {
titledText(it, Modifier.weight(1f))
}
}
}
CardWithPadding {
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
titledText(sent)
titledText(received)
titledView("From:") {
Row {
Box(modifier = Modifier.width(60.dp).height(60.dp))
Column {
titledText(user)
}
}
}
}
}
Card {
Column {
ItemButton("Reply", R.drawable.ic_reply)
Divider()
ItemButton("Resend", R.drawable.ic_reply)
Divider()
ItemButton("Delete", R.drawable.ic_delete_24, color = Color.Red)
}
}
}
2021-07-13 08:22:10 +02:00
}
}
2023-06-29 04:07:55 +02:00
@Composable
fun Divider() {
Divider(modifier = Modifier.padding(horizontal = 16.dp), thickness = 1.dp, color = Color(0xff414141))
}
@Composable
fun ItemButton(text: String, @DrawableRes icon: Int, color: Color = Color.White) {
TextButton(
modifier = Modifier
.fillMaxWidth()
.height(60.dp),
onClick = {},
shape = RectangleShape,
) {
Box(modifier = Modifier.width(80.dp).fillMaxHeight()) {
Icon(
painter = painterResource(id = icon),
contentDescription = "",
tint = color,
modifier = Modifier.align(Alignment.Center)
)
}
Text(text, color = color, modifier = Modifier.fillMaxWidth())
Paged conversation recycler, update compile sdk version 31 (#1049) * Update build tools * Update appcompat version * Update dependencies * feat: add paging into conversation recycler and queries to fetch data off-thread * refactor: wip for updating paged results and bucketing messages / fetching enough to display * fix: currently works for scrolling and possibly refreshing? need scroll to message and auto scroll down on insert (at bottom) * fix: search and scrolling to X message works now * build: increase version code and name * fix: re-add refresh, remove the outdated comment * refactor: lets see if 25 size pages increases performance :eyes: * feat: add in some equals overrides for mms records to refresh if media has finished DLing * feat: add scroll to bottom for new messages if we are at the end of the chat * build: update build numbers * fix: update AGP and fix compile errors for sdk version 31 * feat: add log for loki-avatar and loki-fs on upload types and responses * feat: increase build number to match latest installed version * feat: changing props and permission checks for call service * fix: possible service exception when no call ID remote foreground service not terminated * revert: google services version * fix: re-add paging dependency * feat: adding new last seen function and figuring out the last seen for recycler adapter * build: update version names and codes for deploy * refactor: undo the new adapter and query changes to use previous cursor logic. revert this commit to enable new paged adapter * fix: use author's address in typist equality and hashcode for set inclusion * refactor: refactor the select contacts activity * refactor: refactor the select contacts activity * build: update version code * fix: hide all other bound views if deleted * refactor: change voice message tint, upgrade build number * fix: message detail showing up properly * revert: realise copy public key is actually not allowed if open group participant * fix: copy session ID, message detail activity support re-enabled * build: update build version code * build: remove version name * build: update build code * feat: google services version minimum compatible * fix: selection for re-created objects not properly highlighting * fix: foreground CENTER_INSIDE instead of just CENTER for scaletype * build: update version code * fix: don't show error if no error * build: update version code * fix: clear error messages if any on successful send Co-authored-by: charles <charles@oxen.io>
2022-12-19 01:29:05 +01:00
}
2023-06-29 04:07:55 +02:00
}
2021-07-13 08:22:10 +02:00
2023-06-29 04:07:55 +02:00
@Composable
fun Card(content: @Composable () -> Unit) {
CardWithPadding(0.dp) { content() }
}
2021-07-13 08:22:10 +02:00
2023-06-29 04:07:55 +02:00
@Composable
fun CardWithPadding(padding: Dp = 24.dp, content: @Composable () -> Unit) {
Card(
shape = RoundedCornerShape(16.dp),
elevation = 0.dp,
modifier = Modifier
.wrapContentHeight()
.fillMaxWidth()
.padding(horizontal = 32.dp),
backgroundColor = Color(0xff1b1b1b),
contentColor = Color.White
) { Box(Modifier.padding(padding)) { content() } }
}
@Composable
fun titledText(titledText: TitledText, modifier: Modifier = Modifier) {
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(4.dp)) {
Title(titledText.title)
Text(titledText.value)
}
}
@Composable
fun titledView(title: String, modifier: Modifier = Modifier, content: @Composable () -> Unit) {
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(4.dp)) {
Title(title)
content()
2021-07-13 08:22:10 +02:00
}
}
2023-06-29 04:07:55 +02:00
@Composable
fun Title(text: String) {
Text(text, fontWeight = FontWeight.Bold)
}
2021-07-13 08:22:10 +02:00
}