Add icons and respect nullability

This commit is contained in:
andrew 2023-06-29 22:11:15 +09:30
parent d5b3d9bcf9
commit ac476f4382
5 changed files with 116 additions and 52 deletions

View File

@ -164,6 +164,8 @@ dependencies {
implementation 'androidx.compose.ui:ui:1.4.3'
implementation 'androidx.compose.ui:ui-tooling:1.4.3'
implementation "com.google.accompanist:accompanist-themeadapter-appcompat:0.30.1"
implementation "androidx.compose.runtime:runtime-livedata:1.4.3"
implementation 'androidx.compose.foundation:foundation-layout:1.5.0-alpha02'
implementation 'androidx.compose.material:material:1.5.0-alpha02'

View File

@ -1,7 +1,6 @@
package org.thoughtcrime.securesms.conversation.v2
import android.os.Bundle
import android.view.View
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@ -11,12 +10,15 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Divider
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.text.TextStyle
@ -24,6 +26,9 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import dagger.hilt.android.AndroidEntryPoint
import network.loki.messenger.R
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
@ -60,71 +65,101 @@ class MessageDetailActivity: PassphraseRequiredActionBarActivity() {
title = resources.getString(R.string.conversation_context__menu_message_details)
setContentView(createComposeView())
setContentView(ComposeView(this).apply {
setContent {
MessageDetailsScreen()
}
})
}
private fun createComposeView(): ComposeView = ComposeView(this).apply {
id = View.generateViewId()
setContent {
MessageDetails()
}
class MessageDetailsViewModel: ViewModel() {
private val _details = MutableLiveData(MessageDetails())
val details: LiveData<MessageDetails> = _details
}
@Composable
private fun MessageDetailsScreen(viewModel: MessageDetailsViewModel = MessageDetailsViewModel()) {
val details by viewModel.details.observeAsState(MessageDetails())
MessageDetails(details)
}
data class TitledText(val title: String, val value: String)
@OptIn(ExperimentalLayoutApi::class)
data class MessageDetails(
val fileDetails: List<TitledText>? = null,
val sent: TitledText? = null,
val received: TitledText? = null,
val user: TitledText? = null,
)
@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"),
fun PreviewMessageDetails() {
MessageDetails(
fileDetails = listOf(
TitledText("File Id:", "1237896548514214124235985214"),
TitledText("File Type:", ".PNG"),
TitledText("File Size:", "6mb"),
TitledText("Resolution:", "550x550"),
TitledText("Duration:", "N/A"),
),
sent = TitledText("Sent:", "6:12 AM Tue, 09/08/2022"),
received = TitledText("Received:", "6:12 AM Tue, 09/08/2022"),
user = TitledText("Connor", "d4f1g54sdf5g1d5f4g65ds4564df65f4g65d54gdfsg")
)
}
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")
AppTheme {
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(16.dp)) {
CellWithPadding {
FlowRow(
verticalArrangement = Arrangement.spacedBy(16.dp),
maxItemsInEachRow = 2
) {
fileDetails.forEach {
titledText(it, Modifier.weight(1f))
}
}
}
CellWithPadding {
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, valueStyle = LocalTextStyle.current.copy(fontFamily = FontFamily.Monospace))
@OptIn(ExperimentalLayoutApi::class)
@Composable
fun MessageDetails(messageDetails: MessageDetails) {
messageDetails.apply {
AppTheme {
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
fileDetails?.takeIf { it.isNotEmpty() }?.let {
CellWithPadding {
FlowRow(
verticalArrangement = Arrangement.spacedBy(16.dp),
maxItemsInEachRow = 2
) {
it.forEach {
titledText(it, Modifier.weight(1f))
}
}
}
}
}
Cell {
Column {
ItemButton("Reply", R.drawable.ic_reply)
Divider()
ItemButton("Resend", R.drawable.ic_reply)
Divider()
ItemButton("Delete", R.drawable.ic_delete_24 , colors = destructiveButtonColors())
if (sent != null || received != null || user != null) CellWithPadding {
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
sent?.let { titledText(it) }
received?.let { titledText(it) }
user?.let {
titledView("From:") {
Row {
Box(modifier = Modifier
.width(60.dp)
.height(60.dp))
Column {
titledText(it, valueStyle = LocalTextStyle.current.copy(fontFamily = FontFamily.Monospace))
}
}
}
}
}
}
Cell {
Column {
ItemButton("Reply", R.drawable.ic_message_details__reply)
Divider()
ItemButton("Resend", R.drawable.ic_message_details__refresh)
Divider()
ItemButton(
"Delete",
R.drawable.ic_message_details__trash,
colors = destructiveButtonColors()
)
}
}
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="21dp"
android:viewportWidth="26"
android:viewportHeight="21">
<path
android:pathData="M13.468,20.291C15.669,20.291 17.795,19.548 19.307,18.33C20.22,17.627 20.414,16.646 19.821,15.943C19.207,15.229 18.34,15.224 17.526,15.794C16.296,16.745 15.074,17.235 13.468,17.235C10.109,17.235 7.327,15 6.532,12.011H8.261C9.138,12.011 9.378,11.134 8.868,10.451L5.96,6.434C5.449,5.74 4.581,5.695 4.055,6.434L1.184,10.451C0.674,11.15 0.899,12.011 1.776,12.011H3.556C4.435,16.889 8.431,20.291 13.468,20.291ZM13.438,0.291C11.255,0.291 9.111,1.019 7.617,2.238C6.7,2.94 6.509,3.921 7.102,4.624C7.717,5.338 8.584,5.34 9.38,4.773C10.612,3.837 11.835,3.332 13.438,3.332C16.8,3.332 19.579,5.567 20.392,8.556H18.57C17.678,8.556 17.45,9.432 17.948,10.116L20.871,14.133C21.382,14.827 22.249,14.872 22.775,14.133L25.647,10.116C26.156,9.432 25.932,8.556 25.04,8.556H23.35C22.485,3.675 18.492,0.291 13.438,0.291Z"
android:fillColor="#ffffff"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="26dp"
android:viewportWidth="26"
android:viewportHeight="26">
<path
android:pathData="M10.847,3.572V7.974C20.432,8.707 23.521,16.919 23.868,20.933C19.76,14.869 13.476,14.412 10.847,14.942V19.466L2.962,11.702L10.847,3.572Z"
android:fillColor="#ffffff"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26dp"
android:height="26dp"
android:viewportWidth="26"
android:viewportHeight="26">
<path
android:pathData="M8.749,24.43H19.167C21.186,24.43 22.073,23.433 22.385,21.427L23.972,5.825L22.071,5.907L20.492,21.315C20.35,22.226 19.89,22.591 19.076,22.591H8.847C8.017,22.591 7.566,22.226 7.432,21.315L5.853,5.907L3.952,5.825L5.539,21.427C5.843,23.441 6.738,24.43 8.749,24.43ZM4.063,6.85H23.863C25.195,6.85 25.962,5.998 25.962,4.677V3.244C25.962,1.924 25.195,1.072 23.863,1.072H4.063C2.782,1.072 1.962,1.924 1.962,3.244V4.677C1.962,5.998 2.732,6.85 4.063,6.85ZM4.44,5.102C3.99,5.102 3.794,4.898 3.794,4.446V3.474C3.794,3.023 3.99,2.819 4.44,2.819H23.492C23.942,2.819 24.13,3.023 24.13,3.474V4.446C24.13,4.898 23.942,5.102 23.492,5.102H4.44Z"
android:fillColor="#FF3A3A"/>
</vector>