cloudroam
6 天以前 6403ddc78af1190995fa4f6335b57b3820fa2fc6
app/src/main/java/com/example/firstapp/utils/PreferencesManager.kt
@@ -7,6 +7,10 @@
    private const val PREF_NAME = "app_preferences"
    private const val KEY_TOKEN = "user_token"
    private const val KEY_PHONE = "user_phone"
    private const val KEY_FIRST_INSTALL = "first_install"
    private const val LAST_LOGIN_PHONE = "last_login_phone"
    private const val PREF_LAST_CHECK_TIME_PREFIX = "last_check_time_"
    private const val KEY_INVITE = "user_invite"
    private lateinit var preferences: SharedPreferences
@@ -37,4 +41,36 @@
            apply()
        }
    }
    fun isFirstInstall(): Boolean {
        return preferences.getBoolean(KEY_FIRST_INSTALL, true)
    }
    fun setFirstInstall(isFirst: Boolean) {
        preferences.edit().putBoolean(KEY_FIRST_INSTALL, isFirst).apply()
    }
    fun saveLastLoginPhone(phone: String) {
        preferences.edit().putString(LAST_LOGIN_PHONE, phone).apply()
    }
    fun getLastLoginPhone(): String {
        return preferences.getString(LAST_LOGIN_PHONE, "") ?: ""
    }
    fun getLastCheckTime(categoryId: Int): Long {
        return preferences.getLong(PREF_LAST_CHECK_TIME_PREFIX + categoryId, 0)
    }
    fun setLastCheckTime(categoryId: Int, time: Long) {
        preferences.edit().putLong(PREF_LAST_CHECK_TIME_PREFIX + categoryId, time).apply()
    }
    fun getInviteCode(): String {
        return preferences.getString(KEY_INVITE, "") ?: ""
    }
    fun setInviteCode(invite: String) {
        preferences.edit().putString(KEY_INVITE, invite).apply()
    }