mirror of
https://github.com/Michatec/Radio.git
synced 2026-11-16 21:36:53 +01:00
feat(ui): implement RadioTheme with custom color support
Created a centralized `RadioTheme` component that handles system dark mode and custom background colors based on user preferences. Updated `LicenseFragment` to use the new theme.
This commit is contained in:
1 parent
23d9b4e599
commit
7d69846bb0
2 files changed
+57
-7
No files matched your search
@@ -4,17 +4,15 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.michatec.radio.ui.theme.RadioTheme
|
||||
import com.mikepenz.aboutlibraries.Libs
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
|
||||
import com.mikepenz.aboutlibraries.util.withContext
|
||||
@@ -34,10 +32,7 @@ class LicenseFragment : Fragment() {
|
||||
Libs.Builder().withContext(context).build()
|
||||
}
|
||||
|
||||
val isDark = isSystemInDarkTheme()
|
||||
MaterialTheme(
|
||||
colorScheme = if (isDark) darkColorScheme() else lightColorScheme()
|
||||
) {
|
||||
RadioTheme {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.michatec.radio.ui.theme
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.luminance
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.michatec.radio.helpers.PreferencesHelper
|
||||
import com.michatec.radio.helpers.ThemeHelper
|
||||
|
||||
@Composable
|
||||
fun RadioTheme(
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val customThemeEnabled = PreferencesHelper.loadCustomThemeEnabled()
|
||||
val isDark: Boolean
|
||||
val backgroundColor: Color
|
||||
|
||||
if (customThemeEnabled) {
|
||||
var colorInt = PreferencesHelper.loadCustomThemeColor(context)
|
||||
val index = PreferencesHelper.loadCustomThemeIndex()
|
||||
if (index != -1) {
|
||||
val colors = ThemeHelper.getPredefinedColors(context)
|
||||
if (index < colors.size) {
|
||||
colorInt = colors[index]
|
||||
}
|
||||
}
|
||||
backgroundColor = Color(colorInt)
|
||||
isDark = backgroundColor.luminance() < 0.5f
|
||||
} else {
|
||||
isDark = isSystemInDarkTheme()
|
||||
backgroundColor = if (isDark) Color(0xFF1C1B1F) else Color(0xFFFFFBFE)
|
||||
}
|
||||
|
||||
val colorScheme = if (isDark) {
|
||||
darkColorScheme(
|
||||
background = backgroundColor,
|
||||
surface = backgroundColor
|
||||
)
|
||||
} else {
|
||||
lightColorScheme(
|
||||
background = backgroundColor,
|
||||
surface = backgroundColor
|
||||
)
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user