diff --git a/run/presentation/src/main/java/com/plcoding/run/presentation/run_overview/RunOverviewEvent.kt b/run/presentation/src/main/java/com/plcoding/run/presentation/run_overview/RunOverviewEvent.kt new file mode 100644 index 00000000..99037dde --- /dev/null +++ b/run/presentation/src/main/java/com/plcoding/run/presentation/run_overview/RunOverviewEvent.kt @@ -0,0 +1,5 @@ +package com.plcoding.run.presentation.run_overview + +sealed interface RunOverviewEvent { + data object OnLogout : RunOverviewEvent +} \ No newline at end of file diff --git a/run/presentation/src/main/java/com/plcoding/run/presentation/run_overview/RunOverviewScreen.kt b/run/presentation/src/main/java/com/plcoding/run/presentation/run_overview/RunOverviewScreen.kt index d3d17ab5..c7c40db3 100644 --- a/run/presentation/src/main/java/com/plcoding/run/presentation/run_overview/RunOverviewScreen.kt +++ b/run/presentation/src/main/java/com/plcoding/run/presentation/run_overview/RunOverviewScreen.kt @@ -29,6 +29,7 @@ import com.plcoding.core.presentation.designsystem.components.RuniqueFloatingAct import com.plcoding.core.presentation.designsystem.components.RuniqueScaffold import com.plcoding.core.presentation.designsystem.components.RuniqueToolbar import com.plcoding.core.presentation.designsystem.components.util.DropDownItem +import com.plcoding.core.presentation.ui.ObserveAsEvents import com.plcoding.run.presentation.R import com.plcoding.run.presentation.run_overview.components.RunListItem import org.koin.androidx.compose.koinViewModel @@ -40,13 +41,18 @@ fun RunOverviewScreenRoot( onAnalyticsClick: () -> Unit, viewModel: RunOverviewViewModel = koinViewModel(), ) { + ObserveAsEvents(flow = viewModel.events) { event -> + when (event) { + RunOverviewEvent.OnLogout -> onLogoutClick() + } + } + RunOverviewScreen( state = viewModel.state, onAction = { action -> when(action) { RunOverviewAction.OnAnalyticsClick -> onAnalyticsClick() RunOverviewAction.OnStartClick -> onStartRunClick() - RunOverviewAction.OnLogoutClick -> onLogoutClick() else -> Unit } viewModel.onAction(action) diff --git a/run/presentation/src/main/java/com/plcoding/run/presentation/run_overview/RunOverviewViewModel.kt b/run/presentation/src/main/java/com/plcoding/run/presentation/run_overview/RunOverviewViewModel.kt index 0f0a765f..d368a3b8 100644 --- a/run/presentation/src/main/java/com/plcoding/run/presentation/run_overview/RunOverviewViewModel.kt +++ b/run/presentation/src/main/java/com/plcoding/run/presentation/run_overview/RunOverviewViewModel.kt @@ -10,8 +10,10 @@ import com.plcoding.core.domain.run.RunRepository import com.plcoding.core.domain.run.SyncRunScheduler import com.plcoding.run.presentation.run_overview.mapper.toRunUi import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch import kotlin.time.Duration.Companion.minutes @@ -25,6 +27,9 @@ class RunOverviewViewModel( var state by mutableStateOf(RunOverviewState()) private set + private val eventChannel = Channel() + val events = eventChannel.receiveAsFlow() + init { viewModelScope.launch { syncRunScheduler.scheduleSync( @@ -62,6 +67,7 @@ class RunOverviewViewModel( runRepository.deleteAllRuns() runRepository.logout() sessionStorage.set(null) + eventChannel.send(RunOverviewEvent.OnLogout) } } } \ No newline at end of file