Clear settings on logout (#395)
This commit is contained in:
parent
78d5744139
commit
ca5186d20a
@ -14,11 +14,11 @@ import android.view.MenuItem
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
||||||
import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse
|
import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse
|
||||||
import apps.amine.bou.readerforselfoss.databinding.ActivityLoginBinding
|
import apps.amine.bou.readerforselfoss.databinding.ActivityLoginBinding
|
||||||
import apps.amine.bou.readerforselfoss.themes.AppColors
|
import apps.amine.bou.readerforselfoss.themes.AppColors
|
||||||
import apps.amine.bou.readerforselfoss.utils.Config
|
|
||||||
import apps.amine.bou.readerforselfoss.utils.isBaseUrlValid
|
import apps.amine.bou.readerforselfoss.utils.isBaseUrlValid
|
||||||
import apps.amine.bou.readerforselfoss.utils.network.isNetworkAccessible
|
import apps.amine.bou.readerforselfoss.utils.network.isNetworkAccessible
|
||||||
import com.mikepenz.aboutlibraries.LibsBuilder
|
import com.mikepenz.aboutlibraries.LibsBuilder
|
||||||
@ -52,7 +52,7 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
handleBaseUrlFail()
|
handleBaseUrlFail()
|
||||||
|
|
||||||
settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
|
settings = PreferenceManager.getDefaultSharedPreferences(applicationContext)
|
||||||
userIdentifier = settings.getString("unique_id", "")!!
|
userIdentifier = settings.getString("unique_id", "")!!
|
||||||
|
|
||||||
editor = settings.edit()
|
editor = settings.edit()
|
||||||
|
@ -4,11 +4,12 @@ import android.app.Activity
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import apps.amine.bou.readerforselfoss.LoginActivity
|
import apps.amine.bou.readerforselfoss.LoginActivity
|
||||||
|
|
||||||
class Config(c: Context) {
|
class Config(c: Context) {
|
||||||
|
|
||||||
val settings: SharedPreferences = c.getSharedPreferences(settingsName, Context.MODE_PRIVATE)
|
val settings: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(c)
|
||||||
|
|
||||||
val baseUrl: String
|
val baseUrl: String
|
||||||
get() = settings.getString("url", "")!!
|
get() = settings.getString("url", "")!!
|
||||||
@ -42,17 +43,15 @@ class Config(c: Context) {
|
|||||||
|
|
||||||
var apiVersion = 0
|
var apiVersion = 0
|
||||||
|
|
||||||
|
/* Execute logout and clear all settings to default */
|
||||||
fun logoutAndRedirect(
|
fun logoutAndRedirect(
|
||||||
c: Context,
|
c: Context,
|
||||||
callingActivity: Activity,
|
callingActivity: Activity,
|
||||||
editor: SharedPreferences.Editor,
|
editor: SharedPreferences.Editor,
|
||||||
baseUrlFail: Boolean = false
|
baseUrlFail: Boolean = false
|
||||||
): Boolean {
|
): Boolean {
|
||||||
editor.remove("url")
|
val settings = PreferenceManager.getDefaultSharedPreferences(c)
|
||||||
editor.remove("login")
|
settings.edit().clear().commit()
|
||||||
editor.remove("password")
|
|
||||||
editor.remove("apiVersionMajor")
|
|
||||||
editor.apply()
|
|
||||||
val intent = Intent(c, LoginActivity::class.java)
|
val intent = Intent(c, LoginActivity::class.java)
|
||||||
if (baseUrlFail) {
|
if (baseUrlFail) {
|
||||||
intent.putExtra("baseUrlFail", baseUrlFail)
|
intent.putExtra("baseUrlFail", baseUrlFail)
|
||||||
|
Loading…
Reference in New Issue
Block a user