refactor: migrate to SimpleTheme from MaterialTheme

This commit is contained in:
FunkyMuse 2023-10-06 14:19:58 +02:00
parent 7bd3746b83
commit f60fae4e55
18 changed files with 59 additions and 54 deletions

View file

@ -9,7 +9,6 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
@ -24,6 +23,7 @@ import androidx.lifecycle.compose.LifecycleEventEffect
import androidx.lifecycle.compose.LifecycleResumeEffect
import androidx.lifecycle.compose.LifecycleStartEffect
import com.simplemobiletools.commons.compose.system_ui_controller.rememberSystemUiController
import com.simplemobiletools.commons.compose.theme.SimpleTheme
import com.simplemobiletools.commons.compose.theme.isLitWell
import com.simplemobiletools.commons.extensions.darkenColor
@ -44,8 +44,8 @@ fun rememberMutableInteractionSource() = remember { MutableInteractionSource() }
fun AdjustNavigationBarColors() {
val systemUiController = rememberSystemUiController()
val isSystemInDarkTheme = isSystemInDarkTheme()
val isSurfaceLitWell = MaterialTheme.colorScheme.surface.isLitWell()
val navigationBarColor = Color(MaterialTheme.colorScheme.surface.toArgb().darkenColor()).copy(alpha = 0.5f)
val isSurfaceLitWell = SimpleTheme.colorScheme.surface.isLitWell()
val navigationBarColor = Color(SimpleTheme.colorScheme.surface.toArgb().darkenColor()).copy(alpha = 0.5f)
DisposableEffect(systemUiController, isSystemInDarkTheme, navigationBarColor) {
systemUiController.setNavigationBarColor(color = navigationBarColor, darkIcons = !isSystemInDarkTheme)
systemUiController.navigationBarDarkContentEnabled = isSurfaceLitWell

View file

@ -1,7 +1,6 @@
package com.simplemobiletools.commons.compose.screens
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@ -16,6 +15,7 @@ import com.simplemobiletools.commons.compose.settings.SettingsListItem
import com.simplemobiletools.commons.compose.settings.SettingsTitleTextComponent
import com.simplemobiletools.commons.compose.settings.scaffold.SettingsScaffold
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.compose.theme.SimpleTheme
private val startingTitlePadding = Modifier.padding(start = 60.dp)
@ -166,7 +166,7 @@ internal fun SocialSection(
click = onGithubClick,
text = stringResource(id = R.string.github),
icon = R.drawable.ic_github_vector,
tint = MaterialTheme.colorScheme.onSurface
tint = SimpleTheme.colorScheme.onSurface
)
SocialText(
click = onRedditClick,
@ -203,7 +203,7 @@ internal fun SocialText(
@Composable
internal fun TwoLinerTextItem(text: String, icon: Int, click: () -> Unit) {
SettingsListItem(
tint = MaterialTheme.colorScheme.onSurface,
tint = SimpleTheme.colorScheme.onSurface,
click = click,
text = text,
icon = icon,

View file

@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@ -132,7 +131,7 @@ private fun ContributorItem(
text = stringResource(id = languageContributor.contributorsId),
modifier = Modifier
.fillMaxWidth(),
color = MaterialTheme.colorScheme.onSurface
color = SimpleTheme.colorScheme.onSurface
)
}
)

View file

@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@ -61,7 +60,7 @@ private fun LicenseItem(
text = stringResource(id = license.textId),
modifier = Modifier.padding(top = SimpleTheme.dimens.margin.extraSmall),
)
}, colors = ListItemDefaults.colors(headlineColor = MaterialTheme.colorScheme.primary, supportingColor = MaterialTheme.colorScheme.onSurface))
}, colors = ListItemDefaults.colors(headlineColor = SimpleTheme.colorScheme.primary, supportingColor = SimpleTheme.colorScheme.onSurface))
}
@Composable

View file

@ -365,12 +365,12 @@ private fun blockedNumberListItemColors(
) = ListItemDefaults.colors(
containerColor = if (isSelected) {
if (LocalTheme.current is Theme.SystemDefaultMaterialYou) {
Color(MaterialTheme.colorScheme.primaryContainer.toArgb().darkenColor()).copy(alpha = 0.8f)
Color(SimpleTheme.colorScheme.primaryContainer.toArgb().darkenColor()).copy(alpha = 0.8f)
} else {
MaterialTheme.colorScheme.primary.copy(alpha = 0.3f)
SimpleTheme.colorScheme.primary.copy(alpha = 0.3f)
}
} else {
MaterialTheme.colorScheme.surface
SimpleTheme.colorScheme.surface
},
trailingIconColor = iconsColor
)
@ -488,7 +488,7 @@ private fun ActionModeToolbar(
@ReadOnlyComposable
private fun actionModeBgColor(): Color =
if (LocalTheme.current is Theme.SystemDefaultMaterialYou) {
MaterialTheme.colorScheme.primaryContainer
SimpleTheme.colorScheme.primaryContainer
} else {
actionModeColor
}
@ -580,7 +580,7 @@ private fun LazyListScope.emptyBlockedNumbers(
item {
Text(
text = stringResource(id = R.string.not_blocking_anyone),
style = TextStyle(fontStyle = FontStyle.Italic, textAlign = TextAlign.Center, color = MaterialTheme.colorScheme.onSurface),
style = TextStyle(fontStyle = FontStyle.Italic, textAlign = TextAlign.Center, color = SimpleTheme.colorScheme.onSurface),
modifier = Modifier
.fillMaxWidth()
.padding(top = SimpleTheme.dimens.margin.extraLarge, bottom = SimpleTheme.dimens.margin.small)
@ -602,7 +602,7 @@ private fun LazyListScope.emptyBlockedNumbers(
style = TextStyle(
textAlign = TextAlign.Center,
textDecoration = TextDecoration.Underline,
color = MaterialTheme.colorScheme.primary,
color = SimpleTheme.colorScheme.primary,
fontSize = 18.sp
),
modifier = Modifier.padding(SimpleTheme.dimens.margin.medium)
@ -640,7 +640,7 @@ private fun LazyListScope.noPermissionToBlock(
style = TextStyle(
textAlign = TextAlign.Center,
textDecoration = TextDecoration.Underline,
color = MaterialTheme.colorScheme.primary,
color = SimpleTheme.colorScheme.primary,
fontSize = 18.sp
),
modifier = Modifier.padding(SimpleTheme.dimens.margin.extraLarge)

View file

@ -5,7 +5,10 @@ import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.material3.*
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CheckboxColors
import androidx.compose.material3.CheckboxDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
@ -15,7 +18,10 @@ import androidx.compose.ui.unit.sp
import com.simplemobiletools.commons.compose.extensions.MyDevices
import com.simplemobiletools.commons.compose.extensions.NoRippleTheme
import com.simplemobiletools.commons.compose.extensions.rememberMutableInteractionSource
import com.simplemobiletools.commons.compose.theme.*
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.compose.theme.SimpleTheme
import com.simplemobiletools.commons.compose.theme.preferenceLabelColor
import com.simplemobiletools.commons.compose.theme.preferenceValueColor
@Composable
fun SettingsCheckBoxComponent(
@ -26,8 +32,8 @@ fun SettingsCheckBoxComponent(
isPreferenceEnabled: Boolean = true,
onChange: ((Boolean) -> Unit)? = null,
checkboxColors: CheckboxColors = CheckboxDefaults.colors(
checkedColor = MaterialTheme.colorScheme.primary,
checkmarkColor = MaterialTheme.colorScheme.surface,
checkedColor = SimpleTheme.colorScheme.primary,
checkmarkColor = SimpleTheme.colorScheme.surface,
)
) {
val interactionSource = rememberMutableInteractionSource()

View file

@ -38,8 +38,8 @@ fun SettingsGroupTitle(
.padding(horizontal = SimpleTheme.dimens.margin.extraLarge),
contentAlignment = Alignment.CenterStart
) {
val primary = MaterialTheme.colorScheme.primary
val titleStyle = MaterialTheme.typography.headlineMedium.copy(color = primary)
val primary = SimpleTheme.colorScheme.primary
val titleStyle = SimpleTheme.typography.headlineMedium.copy(color = primary)
ProvideTextStyle(value = titleStyle) { title() }
}
}

View file

@ -2,7 +2,6 @@ package com.simplemobiletools.commons.compose.settings
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@ -17,7 +16,7 @@ import com.simplemobiletools.commons.compose.theme.SimpleTheme
fun SettingsTitleTextComponent(
modifier: Modifier = Modifier,
text: String,
color: Color = MaterialTheme.colorScheme.primary,
color: Color = SimpleTheme.colorScheme.primary,
maxLines: Int = 1,
overflow: TextOverflow = TextOverflow.Ellipsis
) {

View file

@ -4,7 +4,6 @@ import android.content.Context
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
@ -14,6 +13,7 @@ import androidx.compose.ui.platform.LocalLayoutDirection
import com.simplemobiletools.commons.compose.extensions.onEventValue
import com.simplemobiletools.commons.compose.system_ui_controller.rememberSystemUiController
import com.simplemobiletools.commons.compose.theme.LocalTheme
import com.simplemobiletools.commons.compose.theme.SimpleTheme
import com.simplemobiletools.commons.compose.theme.isNotLitWell
import com.simplemobiletools.commons.compose.theme.isSurfaceLitWell
import com.simplemobiletools.commons.compose.theme.model.Theme
@ -35,7 +35,7 @@ internal fun ScreenBoxSettingsScaffold(paddingValues: PaddingValues, modifier: M
Box(
modifier = modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.surface)
.background(SimpleTheme.colorScheme.surface)
.padding(
top = paddingValues.calculateTopPadding(),
start = paddingValues.calculateStartPadding(layoutDirection),

View file

@ -129,8 +129,8 @@ fun topAppBarColors(
contrastColor: Color
) = TopAppBarDefaults.topAppBarColors(
scrolledContainerColor = Color(statusBarColor),
containerColor = if (colorTransitionFraction == 1f) contrastColor else MaterialTheme.colorScheme.surface,
navigationIconContentColor = if (colorTransitionFraction == 1f) contrastColor else MaterialTheme.colorScheme.surface
containerColor = if (colorTransitionFraction == 1f) contrastColor else SimpleTheme.colorScheme.surface,
navigationIconContentColor = if (colorTransitionFraction == 1f) contrastColor else SimpleTheme.colorScheme.surface
)
@Composable
@ -161,7 +161,7 @@ fun SettingsNavigationIcon(
.clip(RoundedCornerShape(50))
.clickable(
navigationIconInteractionSource, rememberRipple(
color = MaterialTheme.colorScheme.onSurface,
color = SimpleTheme.colorScheme.onSurface,
bounded = true
)
) { goBack() }

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.commons.compose.theme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.graphics.Color
@ -31,11 +30,11 @@ val iconsColor
@Composable
@ReadOnlyComposable
fun preferenceValueColor(isEnabled: Boolean) =
if (isEnabled) MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f) else disabledTextColor
if (isEnabled) SimpleTheme.colorScheme.onSurface.copy(alpha = 0.6f) else disabledTextColor
@Composable
@ReadOnlyComposable
fun preferenceLabelColor(isEnabled: Boolean) = if (isEnabled) MaterialTheme.colorScheme.onSurface else disabledTextColor
fun preferenceLabelColor(isEnabled: Boolean) = if (isEnabled) SimpleTheme.colorScheme.onSurface else disabledTextColor
fun Color.isLitWell(threshold: Float = LUMINANCE_THRESHOLD) = luminance() > threshold

View file

@ -5,9 +5,11 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Shapes
import androidx.compose.material3.Typography
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.ReadOnlyComposable
import com.simplemobiletools.commons.compose.theme.model.Dimensions
@Immutable
object SimpleTheme {
val dimens: Dimensions
@Composable

View file

@ -3,7 +3,6 @@ package com.simplemobiletools.commons.compose.theme
import android.content.Context
import android.content.res.Configuration
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.graphics.luminance
@ -26,11 +25,11 @@ internal const val LUMINANCE_THRESHOLD = 0.5f
@Composable
@ReadOnlyComposable
fun isSurfaceNotLitWell(threshold: Float = LUMINANCE_THRESHOLD) = MaterialTheme.colorScheme.surface.luminance() < threshold
fun isSurfaceNotLitWell(threshold: Float = LUMINANCE_THRESHOLD) = SimpleTheme.colorScheme.surface.luminance() < threshold
@Composable
@ReadOnlyComposable
fun isSurfaceLitWell(threshold: Float = LUMINANCE_THRESHOLD) = MaterialTheme.colorScheme.surface.luminance() > threshold
fun isSurfaceLitWell(threshold: Float = LUMINANCE_THRESHOLD) = SimpleTheme.colorScheme.surface.luminance() > threshold
internal fun Context.isDarkMode(): Boolean {
val darkModeFlag = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK

View file

@ -204,8 +204,8 @@ private fun DialogCheckBoxChangeDateTimeFormatComponent(
isPreferenceEnabled: Boolean = true,
onChange: ((Boolean) -> Unit)? = null,
checkboxColors: CheckboxColors = CheckboxDefaults.colors(
checkedColor = MaterialTheme.colorScheme.primary,
checkmarkColor = MaterialTheme.colorScheme.surface,
checkedColor = SimpleTheme.colorScheme.primary,
checkmarkColor = SimpleTheme.colorScheme.surface,
)
) {
val interactionSource = rememberMutableInteractionSource()

View file

@ -3,7 +3,6 @@ package com.simplemobiletools.commons.dialogs
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@ -19,6 +18,7 @@ import androidx.compose.ui.unit.dp
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.compose.theme.LocalTheme
import com.simplemobiletools.commons.compose.theme.Shapes
import com.simplemobiletools.commons.compose.theme.SimpleTheme
import com.simplemobiletools.commons.compose.theme.light_grey_stroke
import com.simplemobiletools.commons.compose.theme.model.Theme
import com.simplemobiletools.commons.extensions.baseConfig
@ -29,7 +29,7 @@ val dialogContainerColor
@ReadOnlyComposable
@Composable get() = when (LocalTheme.current) {
is Theme.BlackAndWhite -> Color.Black
is Theme.SystemDefaultMaterialYou -> if (isSPlus()) colorResource(R.color.you_dialog_background_color) else MaterialTheme.colorScheme.surface
is Theme.SystemDefaultMaterialYou -> if (isSPlus()) colorResource(R.color.you_dialog_background_color) else SimpleTheme.colorScheme.surface
else -> {
val context = LocalContext.current
Color(context.baseConfig.backgroundColor)
@ -49,7 +49,7 @@ val dialogShape = Shapes.extraLarge
val dialogElevation = 0.dp
val dialogTextColor @Composable @ReadOnlyComposable get() = MaterialTheme.colorScheme.onSurface
val dialogTextColor @Composable @ReadOnlyComposable get() = SimpleTheme.colorScheme.onSurface
val Modifier.dialogBorder: Modifier
@ReadOnlyComposable

View file

@ -9,7 +9,10 @@ import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.filled.StarOutline
import androidx.compose.material3.*
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Alignment.Companion.End
@ -132,7 +135,7 @@ private fun StarRating(
maxRating: Int = 5,
currentRating: Int,
onRatingChanged: (Int) -> Unit,
starsColor: Color = MaterialTheme.colorScheme.primary,
starsColor: Color = SimpleTheme.colorScheme.primary,
) {
val animatedRating by animateIntAsState(
targetValue = currentRating,

View file

@ -17,7 +17,7 @@ androidx-coreKtx = "1.12.0"
androidx-appcompat = "1.6.1"
androidx-swiperefreshlayout = "1.1.0"
#Material
material = "1.9.0"
material = "1.10.0"
#patternLockView
patternLockView = "a90b0d4bf0"
#reprint
@ -27,12 +27,13 @@ recyclerviewFastscroller = "5a95285b1f"
#rtlViewpager
rtlViewpager = "940f12724f"
#Compose
composeActivity = "1.8.0-rc01"
compose = "1.6.0-alpha06"
composeActivity = "1.8.0"
compose = "1.6.0-alpha07"
composeCompiler = "1.5.3"
composeMaterial3 = "1.2.0-alpha08"
composeMaterial3 = "1.2.0-alpha09"
#Glide
glide = "4.16.0"
glideCompose = "1.0.0-beta01"
#Room
room = "2.6.0-rc01"
#ezVcard
@ -89,6 +90,7 @@ compose-uiTooling-preview = { module = "androidx.compose.ui:ui-tooling-preview",
compose-view-binding = { module = "androidx.compose.ui:ui-viewbinding", version.ref = "compose" }
#Glide
glide = { module = "com.github.bumptech.glide:glide", version.ref = "glide" }
glide-compose = { module = "com.github.bumptech.glide:compose", version.ref = "glideCompose" }
glide-compiler = { module = "com.github.bumptech.glide:compiler", version.ref = "glide" }
#Material
material = { module = "com.google.android.material:material", version.ref = "material" }

View file

@ -4,12 +4,9 @@ import android.content.Intent
import android.os.Bundle
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.activities.ManageBlockedNumbersActivity
import com.simplemobiletools.commons.compose.extensions.DEVELOPER_PLAY_STORE_URL
import com.simplemobiletools.commons.compose.extensions.FAKE_VERSION_APP_LABEL
import com.simplemobiletools.commons.dialogs.BottomSheetChooserDialog
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.WritePermissionDialog
import com.simplemobiletools.commons.extensions.appLaunched
import com.simplemobiletools.commons.extensions.launchViewIntent
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.viewBinding
import com.simplemobiletools.commons.helpers.LICENSE_AUTOFITTEXTVIEW
@ -51,9 +48,9 @@ class MainActivity : BaseSimpleActivity() {
startActivity(Intent(this, TestDialogActivity::class.java))
}
binding.testButton.setOnClickListener {
ConfirmationDialog(this, FAKE_VERSION_APP_LABEL, positive = com.simplemobiletools.commons.R.string.ok, negative = 0) {
launchViewIntent(DEVELOPER_PLAY_STORE_URL)
}
WritePermissionDialog(this, mode = WritePermissionDialog.Mode.OpenDocumentTreeSDK30("")){
}
}
}