From 075f2c0e8c4a655aebcd51cd272b9f98a3017a27 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Fri, 21 Mar 2025 16:27:11 +0530 Subject: [PATCH] Created `KiwixSnackToastTheme` to manage the theme of Toast and Snackbar messages separately from the app's main theme, ensuring consistency and preventing unintended style changes. * Minor refinement in showing the `NoFileView`. --- .../library/local/LocalLibraryScreen.kt | 7 +++- .../core/ui/components/KiwixSnackbarHost.kt | 23 +++++++----- .../kiwix/kiwixmobile/core/ui/theme/Theme.kt | 37 +++++++++++++++++++ 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryScreen.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryScreen.kt index c73e4e7a8..7201bb602 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryScreen.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/local/LocalLibraryScreen.kt @@ -46,6 +46,7 @@ import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import org.kiwix.kiwixmobile.R.string @@ -64,6 +65,7 @@ import org.kiwix.kiwixmobile.core.ui.theme.KiwixTheme import org.kiwix.kiwixmobile.core.ui.theme.White import org.kiwix.kiwixmobile.core.utils.ComposeDimens.EIGHT_DP import org.kiwix.kiwixmobile.core.utils.ComposeDimens.FAB_ICON_BOTTOM_MARGIN +import org.kiwix.kiwixmobile.core.utils.ComposeDimens.FOUR_DP import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk import org.kiwix.kiwixmobile.ui.BookItem @@ -207,13 +209,14 @@ fun NoFilesView( onDownloadButtonClick: () -> Unit ) { Column( - modifier = Modifier.fillMaxSize(), + modifier = Modifier.fillMaxSize().padding(horizontal = FOUR_DP), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { Text( text = noFilesViewItem.first, - style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Medium) + style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Medium), + textAlign = TextAlign.Center ) Spacer(modifier = Modifier.height(EIGHT_DP)) KiwixButton(noFilesViewItem.second, onDownloadButtonClick) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/ui/components/KiwixSnackbarHost.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/ui/components/KiwixSnackbarHost.kt index f5ef0a449..52d194ce0 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/ui/components/KiwixSnackbarHost.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/ui/components/KiwixSnackbarHost.kt @@ -25,6 +25,7 @@ import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable import org.kiwix.kiwixmobile.core.ui.theme.DenimBlue400 +import org.kiwix.kiwixmobile.core.ui.theme.KiwixSnackToastTheme /** * A custom SnackbarHost for displaying snackbars with theme-aware action button colors. @@ -37,15 +38,17 @@ import org.kiwix.kiwixmobile.core.ui.theme.DenimBlue400 */ @Composable fun KiwixSnackbarHost(snackbarHostState: SnackbarHostState) { - val actionColor = if (isSystemInDarkTheme()) { - MaterialTheme.colorScheme.surface - } else { - DenimBlue400 - } - SnackbarHost(hostState = snackbarHostState) { snackbarData -> - Snackbar( - snackbarData = snackbarData, - actionColor = actionColor - ) + KiwixSnackToastTheme { + val actionColor = if (isSystemInDarkTheme()) { + MaterialTheme.colorScheme.surface + } else { + DenimBlue400 + } + SnackbarHost(hostState = snackbarHostState) { snackbarData -> + Snackbar( + snackbarData = snackbarData, + actionColor = actionColor + ) + } } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/ui/theme/Theme.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/ui/theme/Theme.kt index 4d1a13770..9972d46df 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/ui/theme/Theme.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/ui/theme/Theme.kt @@ -23,6 +23,9 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable +import androidx.compose.ui.text.TextStyle +import org.kiwix.kiwixmobile.core.utils.ComposeDimens.MEDIUM_BODY_LETTER_SPACING +import org.kiwix.kiwixmobile.core.utils.ComposeDimens.MEDIUM_BODY_TEXT_SIZE private val DarkColorScheme = darkColorScheme( primary = DenimBlue200, @@ -95,3 +98,37 @@ fun KiwixDialogTheme( typography = KiwixTypography ) } + +/** + * A custom theme specifically designed for displaying short-lived UI messages, + * such as Snackbars, and Toasts. + * + * This theme overrides the default `bodyMedium` typography to remove bold styling, + * ensuring that Snackbar and Toast messages appear in a normal-weight font. + * + * @param darkTheme Determines whether the theme should use dark mode colors. + * Defaults to the system's dark mode setting. + * @param content The composable content that will be wrapped with this theme. + */ +@Composable +fun KiwixSnackToastTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + content: @Composable () -> Unit +) { + val colorScheme = when { + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val snackBarTypography = KiwixTypography.copy( + bodyMedium = TextStyle( + fontSize = MEDIUM_BODY_TEXT_SIZE, + letterSpacing = MEDIUM_BODY_LETTER_SPACING + ) + ) + MaterialTheme( + colorScheme = colorScheme, + content = content, + shapes = shapes, + typography = snackBarTypography + ) +}