From 12cf0eecafc8b6364ad2e63676489341f91af8f5 Mon Sep 17 00:00:00 2001 From: Isidro Henoch Date: Mon, 6 Dec 2021 02:33:20 -0600 Subject: WIP: Adds the token persistance --- .../main/java/mx/trackermap/TrackerMap/android/TrackerApp.kt | 2 +- .../trackermap/TrackerMap/android/session/LoginActivity.kt | 2 -- .../trackermap/TrackerMap/android/session/LoginFragment.kt | 1 + .../trackermap/TrackerMap/android/session/LoginViewModel.kt | 12 ++++++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) (limited to 'androidApp') 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() val loginResult: EventSource = 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() -- cgit v1.2.3