blob: ad222145be1c03246c2acbfb362d72eade86f036 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package com.pitchedapps.frost.utils
import android.content.Context
import android.content.SharedPreferences
/**
* Created by Allan Wang on 2017-05-28.
*/
private val PREFERENCE_NAME = "${com.pitchedapps.frost.BuildConfig.APPLICATION_ID}.prefs"
private val LAST_ACTIVE = "last_active"
object Prefs {
val prefs: Prefs by lazy { this }
lateinit private var c: Context
operator fun invoke(c: Context) {
this.c = c
}
private val sp: SharedPreferences by lazy { c.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE) }
var lastActive: Long
get() = sp.getLong(LAST_ACTIVE, -1)
set(value) = set(LAST_ACTIVE, System.currentTimeMillis())
init {
lastActive = 0
}
private fun set(key: String, value: Boolean) = sp.edit().putBoolean(key, value).apply()
private fun set(key: String, value: Int) = sp.edit().putInt(key, value).apply()
private fun set(key: String, value: Long) = sp.edit().putLong(key, value).apply()
private fun set(key: String, value: String) = sp.edit().putString(key, value).apply()
}
|