From cf97899ec14e994fbbf85e9f5e33cac61bf5ba0e Mon Sep 17 00:00:00 2001 From: DianQK Date: Wed, 3 May 2023 07:14:27 +0800 Subject: [PATCH 1/2] Remove note loading state --- .../main/java/org/dianqk/ruslin/ui/page/notes/NotesPage.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/dianqk/ruslin/ui/page/notes/NotesPage.kt b/app/src/main/java/org/dianqk/ruslin/ui/page/notes/NotesPage.kt index fbe29d0..699e1e9 100644 --- a/app/src/main/java/org/dianqk/ruslin/ui/page/notes/NotesPage.kt +++ b/app/src/main/java/org/dianqk/ruslin/ui/page/notes/NotesPage.kt @@ -215,9 +215,9 @@ fun NotesPage( } } if (notes == null) { - ContentLoadingState { - Text(text = stringResource(id = R.string.notes_loading)) - } +// ContentLoadingState { +// Text(text = stringResource(id = R.string.notes_loading)) +// } } else if (notes.isEmpty()) { ContentEmptyState { Text(text = stringResource(id = R.string.create_a_note)) From c273af5fcc2648b1ad0e8c9c754c2316a8d0749d Mon Sep 17 00:00:00 2001 From: DianQK Date: Wed, 3 May 2023 10:09:24 +0800 Subject: [PATCH 2/2] Add a splash screen and set the startup theme manually --- app/build.gradle.kts | 2 ++ app/src/main/AndroidManifest.xml | 4 ++-- .../java/org/dianqk/ruslin/MainActivity.kt | 14 +++++++++++++ .../java/org/dianqk/ruslin/data/Settings.kt | 2 +- .../data/preference/DarkThemePreference.kt | 14 +++++++------ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/themes.xml | 20 ++++++++++++------- 7 files changed, 41 insertions(+), 16 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 60cd8ae..3d9f467 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -186,6 +186,8 @@ dependencies { implementation("androidx.datastore:datastore-preferences:1.0.0") + implementation("androidx.core:core-splashscreen:1.0.1") + testImplementation(libs.junit) androidTestImplementation(libs.androidx.test.ext.junit) androidTestImplementation(libs.androidx.test.espresso.core) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 74fe7e5..5a4bb2d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,13 +14,13 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/Theme.Ruslin" + android:theme="@style/Theme.Ruslin.Launcher" android:windowSoftInputMode="adjustResize" tools:targetApi="33"> + android:theme="@style/Theme.Ruslin.Launcher"> diff --git a/app/src/main/java/org/dianqk/ruslin/MainActivity.kt b/app/src/main/java/org/dianqk/ruslin/MainActivity.kt index 0a8623c..01372dc 100644 --- a/app/src/main/java/org/dianqk/ruslin/MainActivity.kt +++ b/app/src/main/java/org/dianqk/ruslin/MainActivity.kt @@ -3,10 +3,15 @@ package org.dianqk.ruslin import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.view.WindowCompat import dagger.hilt.android.AndroidEntryPoint +import org.dianqk.ruslin.data.DataStoreKeys import org.dianqk.ruslin.data.SettingsProvider +import org.dianqk.ruslin.data.dataStore +import org.dianqk.ruslin.data.get import org.dianqk.ruslin.data.languages +import org.dianqk.ruslin.data.preference.DarkThemePreference import org.dianqk.ruslin.data.preference.LanguagesPreference import org.dianqk.ruslin.ui.RuslinApp @@ -14,6 +19,15 @@ import org.dianqk.ruslin.ui.RuslinApp class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { + // Manually set the postSplashScreenTheme + setTheme( + when (DarkThemePreference.fromInt(dataStore.get(DataStoreKeys.DarkTheme))) { + DarkThemePreference.UseDeviceTheme -> R.style.Theme_Ruslin + DarkThemePreference.ON -> R.style.Theme_Ruslin_Dark + DarkThemePreference.OFF -> R.style.Theme_Ruslin_Light + } + ) + installSplashScreen() super.onCreate(savedInstanceState) WindowCompat.setDecorFitsSystemWindows(window, false) diff --git a/app/src/main/java/org/dianqk/ruslin/data/Settings.kt b/app/src/main/java/org/dianqk/ruslin/data/Settings.kt index ed4472d..c5ffc15 100644 --- a/app/src/main/java/org/dianqk/ruslin/data/Settings.kt +++ b/app/src/main/java/org/dianqk/ruslin/data/Settings.kt @@ -186,7 +186,7 @@ fun SettingsProvider( context.dataStore.data.map { it.toSettings() } - }.collectAsState(initial = Settings()).value + }.collectAsState(initial = runBlocking { context.dataStore.data.first().toSettings() }).value CompositionLocalProvider( LocalLanguages provides settings.languages, diff --git a/app/src/main/java/org/dianqk/ruslin/data/preference/DarkThemePreference.kt b/app/src/main/java/org/dianqk/ruslin/data/preference/DarkThemePreference.kt index 44cb06c..c4cb641 100644 --- a/app/src/main/java/org/dianqk/ruslin/data/preference/DarkThemePreference.kt +++ b/app/src/main/java/org/dianqk/ruslin/data/preference/DarkThemePreference.kt @@ -45,13 +45,15 @@ sealed class DarkThemePreference(val value: Int) { val default = UseDeviceTheme val values = listOf(UseDeviceTheme, ON, OFF) + fun fromInt(i: Int?) = when (i) { + 0 -> UseDeviceTheme + 1 -> ON + 2 -> OFF + else -> default + } + fun fromPreferences(preferences: Preferences) = - when (preferences[DataStoreKeys.DarkTheme.key]) { - 0 -> UseDeviceTheme - 1 -> ON - 2 -> OFF - else -> default - } + fromInt(preferences[DataStoreKeys.DarkTheme.key]) } } diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f8c6127..ee9b841 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,4 +7,5 @@ #FF018786 #FF000000 #FFFFFFFF + #FFA72145 \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index a775666..dda4a93 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,24 +1,30 @@ - - - + + \ No newline at end of file