Added saving activity xD

pull/1824/head
Oussama Hafferssas 10 months ago
parent 76eafc42e8
commit c8428fab3e

@ -92,6 +92,8 @@ class MainActivity : ComponentActivity() {
} }
} }
viewModel.saveActivity(this)
// Keep the splash screen on-screen until the UI state is loaded. This condition is // Keep the splash screen on-screen until the UI state is loaded. This condition is
// evaluated each time the app needs to be redrawn so it should be fast to avoid blocking // evaluated each time the app needs to be redrawn so it should be fast to avoid blocking
// the UI. // the UI.

@ -16,6 +16,7 @@
package com.google.samples.apps.nowinandroid package com.google.samples.apps.nowinandroid
import android.content.Context
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading
@ -33,6 +34,9 @@ import javax.inject.Inject
class MainActivityViewModel @Inject constructor( class MainActivityViewModel @Inject constructor(
userDataRepository: UserDataRepository, userDataRepository: UserDataRepository,
) : ViewModel() { ) : ViewModel() {
private lateinit var _context: Context
val uiState: StateFlow<MainActivityUiState> = userDataRepository.userData.map { val uiState: StateFlow<MainActivityUiState> = userDataRepository.userData.map {
Success(it) Success(it)
}.stateIn( }.stateIn(
@ -40,6 +44,10 @@ class MainActivityViewModel @Inject constructor(
initialValue = Loading, initialValue = Loading,
started = SharingStarted.WhileSubscribed(5_000), started = SharingStarted.WhileSubscribed(5_000),
) )
fun saveActivity(context: Context) {
_context = context
}
} }
sealed interface MainActivityUiState { sealed interface MainActivityUiState {

Loading…
Cancel
Save