Commit c376ea2d authored by Niklas Fix's avatar Niklas Fix 🎓

fix "invalid auth" toast bug

parent d937577c
......@@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.preference.PreferenceManager
import de.akamu.tudarmstadt.BaseActivity
import de.akamu.tudarmstadt.R
import de.akamu.tudarmstadt.data.login.LoginDataSourceImpl
......@@ -22,13 +23,6 @@ class LoginActivity : BaseActivity(), LoginContract.View {
override lateinit var presenter: LoginContract.Presenter
override fun onStart() {
super.onStart()
if (!presenter.unauthorized) {
presenter.autoLogin()
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTheme(R.style.OffWhiteTheme)
......@@ -39,7 +33,8 @@ class LoginActivity : BaseActivity(), LoginContract.View {
this
)
presenter.unauthorized = intent.getBooleanExtra(Constants.KEY_UNAUTHORIZED, false)
val isUnauthorized = intent.getBooleanExtra(Constants.KEY_UNAUTHORIZED, false)
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(Constants.PREF_UNAUTHORIZED, isUnauthorized).apply()
logo_login.start()
......@@ -69,6 +64,13 @@ class LoginActivity : BaseActivity(), LoginContract.View {
}
}
override fun onStart() {
super.onStart()
if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.PREF_UNAUTHORIZED, true)) {
presenter.autoLogin()
}
}
override fun showLoginFailed() {
toast(getString(R.string.invalid_username_or_password))
}
......@@ -89,6 +91,7 @@ class LoginActivity : BaseActivity(), LoginContract.View {
override fun isLoggedIn(loggedIn: Boolean, appUser: User) {
if (loggedIn) {
AppUserUtil.updateLocalAppUser(appUser, this)
PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(Constants.PREF_UNAUTHORIZED, false).apply()
startActivity(Intent(this, MainActivity::class.java))
finish()
}
......
......@@ -41,8 +41,6 @@ interface LoginContract {
interface Presenter : BasePresenter {
var unauthorized : Boolean
/** Checks if the user is already logged in and if so, navigates to MainActivity */
fun autoLogin()
......
package de.akamu.tudarmstadt.features.login
import androidx.preference.PreferenceManager
import de.akamu.tudarmstadt.api.AkamuFirebase
import de.akamu.tudarmstadt.api.V2API
import de.akamu.tudarmstadt.data.login.LoginDataSource
import de.akamu.tudarmstadt.model.User
import de.akamu.tudarmstadt.util.Constants
class LoginPresenter(private val interactor: LoginInteractor, var view: LoginContract.View?) : LoginContract.Presenter {
override var unauthorized: Boolean = false
init {
view?.presenter = this
}
......
......@@ -54,5 +54,6 @@ class Constants {
const val BUG_REPORTS_ENABLED_KEY = "BUG_REPORTS_ENABLED_KEY"
const val IS_NIGHT_MODE = "IS_NIGHT_MODE"
const val USER_LANG = "USER_LANG"
const val PREF_UNAUTHORIZED = "PREF_UNAUTHORIZED"
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment