diff options
author | Isidro Henoch <imhenoch@protonmail.com> | 2021-12-06 02:33:20 -0600 |
---|---|---|
committer | Isidro Henoch <imhenoch@protonmail.com> | 2021-12-06 02:33:20 -0600 |
commit | 4972774bb3d2b96a47b17c89d4bc6f9aeac27e25 (patch) | |
tree | 6a12ad7014afd141f774198385d8ec81810256f5 /androidApp/src/main/java/mx | |
parent | 93c204bcd190b242f1dea49e52f28c795e4d0b92 (diff) | |
download | etbsa-trackermap-mobile-4972774bb3d2b96a47b17c89d4bc6f9aeac27e25.tar.gz etbsa-trackermap-mobile-4972774bb3d2b96a47b17c89d4bc6f9aeac27e25.tar.bz2 etbsa-trackermap-mobile-4972774bb3d2b96a47b17c89d4bc6f9aeac27e25.zip |
WIP: Adds the token persistance
Diffstat (limited to 'androidApp/src/main/java/mx')
4 files changed, 14 insertions, 3 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt index a8efbf2..9331dcc 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt @@ -15,7 +15,7 @@ class TrackerApp: Application() { super.onCreate() val appModule = module { - single { "https://etbsa.net/api/" } + single { "https://etbsa.net/api" } single { SessionApi(get()) } viewModel { LoginViewModel(get(), get()) } diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginActivity.kt index 3aec7b8..3fbab80 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginActivity.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginActivity.kt @@ -1,8 +1,6 @@ package mx.trackermap.TrackerMap.android.session import android.os.Bundle -import android.os.PersistableBundle -import android.util.Log import androidx.appcompat.app.AppCompatActivity import mx.trackermap.TrackerMap.android.R diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt index 5039a7c..82d11d1 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/session/LoginFragment.kt @@ -32,6 +32,7 @@ class LoginFragment : Fragment() { setupEvents() setupObservers() + loginViewModel.restoreSession() } override fun onDestroyView() { 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 9df78aa..82c5bf9 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 @@ -29,6 +29,18 @@ class LoginViewModel( private val loginResultEmitter = EventEmitter<LoginResult>() val loginResult: EventSource<LoginResult> = loginResultEmitter + fun restoreSession() { + viewModelScope.launch { + try { + val user = sessionApi.sessionGet() + Log.d("LoginViewModel", user.toString()) + loginResultEmitter.emit(LoginResult.Success) + } catch (e: Exception) { + Log.d("LoginViewModel", "No session") + } + } + } + fun login() { val email = email.value!!.toString().trim() val password = password.value!!.toString().trim() |