Skip to content

Commit

Permalink
Call app start in SplashViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz committed Feb 28, 2025
1 parent 51d4336 commit dde2227
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ val splashModule = module {
analytics = get(),
appInfoProvider = get(),
ioDispatcher = get(named(IODispatcher)),
appStart = get(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun SplashScreen(

val splashComplete by rememberUpdatedState(onSplashComplete)
LaunchedEffect(key1 = Unit) {
delay(2000) // TODO - replace back
delay(1200)
splashComplete()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kotlinx.coroutines.withContext
import xyz.ksharma.krail.core.analytics.Analytics
import xyz.ksharma.krail.core.analytics.event.AnalyticsEvent
import xyz.ksharma.krail.core.appinfo.AppInfoProvider
import xyz.ksharma.krail.core.appstart.AppStart
import xyz.ksharma.krail.core.log.log
import xyz.ksharma.krail.sandook.Sandook
import xyz.ksharma.krail.taj.theme.DEFAULT_THEME_STYLE
Expand All @@ -22,6 +23,7 @@ class SplashViewModel(
private val analytics: Analytics,
private val appInfoProvider: AppInfoProvider,
private val ioDispatcher: CoroutineDispatcher,
private val appStart: AppStart,
) : ViewModel() {

private val _uiState: MutableStateFlow<KrailThemeStyle> =
Expand All @@ -33,6 +35,7 @@ class SplashViewModel(
.onStart {
loadKrailThemeStyle()
trackAppStartEvent()
appStart.start()
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), true)

private suspend fun trackAppStartEvent() = with(appInfoProvider.getAppInfo()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class RealAppStart(
private val protoParser: ProtoParser,
private val sandook: Sandook,
) : AppStart {

init {
log("RealAppStart created.")
}

override fun start() {
coroutineScope.launch {
parseAndInsertNswStopsIfNeeded()
Expand All @@ -30,7 +35,7 @@ class RealAppStart(
* Parses and inserts NSW_STOPS data in the database if they are not already inserted.
*/
private suspend fun parseAndInsertNswStopsIfNeeded() = runCatching {
if (isStopsNotInserted()) {
if (shouldInsertStops()) {
protoParser.parseAndInsertStops()
} else {
log("Stops already inserted in the database.")
Expand All @@ -40,7 +45,7 @@ class RealAppStart(
// TODO - Firebase performance track.
}

private fun isStopsNotInserted(): Boolean {
private fun shouldInsertStops(): Boolean {
return sandook.stopsCount() == 0 || sandook.productClassCount() == 0
}
}

0 comments on commit dde2227

Please sign in to comment.