Add splash screen

pull/3535/head
Alex Baker 8 months ago
parent d3fed98e64
commit 8abf1f0342

@ -181,6 +181,7 @@ dependencies {
implementation(libs.androidx.hilt.navigation)
implementation(libs.androidx.hilt.work)
implementation(libs.androidx.core.splashscreen)
implementation(libs.androidx.datastore)
implementation(libs.androidx.fragment.compose)
implementation(libs.androidx.lifecycle.runtime)

@ -623,10 +623,11 @@
android:theme="@style/TranslucentDialog"/>
<activity
android:launchMode="singleTask"
android:exported="true"
android:windowSoftInputMode="adjustResize"
android:name="com.todoroo.astrid.activity.MainActivity">
android:name="com.todoroo.astrid.activity.MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/Theme.App.Starting"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>

@ -30,6 +30,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.unit.dp
import androidx.core.content.IntentCompat.getParcelableExtra
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.compose.NavHost
@ -91,10 +92,15 @@ class MainActivity : AppCompatActivity() {
private var currentNightMode = 0
private var currentPro = false
private var actionMode: ActionMode? = null
private var isReady = false
/** @see android.app.Activity.onCreate
*/
override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
splashScreen.setKeepOnScreenCondition { !isReady }
super.onCreate(savedInstanceState)
theme.themeBase.set(this)
currentNightMode = nightMode
@ -117,6 +123,17 @@ class MainActivity : AppCompatActivity() {
primary = theme.themeColor.primaryColor,
) {
val navController = rememberNavController()
val hasAccount = viewModel
.accountExists
.collectAsStateWithLifecycle(null)
.value
LaunchedEffect(hasAccount) {
Timber.d("hasAccount=$hasAccount")
if (hasAccount == false) {
// TODO: navigate to add account screen
}
isReady = hasAccount != null
}
NavHost(
navController = navController,
startDestination = HomeDestination,

@ -14,6 +14,7 @@ import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
@ -83,6 +84,9 @@ class MainActivityViewModel @Inject constructor(
)
val state = _state.asStateFlow()
val accountExists: Flow<Boolean>
get() = caldavDao.watchAccountExists()
private val refreshReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
when (intent?.action) {

@ -61,4 +61,11 @@
<item name="android:windowShowWallpaper">true</item>
</style>
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/window_background</item>
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher_blue</item>
<item name="windowSplashScreenAnimationDuration">300</item>
<item name="postSplashScreenTheme">@style/Tasks</item>
</style>
</resources>

@ -60,6 +60,9 @@ abstract class CaldavDao {
@Query("SELECT * FROM caldav_accounts WHERE cda_id = :id")
abstract fun watchAccount(id: Long): Flow<CaldavAccount?>
@Query("SELECT EXISTS(SELECT 1 FROM caldav_accounts LIMIT 1)")
abstract fun watchAccountExists(): Flow<Boolean>
@Query("""
SELECT *
FROM caldav_accounts

@ -1274,6 +1274,9 @@
+| | +--- androidx.work:work-runtime-ktx:2.10.0 (c)
+| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 -> 2.1.20 (c)
+| \--- com.google.dagger:hilt-android:2.49 -> 2.56.2 (*)
++--- androidx.core:core-splashscreen:1.0.1
+| +--- androidx.annotation:annotation:1.2.0 -> 1.9.1 (*)
+| \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 2.1.20 (*)
++--- androidx.datastore:datastore-preferences:1.1.4 (*)
++--- androidx.fragment:fragment-compose:1.8.6
+| +--- androidx.compose.runtime:runtime:1.5.4 -> 1.7.8 (*)

@ -1630,6 +1630,9 @@
+| | +--- androidx.work:work-runtime-ktx:2.10.0 (c)
+| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.22 -> 2.1.20 (c)
+| \--- com.google.dagger:hilt-android:2.49 -> 2.56.2 (*)
++--- androidx.core:core-splashscreen:1.0.1
+| +--- androidx.annotation:annotation:1.2.0 -> 1.9.1 (*)
+| \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 2.1.20 (*)
++--- androidx.datastore:datastore-preferences:1.1.4 (*)
++--- androidx.fragment:fragment-compose:1.8.6
+| +--- androidx.compose.runtime:runtime:1.5.4 -> 1.7.8 (*)

Loading…
Cancel
Save