Skip to content

Instantly share code, notes, and snippets.

@Younes-Charfaoui
Created May 7, 2019 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Younes-Charfaoui/129e7afa42b7411308abadc10e984da2 to your computer and use it in GitHub Desktop.
Save Younes-Charfaoui/129e7afa42b7411308abadc10e984da2 to your computer and use it in GitHub Desktop.
PreferenceManager for the AppIntro
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"
}
}
@wal0x
Copy link

wal0x commented Dec 24, 2022

I don't think we need this second commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment