AppLocalImpl.kt 1.95 KB
Newer Older
ydl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
package com.yidianling.user.mine.data

import android.content.Context
import android.content.SharedPreferences
import com.ydl.ydlcommon.base.BaseApp

/**
 * author : Zhangwenchao
 * e-mail : zhangwch@yidianling.com
 * time   : 2018/04/27
 */
internal class AppLocalImpl private constructor(): AppLocal {

    companion object {
        fun getInstance(): AppLocalImpl {
            return Holder.INSTANCE
        }

范玉宾 committed
19 20 21
        private const val APP = "app"
        private const val RED_POCKET_TIME = "red_pocket_time"
        private const val UPDATE = "update"
范玉宾 committed
22

范玉宾 committed
23 24 25
        private const val CONFIDE = "confide"
        private const val CONSULT = "consult"
        private const val COUPON = "coupon"
ydl committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    }


    override fun getRedPocketTime(): Long {
        return getAppSP().getLong(RED_POCKET_TIME, 0)
    }

    override fun putRedPocketTime(time: Long) {
        getAppSP().edit().putLong(RED_POCKET_TIME, time).apply()
    }

    override fun hasUpdate(): Boolean {
        return getAppSP().getBoolean(UPDATE, false)
    }

    override fun putUpdate(update: Boolean) {
        getAppSP().edit().putBoolean(UPDATE, update).apply()
    }

范玉宾 committed
45 46 47 48 49 50 51 52 53 54 55 56 57
    override fun getCoupon(): Boolean {
        return getAppSP().getBoolean(COUPON, false)
    }

    override fun setCoupon(have: Boolean) {
        getAppSP().edit().putBoolean(COUPON, have).apply()
    }

    override fun getConsult(): Boolean {
        return getAppSP().getBoolean(CONSULT, false)
    }

    override fun setConsult(have: Boolean) {
58
        getAppSP().edit().putBoolean(CONSULT, have).apply()
范玉宾 committed
59 60 61 62 63 64 65 66 67 68
    }

    override fun getConfide(): Boolean {
        return getAppSP().getBoolean(CONFIDE, false)
    }

    override fun setConfide(have: Boolean) {
        getAppSP().edit().putBoolean(CONFIDE, have).apply()
    }

ydl committed
69 70 71 72 73 74 75 76 77 78 79
    private fun getAppSP(): SharedPreferences {
        return BaseApp.getApp().getSharedPreferences(APP, Context.MODE_PRIVATE)
    }



    private object Holder {
        internal val INSTANCE = AppLocalImpl()
    }

}