You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
package org.wntr.mdeditor
|
|
import android.content.Context
|
|
|
|
class CredentialManager(applicationContext: Context) {
|
|
val sharedPrefs= applicationContext.getSharedPreferences("prefs", Context.MODE_PRIVATE)
|
|
var instance = "nowhere"
|
|
get() =
|
|
if (field.equals("nowhere")) loadCredentialsFromSharedPrefs().instance
|
|
else field
|
|
|
|
var username = "nobody"
|
|
get() =
|
|
if (field.equals("nobody")) loadCredentialsFromSharedPrefs().username
|
|
else field
|
|
|
|
fun saveCredentialsToSharedPrefs(creds: Credentials) {
|
|
val (instance, username) = creds
|
|
|
|
sharedPrefs.edit().apply {
|
|
putString("instance", instance)
|
|
putString("username", username)
|
|
apply()
|
|
}
|
|
}
|
|
|
|
fun loadCredentialsFromSharedPrefs() : Credentials {
|
|
val instance = sharedPrefs.getString("instance", "nowhere")!!
|
|
val username = sharedPrefs.getString("username", "nobody")!!
|
|
return (Credentials(instance!!, username!!, "nothing"))
|
|
}
|
|
}
|
|
|
|
|