Created
May 7, 2019 20:12
-
-
Save Younes-Charfaoui/129e7afa42b7411308abadc10e984da2 to your computer and use it in GitHub Desktop.
PreferenceManager for the AppIntro
This file contains 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
package com.example.introsliders | |
import android.annotation.SuppressLint | |
import android.content.Context | |
import android.content.SharedPreferences | |
class PreferencesManager @SuppressLint("CommitPrefEdits") | |
constructor(context: Context) { | |
private val preferences: SharedPreferences | |
private val editor: SharedPreferences.Editor | |
init { | |
preferences = context.getSharedPreferences(PREFERENCE_CONFIGURATION_NAME, PRIVATE_MODE) | |
editor = preferences.edit() | |
} | |
fun isFirstRun() = preferences.getBoolean(FIRST_TIME, true) | |
fun setFirstRun() { | |
editor.putBoolean(FIRST_TIME, false).commit() | |
editor.commit() | |
} | |
companion object { | |
private const val PRIVATE_MODE = 0 | |
private const val PREFERENCE_CONFIGURATION_NAME = "configuration" | |
private const val FIRST_TIME = "isFirstRun" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think we need this second commit