Skip to content

Instantly share code, notes, and snippets.

@shaon2016
Created December 10, 2019 12:18
Show Gist options
  • Save shaon2016/b3b29c9226eb53f1e702dfbde45ec788 to your computer and use it in GitHub Desktop.
Save shaon2016/b3b29c9226eb53f1e702dfbde45ec788 to your computer and use it in GitHub Desktop.
object P {
private val TAG = P::class.java.simpleName
private var prefs: SharedPreferences? = null
private var prefsEditor: SharedPreferences.Editor? = null
@SuppressLint("CommitPrefEdits")
private fun assurePrefNotNull(context: Context) {
if (prefs == null)
prefs = PreferenceManager.getDefaultSharedPreferences(context)
if (prefsEditor == null) {
prefsEditor = PreferenceManager
.getDefaultSharedPreferences(context).edit()
prefsEditor!!.apply()
}
}
fun setShowFirstTimeShowCase(context: Context, set:Boolean) {
assurePrefNotNull(context)
prefsEditor!!.putBoolean(PREF_SHOW_FIRST_TIME_SHOW_CASE, set)
prefsEditor!!.commit()
}
fun getShowFirstTimeShowCase(ctx: Context): Boolean {
assurePrefNotNull(ctx)
return prefs!!.getBoolean(PREF_SHOW_FIRST_TIME_SHOW_CASE, false)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment