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`.
This commit is contained in:
MohitMaliFtechiz 2025-03-21 16:27:11 +05:30
parent 9a7df5e1d9
commit 075f2c0e8c
3 changed files with 55 additions and 12 deletions

View File

@ -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)

View File

@ -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
)
}
}
}

View File

@ -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
)
}