Created
November 1, 2020 16:53
-
-
Save adit-gudhel/cac63d5145f5ab2451a9ef623c0e5a25 to your computer and use it in GitHub Desktop.
com.gudhel.loginoauth.utils.SessionManager.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Session manager untuk menyimpan dan mengambil session dari SharedPreferences | |
*/ | |
class SessionManager(context: Context) { | |
private var prefs: SharedPreferences = context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE) | |
companion object { | |
const val ACCESS_TOKEN = "access_token" | |
} | |
/** | |
* Fungsi simpan access_token | |
*/ | |
fun saveAccessToken(token: String) { | |
val editor = prefs.edit() | |
editor.putString(ACCESS_TOKEN, token) | |
.apply() | |
} | |
/** | |
* Fungsi get access_token | |
*/ | |
fun fetchAccessToken(): String? { | |
return prefs.getString(ACCESS_TOKEN, null) | |
} | |
/** | |
* Fungsi delete access_token / clear shared preferences | |
*/ | |
fun deleteAccessToken() { | |
val editor = prefs.edit() | |
editor.clear() | |
.apply() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment