From fb10dce89ec219a123eb4c163c9a09e91bba0e30 Mon Sep 17 00:00:00 2001 From: Fabian Zobrist Date: Thu, 19 Jan 2023 19:47:34 +0100 Subject: [PATCH] Remove old files. Add theme and apply it --- .../me/zobrist/tichucounter/MainActivity.kt | 3 +- .../java/me/zobrist/tichucounter/ui/Color.kt | 67 ++++++++++++++ .../zobrist/tichucounter/ui/FragmentBase.kt | 32 ------- .../java/me/zobrist/tichucounter/ui/Theme.kt | 90 +++++++++++++++++++ .../ui/settings/SettingsFragment.kt | 30 ------- app/src/main/res/xml/root_preferences.xml | 28 ------ 6 files changed, 159 insertions(+), 91 deletions(-) create mode 100644 app/src/main/java/me/zobrist/tichucounter/ui/Color.kt delete mode 100644 app/src/main/java/me/zobrist/tichucounter/ui/FragmentBase.kt create mode 100644 app/src/main/java/me/zobrist/tichucounter/ui/Theme.kt delete mode 100644 app/src/main/java/me/zobrist/tichucounter/ui/settings/SettingsFragment.kt delete mode 100644 app/src/main/res/xml/root_preferences.xml diff --git a/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt b/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt index ff0f02b..660aa5d 100644 --- a/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt +++ b/app/src/main/java/me/zobrist/tichucounter/MainActivity.kt @@ -27,6 +27,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import me.zobrist.tichucounter.domain.TopBarAction import me.zobrist.tichucounter.repository.GameRepository +import me.zobrist.tichucounter.ui.AppTheme import me.zobrist.tichucounter.ui.MainViewModel import me.zobrist.tichucounter.ui.counter.* import me.zobrist.tichucounter.ui.history.HistoryList @@ -63,7 +64,7 @@ class MainActivity : BaseActivity() { navController: NavHostController ) { - MaterialTheme() { + AppTheme() { Scaffold( topBar = { TopBar(drawerState, scope, mainViewModel.topBarActions) }) { diff --git a/app/src/main/java/me/zobrist/tichucounter/ui/Color.kt b/app/src/main/java/me/zobrist/tichucounter/ui/Color.kt new file mode 100644 index 0000000..3b116a5 --- /dev/null +++ b/app/src/main/java/me/zobrist/tichucounter/ui/Color.kt @@ -0,0 +1,67 @@ +package me.zobrist.tichucounter.ui +import androidx.compose.ui.graphics.Color + +val md_theme_light_primary = Color(0xFFBE0034) +val md_theme_light_onPrimary = Color(0xFFFFFFFF) +val md_theme_light_primaryContainer = Color(0xFFFFDADA) +val md_theme_light_onPrimaryContainer = Color(0xFF40000B) +val md_theme_light_secondary = Color(0xFF6E5D00) +val md_theme_light_onSecondary = Color(0xFFFFFFFF) +val md_theme_light_secondaryContainer = Color(0xFFFFE261) +val md_theme_light_onSecondaryContainer = Color(0xFF221B00) +val md_theme_light_tertiary = Color(0xFF76592F) +val md_theme_light_onTertiary = Color(0xFFFFFFFF) +val md_theme_light_tertiaryContainer = Color(0xFFFFDDB1) +val md_theme_light_onTertiaryContainer = Color(0xFF291800) +val md_theme_light_error = Color(0xFFBA1A1A) +val md_theme_light_errorContainer = Color(0xFFFFDAD6) +val md_theme_light_onError = Color(0xFFFFFFFF) +val md_theme_light_onErrorContainer = Color(0xFF410002) +val md_theme_light_background = Color(0xFFFFFBFF) +val md_theme_light_onBackground = Color(0xFF201A1A) +val md_theme_light_surface = Color(0xFFFFFBFF) +val md_theme_light_onSurface = Color(0xFF201A1A) +val md_theme_light_surfaceVariant = Color(0xFFF4DDDD) +val md_theme_light_onSurfaceVariant = Color(0xFF524343) +val md_theme_light_outline = Color(0xFF857373) +val md_theme_light_inverseOnSurface = Color(0xFFFBEEED) +val md_theme_light_inverseSurface = Color(0xFF362F2F) +val md_theme_light_inversePrimary = Color(0xFFFFB3B5) +val md_theme_light_shadow = Color(0xFF000000) +val md_theme_light_surfaceTint = Color(0xFFBE0034) +val md_theme_light_outlineVariant = Color(0xFFD7C1C1) +val md_theme_light_scrim = Color(0xFF000000) + +val md_theme_dark_primary = Color(0xFFFFB3B5) +val md_theme_dark_onPrimary = Color(0xFF680018) +val md_theme_dark_primaryContainer = Color(0xFF920026) +val md_theme_dark_onPrimaryContainer = Color(0xFFFFDADA) +val md_theme_dark_secondary = Color(0xFFE6C500) +val md_theme_dark_onSecondary = Color(0xFF3A3000) +val md_theme_dark_secondaryContainer = Color(0xFF534600) +val md_theme_dark_onSecondaryContainer = Color(0xFFFFE261) +val md_theme_dark_tertiary = Color(0xFFE6C18D) +val md_theme_dark_onTertiary = Color(0xFF422C05) +val md_theme_dark_tertiaryContainer = Color(0xFF5C421A) +val md_theme_dark_onTertiaryContainer = Color(0xFFFFDDB1) +val md_theme_dark_error = Color(0xFFFFB4AB) +val md_theme_dark_errorContainer = Color(0xFF93000A) +val md_theme_dark_onError = Color(0xFF690005) +val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6) +val md_theme_dark_background = Color(0xFF201A1A) +val md_theme_dark_onBackground = Color(0xFFECE0DF) +val md_theme_dark_surface = Color(0xFF201A1A) +val md_theme_dark_onSurface = Color(0xFFECE0DF) +val md_theme_dark_surfaceVariant = Color(0xFF524343) +val md_theme_dark_onSurfaceVariant = Color(0xFFD7C1C1) +val md_theme_dark_outline = Color(0xFF9F8C8C) +val md_theme_dark_inverseOnSurface = Color(0xFF201A1A) +val md_theme_dark_inverseSurface = Color(0xFFECE0DF) +val md_theme_dark_inversePrimary = Color(0xFFBE0034) +val md_theme_dark_shadow = Color(0xFF000000) +val md_theme_dark_surfaceTint = Color(0xFFFFB3B5) +val md_theme_dark_outlineVariant = Color(0xFF524343) +val md_theme_dark_scrim = Color(0xFF000000) + + +val seed = Color(0xFFED0043) diff --git a/app/src/main/java/me/zobrist/tichucounter/ui/FragmentBase.kt b/app/src/main/java/me/zobrist/tichucounter/ui/FragmentBase.kt deleted file mode 100644 index 64055b7..0000000 --- a/app/src/main/java/me/zobrist/tichucounter/ui/FragmentBase.kt +++ /dev/null @@ -1,32 +0,0 @@ -package me.zobrist.tichucounter.ui - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import androidx.viewbinding.ViewBinding - -abstract class FragmentBase : Fragment() { - - private var _binding: VB? = null - abstract val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> VB - - // This property is only valid between onCreateView and - // onDestroyView. - protected val binding get() = _binding!! - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - _binding = bindingInflater.invoke(inflater, container, false) - return binding.root - } - - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } -} \ No newline at end of file diff --git a/app/src/main/java/me/zobrist/tichucounter/ui/Theme.kt b/app/src/main/java/me/zobrist/tichucounter/ui/Theme.kt new file mode 100644 index 0000000..c89e3f4 --- /dev/null +++ b/app/src/main/java/me/zobrist/tichucounter/ui/Theme.kt @@ -0,0 +1,90 @@ +package me.zobrist.tichucounter.ui + +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.runtime.Composable + + +private val LightColors = lightColorScheme( + primary = md_theme_light_primary, + onPrimary = md_theme_light_onPrimary, + primaryContainer = md_theme_light_primaryContainer, + onPrimaryContainer = md_theme_light_onPrimaryContainer, + secondary = md_theme_light_secondary, + onSecondary = md_theme_light_onSecondary, + secondaryContainer = md_theme_light_secondaryContainer, + onSecondaryContainer = md_theme_light_onSecondaryContainer, + tertiary = md_theme_light_tertiary, + onTertiary = md_theme_light_onTertiary, + tertiaryContainer = md_theme_light_tertiaryContainer, + onTertiaryContainer = md_theme_light_onTertiaryContainer, + error = md_theme_light_error, + errorContainer = md_theme_light_errorContainer, + onError = md_theme_light_onError, + onErrorContainer = md_theme_light_onErrorContainer, + background = md_theme_light_background, + onBackground = md_theme_light_onBackground, + surface = md_theme_light_surface, + onSurface = md_theme_light_onSurface, + surfaceVariant = md_theme_light_surfaceVariant, + onSurfaceVariant = md_theme_light_onSurfaceVariant, + outline = md_theme_light_outline, + inverseOnSurface = md_theme_light_inverseOnSurface, + inverseSurface = md_theme_light_inverseSurface, + inversePrimary = md_theme_light_inversePrimary, + surfaceTint = md_theme_light_surfaceTint, + outlineVariant = md_theme_light_outlineVariant, + scrim = md_theme_light_scrim, +) + + +private val DarkColors = darkColorScheme( + primary = md_theme_dark_primary, + onPrimary = md_theme_dark_onPrimary, + primaryContainer = md_theme_dark_primaryContainer, + onPrimaryContainer = md_theme_dark_onPrimaryContainer, + secondary = md_theme_dark_secondary, + onSecondary = md_theme_dark_onSecondary, + secondaryContainer = md_theme_dark_secondaryContainer, + onSecondaryContainer = md_theme_dark_onSecondaryContainer, + tertiary = md_theme_dark_tertiary, + onTertiary = md_theme_dark_onTertiary, + tertiaryContainer = md_theme_dark_tertiaryContainer, + onTertiaryContainer = md_theme_dark_onTertiaryContainer, + error = md_theme_dark_error, + errorContainer = md_theme_dark_errorContainer, + onError = md_theme_dark_onError, + onErrorContainer = md_theme_dark_onErrorContainer, + background = md_theme_dark_background, + onBackground = md_theme_dark_onBackground, + surface = md_theme_dark_surface, + onSurface = md_theme_dark_onSurface, + surfaceVariant = md_theme_dark_surfaceVariant, + onSurfaceVariant = md_theme_dark_onSurfaceVariant, + outline = md_theme_dark_outline, + inverseOnSurface = md_theme_dark_inverseOnSurface, + inverseSurface = md_theme_dark_inverseSurface, + inversePrimary = md_theme_dark_inversePrimary, + surfaceTint = md_theme_dark_surfaceTint, + outlineVariant = md_theme_dark_outlineVariant, + scrim = md_theme_dark_scrim, +) + +@Composable +fun AppTheme( + useDarkTheme: Boolean = isSystemInDarkTheme(), + content: @Composable() () -> Unit +) { + val colors = if (!useDarkTheme) { + LightColors + } else { + DarkColors + } + + MaterialTheme( + colorScheme = colors, + content = content + ) +} \ No newline at end of file diff --git a/app/src/main/java/me/zobrist/tichucounter/ui/settings/SettingsFragment.kt b/app/src/main/java/me/zobrist/tichucounter/ui/settings/SettingsFragment.kt deleted file mode 100644 index 3f91255..0000000 --- a/app/src/main/java/me/zobrist/tichucounter/ui/settings/SettingsFragment.kt +++ /dev/null @@ -1,30 +0,0 @@ -package me.zobrist.tichucounter.ui.settings - -import android.os.Build -import android.os.Bundle -import androidx.preference.ListPreference -import androidx.preference.PreferenceFragmentCompat -import me.zobrist.tichucounter.R - -class SettingsFragment : PreferenceFragmentCompat() { - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - setPreferencesFromResource(R.xml.root_preferences, rootKey) - - val index = when (getCurrentLocale()) { - "de" -> 1 - "en" -> 0 - else -> 0 - } - - findPreference("language")?.setValueIndex(index) - } - - private fun getCurrentLocale(): String? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - resources.configuration.locales.get(0).language - } else { - @Suppress("DEPRECATION") - resources.configuration.locale.language - } - } -} \ No newline at end of file diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml deleted file mode 100644 index 1d682e2..0000000 --- a/app/src/main/res/xml/root_preferences.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file