From 9c5e9c8e4381aaa2886d0ad03070b2a57a937cce Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 23 Jul 2022 19:15:36 +0530 Subject: Improvements to key list activity (#2030) --- .../main/kotlin/app/passwordstore/ui/APSAppBar.kt | 36 ++++++++++++++++++++ .../app/passwordstore/ui/compose/theme/Theme.kt | 15 +++------ .../app/passwordstore/ui/compose/theme/utils.kt | 27 +++++++++++++++ .../kotlin/app/passwordstore/ui/pgp/PGPKeyList.kt | 39 ---------------------- 4 files changed, 67 insertions(+), 50 deletions(-) create mode 100644 ui-compose/src/main/kotlin/app/passwordstore/ui/APSAppBar.kt create mode 100644 ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/utils.kt delete mode 100644 ui-compose/src/main/kotlin/app/passwordstore/ui/pgp/PGPKeyList.kt (limited to 'ui-compose/src/main/kotlin') diff --git a/ui-compose/src/main/kotlin/app/passwordstore/ui/APSAppBar.kt b/ui-compose/src/main/kotlin/app/passwordstore/ui/APSAppBar.kt new file mode 100644 index 00000000..6900b25f --- /dev/null +++ b/ui-compose/src/main/kotlin/app/passwordstore/ui/APSAppBar.kt @@ -0,0 +1,36 @@ +package app.passwordstore.ui + +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.SmallTopAppBar +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.painter.Painter + +@Composable +public fun APSAppBar( + title: String, + backgroundColor: Color, + navigationIcon: Painter?, + onNavigationIconClick: (() -> Unit)?, + modifier: Modifier = Modifier, +) { + SmallTopAppBar( + title = { Text(text = title) }, + navigationIcon = { + if (navigationIcon != null) { + IconButton(onClick = { onNavigationIconClick?.invoke() }) { + Icon( + painter = navigationIcon, + contentDescription = null, + ) + } + } + }, + colors = TopAppBarDefaults.smallTopAppBarColors(containerColor = backgroundColor), + modifier = modifier, + ) +} diff --git a/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt b/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt index 9bd8003e..695ff6cc 100644 --- a/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt +++ b/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt @@ -1,12 +1,12 @@ package app.passwordstore.ui.compose.theme -import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.ColorScheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable -private val LightThemeColors = +internal val LightThemeColors = lightColorScheme( primary = md_theme_light_primary, onPrimary = md_theme_light_onPrimary, @@ -34,7 +34,7 @@ private val LightThemeColors = inverseOnSurface = md_theme_light_inverseOnSurface, inverseSurface = md_theme_light_inverseSurface, ) -private val DarkThemeColors = +internal val DarkThemeColors = darkColorScheme( primary = md_theme_dark_primary, onPrimary = md_theme_dark_onPrimary, @@ -65,15 +65,8 @@ private val DarkThemeColors = @Composable public fun APSTheme( - useDarkTheme: Boolean = isSystemInDarkTheme(), + colors: ColorScheme, content: @Composable () -> Unit, ) { - val colors = - if (!useDarkTheme) { - LightThemeColors - } else { - DarkThemeColors - } - MaterialTheme(colorScheme = colors, typography = AppTypography, content = content) } diff --git a/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/utils.kt b/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/utils.kt new file mode 100644 index 00000000..096862dc --- /dev/null +++ b/ui-compose/src/main/kotlin/app/passwordstore/ui/compose/theme/utils.kt @@ -0,0 +1,27 @@ +package app.passwordstore.ui.compose.theme + +import android.content.Context +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.ColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.runtime.Composable + +@Composable +public fun decideColorScheme(context: Context): ColorScheme { + val isDarkTheme = isSystemInDarkTheme() + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (isDarkTheme) { + dynamicDarkColorScheme(context) + } else { + dynamicLightColorScheme(context) + } + } else { + if (isDarkTheme) { + DarkThemeColors + } else { + LightThemeColors + } + } +} diff --git a/ui-compose/src/main/kotlin/app/passwordstore/ui/pgp/PGPKeyList.kt b/ui-compose/src/main/kotlin/app/passwordstore/ui/pgp/PGPKeyList.kt deleted file mode 100644 index ccc6fa01..00000000 --- a/ui-compose/src/main/kotlin/app/passwordstore/ui/pgp/PGPKeyList.kt +++ /dev/null @@ -1,39 +0,0 @@ -package app.passwordstore.ui.pgp - -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.dp -import app.passwordstore.crypto.GpgIdentifier - -@Composable -public fun KeyList( - identifiers: List, - onItemClick: (identifier: GpgIdentifier) -> Unit, - modifier: Modifier = Modifier, -) { - LazyColumn(modifier = modifier) { - items(identifiers) { identifier -> - KeyItem(identifier = identifier, modifier = Modifier.clickable { onItemClick(identifier) }) - } - } -} - -@Composable -private fun KeyItem( - identifier: GpgIdentifier, - modifier: Modifier = Modifier, -) { - val label = - when (identifier) { - is GpgIdentifier.KeyId -> identifier.id.toString() - is GpgIdentifier.UserId -> identifier.email - } - Box(modifier = modifier.padding(16.dp).fillMaxWidth()) { Text(text = label) } -} -- cgit v1.2.3