Fix white flash on app start (#1909)
## Description This fixes the brief full screen white flash when the app starts or reloads. I bisected to find the cause which was #1653. The newly added `Surface` uses `MaterialTheme` to set its colors. `MaterialTheme` defaults to a generic _light_ color scheme. So this PR applies the Wholphin's default purple theme, which will then be overridden once the app preferences are loaded. ### Related issues Mentioned in https://github.com/damontecres/Wholphin/issues/1576#issuecomment-5376373039 ### Testing Used emulator with "Don't keep activities" and repeatedly opened & closed the app to see if the white flash visually occurred ## Screenshots N/A ## AI or LLM usage None
This commit is contained in:
parent
f91bca18ff
commit
786b95a393
1 changed files with 48 additions and 48 deletions
|
|
@ -28,6 +28,7 @@ import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.navigation3.runtime.NavBackStack
|
import androidx.navigation3.runtime.NavBackStack
|
||||||
import androidx.tv.material3.ExperimentalTvMaterial3Api
|
import androidx.tv.material3.ExperimentalTvMaterial3Api
|
||||||
|
import androidx.tv.material3.MaterialTheme
|
||||||
import androidx.tv.material3.Surface
|
import androidx.tv.material3.Surface
|
||||||
import com.github.damontecres.wholphin.data.ServerRepository
|
import com.github.damontecres.wholphin.data.ServerRepository
|
||||||
import com.github.damontecres.wholphin.preferences.AppPreferences
|
import com.github.damontecres.wholphin.preferences.AppPreferences
|
||||||
|
|
@ -62,6 +63,7 @@ import com.github.damontecres.wholphin.ui.nav.Destination
|
||||||
import com.github.damontecres.wholphin.ui.playback.PlayExternalViewModel
|
import com.github.damontecres.wholphin.ui.playback.PlayExternalViewModel
|
||||||
import com.github.damontecres.wholphin.ui.showToast
|
import com.github.damontecres.wholphin.ui.showToast
|
||||||
import com.github.damontecres.wholphin.ui.theme.WholphinTheme
|
import com.github.damontecres.wholphin.ui.theme.WholphinTheme
|
||||||
|
import com.github.damontecres.wholphin.ui.theme.colors.PurpleThemeColors
|
||||||
import com.github.damontecres.wholphin.ui.util.ProvideLocalClock
|
import com.github.damontecres.wholphin.ui.util.ProvideLocalClock
|
||||||
import com.github.damontecres.wholphin.util.DebugLogTree
|
import com.github.damontecres.wholphin.util.DebugLogTree
|
||||||
import com.github.damontecres.wholphin.util.ExceptionHandler
|
import com.github.damontecres.wholphin.util.ExceptionHandler
|
||||||
|
|
@ -228,56 +230,54 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
viewModel.appStart(intent)
|
viewModel.appStart(intent)
|
||||||
setContent {
|
setContent {
|
||||||
Surface(
|
MaterialTheme(colorScheme = PurpleThemeColors.darkScheme) {
|
||||||
Modifier
|
Surface(Modifier.fillMaxSize()) {
|
||||||
.fillMaxSize()
|
val userPreferences by userPreferencesService.flow.collectAsState(null)
|
||||||
.background(Color.Black),
|
if (userPreferences == null) {
|
||||||
) {
|
// Show loading page if it is taking a while to get app preferences
|
||||||
val userPreferences by userPreferencesService.flow.collectAsState(null)
|
var showLoading by remember { mutableStateOf(false) }
|
||||||
if (userPreferences == null) {
|
LaunchedEffect(Unit) {
|
||||||
// Show loading page if it is taking a while to get app preferences
|
delay(500.milliseconds)
|
||||||
var showLoading by remember { mutableStateOf(false) }
|
Timber.i("Showing loading page")
|
||||||
LaunchedEffect(Unit) {
|
showLoading = true
|
||||||
delay(500.milliseconds)
|
|
||||||
Timber.i("Showing loading page")
|
|
||||||
showLoading = true
|
|
||||||
}
|
|
||||||
if (showLoading) {
|
|
||||||
Box(
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(Color.Black),
|
|
||||||
) {
|
|
||||||
LoadingPage()
|
|
||||||
}
|
}
|
||||||
}
|
if (showLoading) {
|
||||||
} else {
|
Box(
|
||||||
userPreferences?.let { userPreferences ->
|
modifier =
|
||||||
val appPreferences = userPreferences.appPreferences
|
Modifier
|
||||||
CoilConfig(
|
.fillMaxSize()
|
||||||
prefs = appPreferences,
|
.background(Color.Black),
|
||||||
okHttpClient = okHttpClient,
|
|
||||||
debugLogging = false,
|
|
||||||
enableCache = true,
|
|
||||||
)
|
|
||||||
LaunchedEffect(appPreferences.debugLogging) {
|
|
||||||
DebugLogTree.INSTANCE.enabled = appPreferences.debugLogging
|
|
||||||
}
|
|
||||||
CompositionLocalProvider(LocalImageUrlService provides imageUrlService) {
|
|
||||||
WholphinTheme(
|
|
||||||
true,
|
|
||||||
appThemeColors = appPreferences.interfacePreferences.appThemeColors,
|
|
||||||
) {
|
) {
|
||||||
ProvideLocalClock {
|
LoadingPage()
|
||||||
MainContent(
|
}
|
||||||
backStack = setupNavigationManager.backStack,
|
}
|
||||||
navigationManager = navigationManager,
|
} else {
|
||||||
userPreferences = userPreferences,
|
userPreferences?.let { userPreferences ->
|
||||||
backdropService = backdropService,
|
val appPreferences = userPreferences.appPreferences
|
||||||
screensaverService = screensaverService,
|
CoilConfig(
|
||||||
modifier = Modifier.fillMaxSize(),
|
prefs = appPreferences,
|
||||||
)
|
okHttpClient = okHttpClient,
|
||||||
|
debugLogging = false,
|
||||||
|
enableCache = true,
|
||||||
|
)
|
||||||
|
LaunchedEffect(appPreferences.debugLogging) {
|
||||||
|
DebugLogTree.INSTANCE.enabled = appPreferences.debugLogging
|
||||||
|
}
|
||||||
|
CompositionLocalProvider(LocalImageUrlService provides imageUrlService) {
|
||||||
|
WholphinTheme(
|
||||||
|
true,
|
||||||
|
appThemeColors = appPreferences.interfacePreferences.appThemeColors,
|
||||||
|
) {
|
||||||
|
ProvideLocalClock {
|
||||||
|
MainContent(
|
||||||
|
backStack = setupNavigationManager.backStack,
|
||||||
|
navigationManager = navigationManager,
|
||||||
|
userPreferences = userPreferences,
|
||||||
|
backdropService = backdropService,
|
||||||
|
screensaverService = screensaverService,
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue