账号生成
This commit is contained in:
parent
6a849aa343
commit
d3fab79e75
|
|
@ -1,6 +1,7 @@
|
||||||
package com.gamedog.vididin
|
package com.gamedog.vididin
|
||||||
|
|
||||||
import com.ama.core.architecture.BaseApp
|
import com.ama.core.architecture.BaseApp
|
||||||
|
import com.gamedog.vididin.core.login.login.AccountManager
|
||||||
import com.gamedog.vididin.manager.TaskManager
|
import com.gamedog.vididin.manager.TaskManager
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
|
|
||||||
|
|
@ -18,6 +19,7 @@ class VidiDinApp : BaseApp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initManagers() {
|
private fun initManagers() {
|
||||||
|
AccountManager.getAccount()
|
||||||
TaskManager.instance()
|
TaskManager.instance()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.gamedog.vididin.core.login.login
|
||||||
|
|
||||||
|
import com.ama.core.architecture.util.DateUtil
|
||||||
|
import com.ama.core.architecture.util.DeviceUtil
|
||||||
|
import com.ama.core.architecture.util.SpUtil
|
||||||
|
import com.gamedog.vididin.beans.Account
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
object AccountManager {
|
||||||
|
|
||||||
|
private val mAccount: Account? by lazy {
|
||||||
|
var account = SpUtil.instance().getObject<Account>(SpUtil.KEY_ACCOUNT)
|
||||||
|
if (account == null) {
|
||||||
|
val deviceUUId = DeviceUtil.generateDeviceId()
|
||||||
|
account = Account(accountId = "user_$deviceUUId", deviceUUId=deviceUUId, createdAt = DateUtil.getCurTimeMs())
|
||||||
|
account.let {
|
||||||
|
SpUtil.instance().putObject(SpUtil.KEY_ACCOUNT, account)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
account
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAccount() : Account? {
|
||||||
|
return mAccount
|
||||||
|
}
|
||||||
|
|
||||||
|
/*fun initAccount() : Account {
|
||||||
|
AsyncUtil.doGlobalAsync({
|
||||||
|
SpUtil.instance().getObject<Account>(SpUtil.KEY_ACCOUNT)
|
||||||
|
}, onComplete = { item->
|
||||||
|
mAccount = item
|
||||||
|
if (mAccount == null) {
|
||||||
|
val deviceUUId = DeviceUtil.generateDeviceId()
|
||||||
|
mAccount = Account(accountId = "user_$deviceUUId", deviceUUId=deviceUUId, createdAt = DateUtil.getCurTimeMs())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
package com.gamedog.vididin.login
|
|
||||||
|
|
||||||
import com.gamedog.vididin.beans.Account
|
|
||||||
|
|
||||||
class LoginInfoSave {
|
|
||||||
|
|
||||||
fun putUser(user: Account?) {
|
|
||||||
UserLocalRepository.saveUser2Sp(user)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getUser() = UserLocalRepository.getUserFromSp()
|
|
||||||
|
|
||||||
|
|
||||||
fun putToken(token: String?) {
|
|
||||||
UserLocalRepository.saveUserToken(token)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getToken(): String? {
|
|
||||||
return UserLocalRepository.getUserToken()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,116 +0,0 @@
|
||||||
package com.gamedog.vididin.core.login.login
|
|
||||||
|
|
||||||
import com.ama.core.architecture.util.AsyncUtil
|
|
||||||
import com.ama.core.architecture.util.DateUtil
|
|
||||||
import com.ama.core.architecture.util.DeviceUtil
|
|
||||||
import com.ama.core.architecture.util.SpUtil
|
|
||||||
import com.gamedog.vididin.beans.OnLoginStateEvent
|
|
||||||
import com.gamedog.vididin.beans.Account
|
|
||||||
import com.gamedog.vididin.login.LoginInfoSave
|
|
||||||
import com.gamedog.vididin.login.OnLoginEvent
|
|
||||||
import com.gamedog.vididin.router.Router
|
|
||||||
import com.pengxr.modular.eventbus.generated.events.EventDefineOfUserEvents
|
|
||||||
|
|
||||||
|
|
||||||
object LoginManager {
|
|
||||||
|
|
||||||
private var mAccount: Account? = null
|
|
||||||
|
|
||||||
fun initAccount() {
|
|
||||||
AsyncUtil.doGlobalAsync({
|
|
||||||
SpUtil.instance().getObject<Account>(SpUtil.KEY_ACCOUNT)
|
|
||||||
}, onComplete = { item->
|
|
||||||
mAccount = item
|
|
||||||
if (mAccount == null) {
|
|
||||||
val deviceUUId = DeviceUtil.generateDeviceId()
|
|
||||||
mAccount = Account(accountId = "user_$deviceUUId", deviceUUId=deviceUUId, createdAt = DateUtil.getCurTimeMs())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/*val loginEntryPoint = EntryPointAccessors.fromApplication(BaseApp.appContext(), LoginEntryPoint::class.java)
|
|
||||||
|
|
||||||
preferencesDataSource = loginEntryPoint.appPreferencesDataSource()
|
|
||||||
applicationScope = loginEntryPoint.applicationScope()
|
|
||||||
|
|
||||||
isLoggedFlow = preferencesDataSource.userData.map { it.user }.distinctUntilChanged()
|
|
||||||
.map { it.id != 0 && it.token.isNotEmpty() }
|
|
||||||
// 启动监听
|
|
||||||
applicationScope.launch {
|
|
||||||
isLoggedFlow.collect {
|
|
||||||
isCurrentLogged = it
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun getAccount() : Account? {
|
|
||||||
return mAccount
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// old ---------------------------------
|
|
||||||
|
|
||||||
private val loginInfoSave by lazy {
|
|
||||||
LoginInfoSave()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var user: Account? = null
|
|
||||||
set(value) {
|
|
||||||
loginInfoSave.putUser(value)
|
|
||||||
field = value
|
|
||||||
}
|
|
||||||
|
|
||||||
var token: String? = null
|
|
||||||
set(value) {
|
|
||||||
loginInfoSave.putToken(value)
|
|
||||||
field = value
|
|
||||||
}
|
|
||||||
|
|
||||||
val isLogin: Boolean
|
|
||||||
get() = user != null
|
|
||||||
|
|
||||||
|
|
||||||
fun init() {
|
|
||||||
user = loginInfoSave.getUser()
|
|
||||||
token = loginInfoSave.getToken()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun logout() {
|
|
||||||
user = null
|
|
||||||
token = null
|
|
||||||
EventDefineOfUserEvents.onLoginStatusChanged().post(OnLoginStateEvent(OnLoginEvent.LOGOUT))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun checkLogin(callback: (() -> Unit)? = null) {
|
|
||||||
if (isLogin) {
|
|
||||||
callback?.invoke()
|
|
||||||
} else {
|
|
||||||
Router.Mine.createMineFragment()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun putUser(user: Account?) {
|
|
||||||
this.user = user
|
|
||||||
}
|
|
||||||
|
|
||||||
fun putToken(token: String?) {
|
|
||||||
this.token = token
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
package com.gamedog.vididin.login
|
|
||||||
|
|
||||||
import com.ama.core.architecture.util.SpUtil
|
|
||||||
import com.gamedog.vididin.beans.Account
|
|
||||||
|
|
||||||
object UserLocalRepository {
|
|
||||||
|
|
||||||
fun getUserFromSp(): Account? {
|
|
||||||
return SpUtil.instance().getObject(SpUtil.KEY_ACCOUNT)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun saveUser2Sp(account: Account?) {
|
|
||||||
SpUtil.instance().putObject(SpUtil.KEY_ACCOUNT, account)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getUserToken(): String? {
|
|
||||||
return SpUtil.instance().getObject(SpUtil.KEY_ACCOUNT_TOKEN)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun saveUserToken(token: String?) {
|
|
||||||
SpUtil.instance().putString(SpUtil.KEY_ACCOUNT_TOKEN, token)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -6,158 +6,164 @@ import java.util.*
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
object DateUtil {
|
class DateUtil private constructor() {
|
||||||
private const val FORMAT_DATE = "yyyy-MM-dd"
|
|
||||||
private const val FORMAT_DATETIME = "yyyy-MM-dd HH:mm:ss"
|
companion object {
|
||||||
|
|
||||||
|
|
||||||
|
private const val FORMAT_DATE = "yyyy-MM-dd"
|
||||||
|
private const val FORMAT_DATETIME = "yyyy-MM-dd HH:mm:ss"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun getCurrentDateTime(format: String = FORMAT_DATETIME): String {
|
fun getCurrentDateTime(format: String = FORMAT_DATETIME): String {
|
||||||
return SimpleDateFormat(format, Locale.getDefault()).format(Date())
|
return SimpleDateFormat(format, Locale.getDefault()).format(Date())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun timestampToDate(timestamp: Long, format: String = FORMAT_DATE): String {
|
fun timestampToDate(timestamp: Long, format: String = FORMAT_DATE): String {
|
||||||
return SimpleDateFormat(format, Locale.getDefault()).format(Date(timestamp))
|
return SimpleDateFormat(format, Locale.getDefault()).format(Date(timestamp))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun stringToDate(dateString: String, format: String = FORMAT_DATE): Date? {
|
fun stringToDate(dateString: String, format: String = FORMAT_DATE): Date? {
|
||||||
return try {
|
return try {
|
||||||
SimpleDateFormat(format, Locale.getDefault()).parse(dateString)
|
SimpleDateFormat(format, Locale.getDefault()).parse(dateString)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
null
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun convertDateFormat(dateString: String, fromFormat: String, toFormat: String): String {
|
||||||
|
return try {
|
||||||
|
val date = SimpleDateFormat(fromFormat, Locale.getDefault()).parse(dateString)
|
||||||
|
SimpleDateFormat(toFormat, Locale.getDefault()).format(date)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
dateString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给定时间是否超过指定周期
|
||||||
|
*/
|
||||||
|
fun isPeriodExpired(targetTime: Any, period: Long, timeUnit: TimeUnit): Boolean {
|
||||||
|
val targetTimestamp = when (targetTime) {
|
||||||
|
is Long -> targetTime
|
||||||
|
is Date -> targetTime.time
|
||||||
|
is String -> stringToTimestamp(targetTime) ?: 0L
|
||||||
|
else -> 0L
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetTimestamp == 0L) return false
|
||||||
|
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
val periodMillis = timeUnit.toMillis(period)
|
||||||
|
|
||||||
|
return currentTime - targetTimestamp > periodMillis
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从起始时间到现在已经过去多少天
|
||||||
|
*/
|
||||||
|
fun getDaysPassed(startTime: Any): Long {
|
||||||
|
val startTimestamp = when (startTime) {
|
||||||
|
is Long -> startTime
|
||||||
|
is Date -> startTime.time
|
||||||
|
is String -> stringToTimestamp(startTime) ?: 0L
|
||||||
|
else -> 0L
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startTimestamp == 0L) return 0L
|
||||||
|
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
val diffMillis = currentTime - startTimestamp
|
||||||
|
|
||||||
|
return TimeUnit.MILLISECONDS.toDays(diffMillis)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getCurTimeMs(): Long {
|
||||||
|
return System.currentTimeMillis()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 两个时间点之间的天数差
|
||||||
|
*/
|
||||||
|
fun getDaysBetween(startTime: Any, endTime: Any): Long {
|
||||||
|
val startTimestamp = convertToTimestamp(startTime)
|
||||||
|
val endTimestamp = convertToTimestamp(endTime)
|
||||||
|
|
||||||
|
if (startTimestamp == 0L || endTimestamp == 0L) return 0L
|
||||||
|
|
||||||
|
val diffMillis = endTimestamp - startTimestamp
|
||||||
|
return TimeUnit.MILLISECONDS.toDays(diffMillis)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断今天是否是特定日期
|
||||||
|
*/
|
||||||
|
fun isToday(targetTime: Any): Boolean {
|
||||||
|
val targetDate = when (targetTime) {
|
||||||
|
is Long -> Date(targetTime)
|
||||||
|
is Date -> targetTime
|
||||||
|
is String -> stringToDate(targetTime)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
return targetDate?.let { isSameDay(it, Date()) } ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 两个日期是否是同一天
|
||||||
|
*/
|
||||||
|
fun isSameDay(date1: Date, date2: Date): Boolean {
|
||||||
|
val cal1 = Calendar.getInstance().apply { time = date1 }
|
||||||
|
val cal2 = Calendar.getInstance().apply { time = date2 }
|
||||||
|
|
||||||
|
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
|
||||||
|
cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) &&
|
||||||
|
cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在指定日期上添加天数
|
||||||
|
*/
|
||||||
|
fun addDays(date: Date, days: Int): Date {
|
||||||
|
val cal = Calendar.getInstance().apply { time = date }
|
||||||
|
cal.add(Calendar.DAY_OF_MONTH, days)
|
||||||
|
return cal.time
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getFirstDayOfMonth(date: Date = Date()): Date {
|
||||||
|
val cal = Calendar.getInstance().apply { time = date }
|
||||||
|
cal.set(Calendar.DAY_OF_MONTH, 1)
|
||||||
|
return cal.time
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getLastDayOfMonth(date: Date = Date()): Date {
|
||||||
|
val cal = Calendar.getInstance().apply { time = date }
|
||||||
|
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH))
|
||||||
|
return cal.time
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 私有工具方法
|
||||||
|
private fun stringToTimestamp(dateString: String, format: String = FORMAT_DATE): Long? {
|
||||||
|
return stringToDate(dateString, format)?.time
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun convertToTimestamp(time: Any): Long {
|
||||||
|
return when (time) {
|
||||||
|
is Long -> time
|
||||||
|
is Date -> time.time
|
||||||
|
is String -> stringToTimestamp(time) ?: 0L
|
||||||
|
else -> 0L
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
fun convertDateFormat(dateString: String, fromFormat: String, toFormat: String): String {
|
|
||||||
return try {
|
|
||||||
val date = SimpleDateFormat(fromFormat, Locale.getDefault()).parse(dateString)
|
|
||||||
SimpleDateFormat(toFormat, Locale.getDefault()).format(date)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
dateString
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 给定时间是否超过指定周期
|
|
||||||
*/
|
|
||||||
fun isPeriodExpired(targetTime: Any, period: Long, timeUnit: TimeUnit): Boolean {
|
|
||||||
val targetTimestamp = when (targetTime) {
|
|
||||||
is Long -> targetTime
|
|
||||||
is Date -> targetTime.time
|
|
||||||
is String -> stringToTimestamp(targetTime) ?: 0L
|
|
||||||
else -> 0L
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetTimestamp == 0L) return false
|
|
||||||
|
|
||||||
val currentTime = System.currentTimeMillis()
|
|
||||||
val periodMillis = timeUnit.toMillis(period)
|
|
||||||
|
|
||||||
return currentTime - targetTimestamp > periodMillis
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从起始时间到现在已经过去多少天
|
|
||||||
*/
|
|
||||||
fun getDaysPassed(startTime: Any): Long {
|
|
||||||
val startTimestamp = when (startTime) {
|
|
||||||
is Long -> startTime
|
|
||||||
is Date -> startTime.time
|
|
||||||
is String -> stringToTimestamp(startTime) ?: 0L
|
|
||||||
else -> 0L
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startTimestamp == 0L) return 0L
|
|
||||||
|
|
||||||
val currentTime = System.currentTimeMillis()
|
|
||||||
val diffMillis = currentTime - startTimestamp
|
|
||||||
|
|
||||||
return TimeUnit.MILLISECONDS.toDays(diffMillis)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getCurTimeMs(): Long {
|
|
||||||
return System.currentTimeMillis()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 两个时间点之间的天数差
|
|
||||||
*/
|
|
||||||
fun getDaysBetween(startTime: Any, endTime: Any): Long {
|
|
||||||
val startTimestamp = convertToTimestamp(startTime)
|
|
||||||
val endTimestamp = convertToTimestamp(endTime)
|
|
||||||
|
|
||||||
if (startTimestamp == 0L || endTimestamp == 0L) return 0L
|
|
||||||
|
|
||||||
val diffMillis = endTimestamp - startTimestamp
|
|
||||||
return TimeUnit.MILLISECONDS.toDays(diffMillis)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断今天是否是特定日期
|
|
||||||
*/
|
|
||||||
fun isToday(targetTime: Any): Boolean {
|
|
||||||
val targetDate = when (targetTime) {
|
|
||||||
is Long -> Date(targetTime)
|
|
||||||
is Date -> targetTime
|
|
||||||
is String -> stringToDate(targetTime)
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
return targetDate?.let { isSameDay(it, Date()) } ?: false
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 两个日期是否是同一天
|
|
||||||
*/
|
|
||||||
fun isSameDay(date1: Date, date2: Date): Boolean {
|
|
||||||
val cal1 = Calendar.getInstance().apply { time = date1 }
|
|
||||||
val cal2 = Calendar.getInstance().apply { time = date2 }
|
|
||||||
|
|
||||||
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
|
|
||||||
cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) &&
|
|
||||||
cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在指定日期上添加天数
|
|
||||||
*/
|
|
||||||
fun addDays(date: Date, days: Int): Date {
|
|
||||||
val cal = Calendar.getInstance().apply { time = date }
|
|
||||||
cal.add(Calendar.DAY_OF_MONTH, days)
|
|
||||||
return cal.time
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getFirstDayOfMonth(date: Date = Date()): Date {
|
|
||||||
val cal = Calendar.getInstance().apply { time = date }
|
|
||||||
cal.set(Calendar.DAY_OF_MONTH, 1)
|
|
||||||
return cal.time
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getLastDayOfMonth(date: Date = Date()): Date {
|
|
||||||
val cal = Calendar.getInstance().apply { time = date }
|
|
||||||
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH))
|
|
||||||
return cal.time
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 私有工具方法
|
|
||||||
private fun stringToTimestamp(dateString: String, format: String = FORMAT_DATE): Long? {
|
|
||||||
return stringToDate(dateString, format)?.time
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun convertToTimestamp(time: Any): Long {
|
|
||||||
return when (time) {
|
|
||||||
is Long -> time
|
|
||||||
is Date -> time.time
|
|
||||||
is String -> stringToTimestamp(time) ?: 0L
|
|
||||||
else -> 0L
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,7 @@ import com.ama.core.architecture.BaseApp
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
|
import java.nio.charset.Charset
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SpUtil private constructor(spFileName: String) {
|
class SpUtil private constructor(spFileName: String) {
|
||||||
|
|
@ -110,8 +107,10 @@ class SpUtil private constructor(spFileName: String) {
|
||||||
val encryptedData = getString(key)
|
val encryptedData = getString(key)
|
||||||
if (encryptedData.isBlank()) return defaultObj
|
if (encryptedData.isBlank()) return defaultObj
|
||||||
|
|
||||||
val jsonString = String(Base64.decode(encryptedData, Base64.DEFAULT))
|
val jsonString = String(Base64.decode(encryptedData, Base64.DEFAULT), Charset.forName("UTF-8"))
|
||||||
gson.fromJson(jsonString, T::class.java) ?: defaultObj
|
|
||||||
|
val type = object : TypeToken<T>() {}.type
|
||||||
|
gson.fromJson(jsonString, type) ?: defaultObj
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
defaultObj
|
defaultObj
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue