mirror of
https://github.com/lizongying/my-tv.git
synced 2026-11-26 13:26:29 +08:00
创建 SP 工具类,管理所有(除 ChannelUtils 以外)用户偏好设置
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package com.lizongying.mytv.api
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.lizongying.mytv.Encryptor
|
||||
import com.lizongying.mytv.MainActivity
|
||||
import com.lizongying.mytv.SP
|
||||
import com.lizongying.mytv.Utils.getDateTimestamp
|
||||
import com.lizongying.mytv.models.TVViewModel
|
||||
import kotlin.math.floor
|
||||
@@ -51,14 +51,11 @@ class YSP(var context: Context) {
|
||||
private var signature = ""
|
||||
|
||||
private var encryptor: Encryptor? = null
|
||||
private lateinit var sharedPref: SharedPreferences
|
||||
|
||||
init {
|
||||
if (context is MainActivity) {
|
||||
encryptor = Encryptor()
|
||||
encryptor!!.init(context)
|
||||
|
||||
sharedPref = (context as MainActivity).sharedPref
|
||||
}
|
||||
|
||||
guid = getGuid()
|
||||
@@ -94,23 +91,17 @@ class YSP(var context: Context) {
|
||||
}
|
||||
|
||||
fun getGuid(): String {
|
||||
var guid = sharedPref.getString("guid", "")
|
||||
if (guid == null || guid.length < 18) {
|
||||
var guid = SP.guid
|
||||
if (guid.length < 18) {
|
||||
guid = generateGuid()
|
||||
with(sharedPref.edit()) {
|
||||
putString("guid", guid)
|
||||
apply()
|
||||
}
|
||||
SP.guid = guid
|
||||
}
|
||||
return guid
|
||||
}
|
||||
|
||||
private fun newGuid(): String {
|
||||
guid = generateGuid()
|
||||
with(sharedPref.edit()) {
|
||||
putString("guid", guid)
|
||||
apply()
|
||||
}
|
||||
SP.guid = guid
|
||||
return guid
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user