Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add splash screen #40

Merged
merged 2 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.Ruslin">
android:theme="@style/Theme.Ruslin.Launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/org/dianqk/ruslin/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,31 @@ 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

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

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/dianqk/ruslin/data/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="ic_launcher_background">#FFA72145</color>
</resources>
20 changes: 13 additions & 7 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Ruslin" parent="Theme.Material3.DayNight">
<style name="Theme.Ruslin" parent="Theme.Material3.DayNight.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">?attr/isLightTheme</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLightNavigationBar">?attr/isLightTheme</item>
</style>

<style name="Theme.Ruslin.Light" parent="Theme.Material3.Light">
<style name="Theme.Ruslin.Light" parent="Theme.Material3.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">?attr/isLightTheme</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLightNavigationBar">?attr/isLightTheme</item>
<item name="android:windowLightNavigationBar">true</item>
</style>

<style name="Theme.Ruslin.Dark" parent="Theme.Material3.Dark">
<style name="Theme.Ruslin.Dark" parent="Theme.Material3.Dark.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">?attr/isLightTheme</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLightNavigationBar">?attr/isLightTheme</item>
<item name="android:windowLightNavigationBar">false</item>
</style>

<style name="Theme.Ruslin.Launcher" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/ic_launcher_background</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
<!-- <item name="postSplashScreenTheme">@style/Theme.Ruslin</item>-->
</style>
</resources>