cleaning up messages theming

This commit is contained in:
Adam Brown 2022-09-12 20:06:16 +01:00 committed by Adam Brown
parent bce38bb24b
commit 3cec16e33a
3 changed files with 39 additions and 25 deletions

View File

@ -1,12 +1,15 @@
package app.dapk.st.design.components package app.dapk.st.design.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.MoreVert
import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material.icons.Icons import androidx.compose.material3.MaterialTheme
import androidx.compose.material.icons.outlined.MoreVert
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -18,7 +21,8 @@ fun OverflowMenu(content: @Composable () -> Unit) {
DropdownMenu( DropdownMenu(
expanded = showMenu, expanded = showMenu,
onDismissRequest = { showMenu = false }, onDismissRequest = { showMenu = false },
offset = DpOffset(0.dp, (-72).dp) offset = DpOffset(0.dp, (-72).dp),
modifier = Modifier.background(MaterialTheme.colorScheme.secondaryContainer)
) { ) {
content() content()
} }

View File

@ -15,18 +15,22 @@ private object Palette {
private val DARK_COLOURS = darkColorScheme( private val DARK_COLOURS = darkColorScheme(
primary = Palette.brandPrimary, primary = Palette.brandPrimary,
onPrimary = Color(0xDDFFFFFF), onPrimary = Color(0xDDFFFFFF),
secondaryContainer = Color(0xFF363639),
onSecondaryContainer = Color(0xDDFFFFFF),
) )
private val LIGHT_COLOURS = lightColorScheme( private val LIGHT_COLOURS = lightColorScheme(
primary = Palette.brandPrimary, primary = Palette.brandPrimary,
onPrimary = Color(0xDDFFFFFF), onPrimary = Color(0xDDFFFFFF),
secondaryContainer = Color(0xFFf1f0f1),
onSecondaryContainer = Color(0xFF000000),
) )
private fun createExtended(primary: Color, onPrimary: Color) = ExtendedColors( private fun createExtended(scheme: ColorScheme) = ExtendedColors(
selfBubble = primary, selfBubble = scheme.primary,
onSelfBubble = onPrimary, onSelfBubble = scheme.onPrimary,
othersBubble = Color(0x20EDEDED), othersBubble = scheme.secondaryContainer,
onOthersBubble = onPrimary, onOthersBubble = scheme.onSecondaryContainer,
selfBubbleReplyBackground = Color(0x40EAEAEA), selfBubbleReplyBackground = Color(0x40EAEAEA),
otherBubbleReplyBackground = Color(0x20EAEAEA), otherBubbleReplyBackground = Color(0x20EAEAEA),
missingImageColors = listOf( missingImageColors = listOf(
@ -58,15 +62,19 @@ fun SmallTalkTheme(themeConfig: ThemeConfig, content: @Composable () -> Unit) {
val systemUiController = rememberSystemUiController() val systemUiController = rememberSystemUiController()
val systemInDarkTheme = isSystemInDarkTheme() val systemInDarkTheme = isSystemInDarkTheme()
val colorScheme = if (themeConfig.useDynamicTheme) { val colorScheme = when {
when (systemInDarkTheme) { themeConfig.useDynamicTheme -> {
true -> dynamicDarkColorScheme(LocalContext.current) when (systemInDarkTheme) {
false -> dynamicLightColorScheme(LocalContext.current) true -> dynamicDarkColorScheme(LocalContext.current)
false -> dynamicLightColorScheme(LocalContext.current)
}
} }
} else {
when (systemInDarkTheme) { else -> {
true -> DARK_COLOURS when (systemInDarkTheme) {
false -> LIGHT_COLOURS true -> DARK_COLOURS
false -> LIGHT_COLOURS
}
} }
} }
MaterialTheme(colorScheme = colorScheme) { MaterialTheme(colorScheme = colorScheme) {
@ -74,7 +82,7 @@ fun SmallTalkTheme(themeConfig: ThemeConfig, content: @Composable () -> Unit) {
SideEffect { SideEffect {
systemUiController.setSystemBarsColor(backgroundColor) systemUiController.setSystemBarsColor(backgroundColor)
} }
CompositionLocalProvider(LocalExtendedColors provides createExtended(MaterialTheme.colorScheme.primary, MaterialTheme.colorScheme.onPrimary)) { CompositionLocalProvider(LocalExtendedColors provides createExtended(colorScheme)) {
content() content()
} }
} }

View File

@ -10,11 +10,11 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.*
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Close import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Send import androidx.compose.material.icons.filled.Send
import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -64,7 +64,7 @@ internal fun MessengerScreen(roomId: RoomId, attachments: List<MessageAttachment
Column { Column {
Toolbar(onNavigate = { navigator.navigate.upToHome() }, roomTitle, actions = { Toolbar(onNavigate = { navigator.navigate.upToHome() }, roomTitle, actions = {
OverflowMenu { OverflowMenu {
DropdownMenuItem(text = { Text("Settings") }, onClick = {}) DropdownMenuItem(text = { Text("Settings", color = MaterialTheme.colorScheme.onSecondaryContainer) }, onClick = {})
} }
}) })
when (state.composerState) { when (state.composerState) {
@ -565,12 +565,12 @@ private fun TextComposer(state: ComposerState.Text, onTextChange: (String) -> Un
.align(Alignment.Bottom) .align(Alignment.Bottom)
.weight(1f) .weight(1f)
.fillMaxHeight() .fillMaxHeight()
.background(Color.DarkGray, RoundedCornerShape(24.dp)), .background(SmallTalkTheme.extendedColors.othersBubble, RoundedCornerShape(24.dp)),
contentAlignment = Alignment.TopStart, contentAlignment = Alignment.TopStart,
) { ) {
Box(Modifier.padding(14.dp)) { Box(Modifier.padding(14.dp)) {
if (state.value.isEmpty()) { if (state.value.isEmpty()) {
Text("Message", color = SmallTalkTheme.extendedColors.onOthersBubble.copy(alpha = 0.4f)) Text("Message", color = SmallTalkTheme.extendedColors.onOthersBubble.copy(alpha = 0.5f))
} }
BasicTextField( BasicTextField(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@ -584,11 +584,12 @@ private fun TextComposer(state: ComposerState.Text, onTextChange: (String) -> Un
} }
Spacer(modifier = Modifier.width(6.dp)) Spacer(modifier = Modifier.width(6.dp))
var size by remember { mutableStateOf(IntSize(0, 0)) } var size by remember { mutableStateOf(IntSize(0, 0)) }
val enabled = state.value.isNotEmpty()
IconButton( IconButton(
enabled = state.value.isNotEmpty(), enabled = enabled,
modifier = Modifier modifier = Modifier
.clip(CircleShape) .clip(CircleShape)
.background(if (state.value.isEmpty()) Color.DarkGray else MaterialTheme.colorScheme.primary) .background(if (enabled) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.secondaryContainer)
.run { .run {
if (size.height == 0 || size.width == 0) { if (size.height == 0 || size.width == 0) {
this this
@ -607,7 +608,7 @@ private fun TextComposer(state: ComposerState.Text, onTextChange: (String) -> Un
Icon( Icon(
imageVector = Icons.Filled.Send, imageVector = Icons.Filled.Send,
contentDescription = "", contentDescription = "",
tint = MaterialTheme.colorScheme.onPrimary, tint = if (enabled) MaterialTheme.colorScheme.onPrimary else MaterialTheme.colorScheme.onSecondaryContainer.copy(alpha = 0.5f),
) )
} }
} }
@ -633,7 +634,8 @@ private fun AttachmentComposer(state: ComposerState.Attachments, onSend: () -> U
Box( Box(
Modifier Modifier
.align(Alignment.BottomEnd) .align(Alignment.BottomEnd)
.padding(12.dp)) { .padding(12.dp)
) {
IconButton( IconButton(
enabled = true, enabled = true,
modifier = Modifier modifier = Modifier