diff options
author | Allan Wang <me@allanwang.ca> | 2017-05-29 15:05:26 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-05-29 15:05:26 -0700 |
commit | e33120d454aeb72acc2c1315bddea31dd2f15bb2 (patch) | |
tree | 6754e8c5c9e8303b0943d1716560b31a0953361a /app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt | |
parent | f83fb56dca63a06e4706e6cb404bca9c49e5dbe0 (diff) | |
download | frost-e33120d454aeb72acc2c1315bddea31dd2f15bb2.tar.gz frost-e33120d454aeb72acc2c1315bddea31dd2f15bb2.tar.bz2 frost-e33120d454aeb72acc2c1315bddea31dd2f15bb2.zip |
initial port
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt new file mode 100644 index 00000000..c98fd5a5 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -0,0 +1,30 @@ +package com.pitchedapps.frost.utils + +import com.pitchedapps.frost.FrostApp + +/** + * Created by Allan Wang on 2017-05-28. + */ +val prefs: Prefs by lazy { FrostApp.prefs } + +class Prefs(c: android.content.Context) { + private companion object { + val PREFERENCE_NAME = "${com.pitchedapps.frost.BuildConfig.APPLICATION_ID}.prefs" + val LAST_ACTIVE = "last_active" + } + + var lastActive: Long + get() = prefs.getLong(com.pitchedapps.frost.utils.Prefs.Companion.LAST_ACTIVE, -1) + set(value) = set(com.pitchedapps.frost.utils.Prefs.Companion.LAST_ACTIVE, System.currentTimeMillis()) + + init { + lastActive = 0 + } + + private val prefs: android.content.SharedPreferences by lazy { c.getSharedPreferences(com.pitchedapps.frost.utils.Prefs.Companion.PREFERENCE_NAME, android.content.Context.MODE_PRIVATE) } + + private fun set(key: String, value: Boolean) = prefs.edit().putBoolean(key, value).apply() + private fun set(key: String, value: Int) = prefs.edit().putInt(key, value).apply() + private fun set(key: String, value: Long) = prefs.edit().putLong(key, value).apply() + private fun set(key: String, value: String) = prefs.edit().putString(key, value).apply() +}
\ No newline at end of file |