From ecc0f39f7db55a87b3822c078fb2bd1a081426a5 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sat, 16 Dec 2023 11:42:11 -0500 Subject: [PATCH] Moves relay modifiers to the app's theme --- .../amethyst/ui/actions/NewRelayListView.kt | 8 ++++-- .../ui/actions/RelayInformationDialog.kt | 5 ++-- .../amethyst/ui/note/RelayListRow.kt | 21 +++++---------- .../vitorpamplona/amethyst/ui/theme/Theme.kt | 26 +++++++++++++++++++ 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewRelayListView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewRelayListView.kt index ade53fb70..d9ca67b0c 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewRelayListView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewRelayListView.kt @@ -74,11 +74,11 @@ import com.vitorpamplona.amethyst.ui.theme.HalfStartPadding import com.vitorpamplona.amethyst.ui.theme.ReactionRowHeightChat import com.vitorpamplona.amethyst.ui.theme.Size30Modifier import com.vitorpamplona.amethyst.ui.theme.Size35dp -import com.vitorpamplona.amethyst.ui.theme.Size55dp import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer import com.vitorpamplona.amethyst.ui.theme.WarningColor import com.vitorpamplona.amethyst.ui.theme.allGoodColor +import com.vitorpamplona.amethyst.ui.theme.largeRelayIconModifier import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.warningColor import kotlinx.coroutines.launch @@ -369,7 +369,11 @@ fun ServerConfigClickableLine( modifier = Modifier.padding(vertical = 5.dp) ) { Column(Modifier.clickable(onClick = onClick)) { - RenderRelayIcon(iconUrl = item.briefInfo.favIcon, loadProfilePicture, Size55dp) + RenderRelayIcon( + iconUrl = item.briefInfo.favIcon, + loadProfilePicture, + MaterialTheme.colorScheme.largeRelayIconModifier + ) } Spacer(modifier = HalfHorzPadding) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/RelayInformationDialog.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/RelayInformationDialog.kt index 36cb94192..f109b3c07 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/RelayInformationDialog.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/RelayInformationDialog.kt @@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -36,8 +37,8 @@ import com.vitorpamplona.amethyst.ui.note.UserCompose import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.theme.DoubleHorzSpacer import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer -import com.vitorpamplona.amethyst.ui.theme.Size55dp import com.vitorpamplona.amethyst.ui.theme.StdPadding +import com.vitorpamplona.amethyst.ui.theme.largeRelayIconModifier @OptIn(ExperimentalLayoutApi::class) @Composable @@ -83,7 +84,7 @@ fun RelayInformationDialog( RenderRelayIcon( relayBriefInfo.favIcon, automaticallyShowProfilePicture, - Size55dp + MaterialTheme.colorScheme.largeRelayIconModifier ) } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt index 4c4945d3e..e2cdf1ea5 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/note/RelayListRow.kt @@ -1,6 +1,5 @@ package com.vitorpamplona.amethyst.ui.note -import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement @@ -9,7 +8,6 @@ import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size -import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ChevronRight import androidx.compose.material.ripple.rememberRipple @@ -25,11 +23,9 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.Role -import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.lifecycle.map import com.vitorpamplona.amethyst.R @@ -41,11 +37,11 @@ import com.vitorpamplona.amethyst.ui.actions.RelayInformationDialog import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.theme.RelayIconFilter -import com.vitorpamplona.amethyst.ui.theme.Size13dp import com.vitorpamplona.amethyst.ui.theme.Size15Modifier import com.vitorpamplona.amethyst.ui.theme.Size15dp import com.vitorpamplona.amethyst.ui.theme.StdStartPadding import com.vitorpamplona.amethyst.ui.theme.placeholderText +import com.vitorpamplona.amethyst.ui.theme.relayIconModifier @Composable public fun RelayBadgesHorizontal(baseNote: Note, accountViewModel: AccountViewModel, nav: (String) -> Unit) { @@ -178,16 +174,11 @@ fun RenderRelay(relay: RelayBriefInfoCache.RelayBriefInfo, accountViewModel: Acc } @Composable -fun RenderRelayIcon(iconUrl: String, loadProfilePicture: Boolean, size: Dp = Size13dp) { - val backgroundColor = MaterialTheme.colorScheme.background - - val iconModifier = remember { - Modifier - .size(size) - .clip(shape = CircleShape) - .background(backgroundColor) - } - +fun RenderRelayIcon( + iconUrl: String, + loadProfilePicture: Boolean, + iconModifier: Modifier = MaterialTheme.colorScheme.relayIconModifier +) { RobohashFallbackAsyncImage( robot = iconUrl, model = iconUrl, diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt index f5d322d29..76692e395 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt @@ -152,6 +152,26 @@ val LightChannelNotePictureModifier = Modifier .background(LightColorPalette.background) .border(2.dp, LightColorPalette.background, CircleShape) +val LightRelayIconModifier = Modifier + .size(Size13dp) + .clip(shape = CircleShape) + .background(LightColorPalette.background) + +val DarkRelayIconModifier = Modifier + .size(Size13dp) + .clip(shape = CircleShape) + .background(DarkColorPalette.background) + +val LightLargeRelayIconModifier = Modifier + .size(Size55dp) + .clip(shape = CircleShape) + .background(LightColorPalette.background) + +val DarkLargeRelayIconModifier = Modifier + .size(Size55dp) + .clip(shape = CircleShape) + .background(DarkColorPalette.background) + val RichTextDefaults = RichTextStyle().resolveDefaults() val MarkDownStyleOnDark = RichTextDefaults.copy( @@ -294,6 +314,12 @@ val ColorScheme.innerPostModifier: Modifier val ColorScheme.channelNotePictureModifier: Modifier get() = if (isLight) LightChannelNotePictureModifier else DarkChannelNotePictureModifier +val ColorScheme.relayIconModifier: Modifier + get() = if (isLight) LightRelayIconModifier else DarkRelayIconModifier + +val ColorScheme.largeRelayIconModifier: Modifier + get() = if (isLight) LightRelayIconModifier else DarkRelayIconModifier + val ColorScheme.chartStyle: ChartStyle get() { val defaultColors = if (isLight) DefaultColors.Light else DefaultColors.Dark