aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
blob: c98fd5a50f2313bdeb8232f4db2925cda6caa331 (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
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()
}