diff options
author | Iván Ávalos <avalos@disroot.org> | 2023-09-26 19:36:27 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2023-09-26 19:36:27 -0600 |
commit | 3e72d9b02e864f4f79ae494c67418031b7625659 (patch) | |
tree | 3d6d7ae3997b9372d50932e0e489dced12e5b07c /androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt | |
parent | 8765d82d3ad055945c6221e4f46bc38d903bf58d (diff) | |
parent | 3022b877d0cf9b7546c80953237c7bca5a4afa50 (diff) | |
download | etbsa-trackermap-mobile-3e72d9b02e864f4f79ae494c67418031b7625659.tar.gz etbsa-trackermap-mobile-3e72d9b02e864f4f79ae494c67418031b7625659.tar.bz2 etbsa-trackermap-mobile-3e72d9b02e864f4f79ae494c67418031b7625659.zip |
Merge branch 'main' of https://git.sr.ht/~avalos/trackermap-mobile
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt')
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt index bcee2ec..434ac44 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginViewModel.kt @@ -17,32 +17,46 @@ */ package mx.trackermap.TrackerMap.android.session +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.zhuinden.eventemitter.EventEmitter import com.zhuinden.eventemitter.EventSource import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import mx.trackermap.TrackerMap.client.models.SessionBody +import mx.trackermap.TrackerMap.controllers.NetworkController import mx.trackermap.TrackerMap.controllers.SessionController import org.koin.core.component.KoinComponent import org.koin.core.component.inject @DelicateCoroutinesApi class LoginViewModel : ViewModel(), KoinComponent { - + private val networkController: NetworkController by inject() private val sessionController: SessionController by inject() + private val _networkAvailable = MutableLiveData<Boolean?>(null) + val networkAvailable: LiveData<Boolean?> = _networkAvailable private val loginStateEmitter = EventEmitter<SessionController.LoginState>() val loginState: EventSource<SessionController.LoginState> = loginStateEmitter + val hasSession: Boolean get() = sessionController.hasSession init { viewModelScope.launch { + setupNetworkObserver() + } + viewModelScope.launch { setupLoginStateObserver() } } + private suspend fun setupNetworkObserver() { + networkController.networkAvailable.collect { + _networkAvailable.postValue(it) + } + } + private suspend fun setupLoginStateObserver() { sessionController.loginStateFlow.collect { it?.let { @@ -52,7 +66,7 @@ class LoginViewModel : ViewModel(), KoinComponent { } fun restoreSession() { - sessionController.restoreSession() + sessionController.getSession() } fun login(email: String, password: String, url: String, token: String?) { |