|
|
@@ -1,12 +1,19 @@
|
|
|
package com.grkj.iscs.util
|
|
|
|
|
|
import android.content.Context
|
|
|
+import com.google.gson.Gson
|
|
|
+import com.google.gson.reflect.TypeToken
|
|
|
+import com.grkj.iscs.model.bo.UpdateKeyReturnBO
|
|
|
import com.grkj.iscs.model.vo.card.CardInfoRespVO
|
|
|
+import com.grkj.iscs.model.vo.ticket.LockPointUpdateReqVO
|
|
|
+import com.grkj.iscs.util.log.LogUtil
|
|
|
+import java.util.Collections
|
|
|
|
|
|
object SPUtils {
|
|
|
|
|
|
private const val SP_NAME = "iscs"
|
|
|
private const val SP_CONFIG_NAME = "iscs_config"
|
|
|
+ private const val SP_DATA = "iscs_data"
|
|
|
|
|
|
private const val KEY_LOGIN_USER_CARD_ID = "card_id"
|
|
|
private const val KEY_LOGIN_USER_CARD_CODE = "card_code"
|
|
|
@@ -20,6 +27,9 @@ object SPUtils {
|
|
|
private const val KEY_DOCK_CONFIG = "dock_config"
|
|
|
private const val KEY_PORT_CONFIG = "port_config"
|
|
|
|
|
|
+ private const val KEY_DATA_UPDATE_LOCK_POINT = "update_lock_point"
|
|
|
+ private const val KEY_DATA_UPDATE_KEY_RETURN = "update_key_return"
|
|
|
+
|
|
|
fun getLoginUser(context: Context): CardInfoRespVO? {
|
|
|
val sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
|
|
|
if (sp.getString(KEY_LOGIN_USER_CARD_NFC, null) == null) {
|
|
|
@@ -102,4 +112,64 @@ object SPUtils {
|
|
|
val sp = context.getSharedPreferences(SP_CONFIG_NAME, Context.MODE_PRIVATE)
|
|
|
return sp.getString(KEY_PORT_CONFIG, null)
|
|
|
}
|
|
|
+
|
|
|
+ fun saveUpdateLockPoint(context: Context, list: MutableList<LockPointUpdateReqVO>) {
|
|
|
+ val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
|
|
|
+ val edit = sp.edit()
|
|
|
+ val tempList = getUpdateLockPoint(context)
|
|
|
+ tempList.addAll(list)
|
|
|
+ edit.putString(KEY_DATA_UPDATE_LOCK_POINT, Gson().toJson(tempList))
|
|
|
+ edit.apply()
|
|
|
+ }
|
|
|
+
|
|
|
+ fun getUpdateLockPoint(context: Context): MutableList<LockPointUpdateReqVO> {
|
|
|
+ val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
|
|
|
+ val listJson = sp.getString(KEY_DATA_UPDATE_LOCK_POINT, null)
|
|
|
+ try {
|
|
|
+ val tempList: MutableList<LockPointUpdateReqVO> = Gson().fromJson(
|
|
|
+ listJson,
|
|
|
+ object : TypeToken<MutableList<LockPointUpdateReqVO>>() {}.type
|
|
|
+ )
|
|
|
+ return tempList
|
|
|
+ } catch (e: Exception) {
|
|
|
+ LogUtil.e("${e.message}")
|
|
|
+ return Collections.emptyList()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun clearUpdateLockPoint(context: Context) {
|
|
|
+ val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
|
|
|
+ val edit = sp.edit()
|
|
|
+ edit.putString(KEY_DATA_UPDATE_LOCK_POINT, null)
|
|
|
+ edit.apply()
|
|
|
+ }
|
|
|
+
|
|
|
+ fun saveUpdateKeyReturn(context: Context, returnBO: UpdateKeyReturnBO) {
|
|
|
+ val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
|
|
|
+ val edit = sp.edit()
|
|
|
+ val tempList = getUpdateKeyReturn(context)
|
|
|
+ tempList.add(returnBO)
|
|
|
+ edit.putString(KEY_DATA_UPDATE_KEY_RETURN, Gson().toJson(tempList))
|
|
|
+ edit.apply()
|
|
|
+ }
|
|
|
+
|
|
|
+ fun getUpdateKeyReturn(context: Context): MutableList<UpdateKeyReturnBO> {
|
|
|
+ val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
|
|
|
+ val listJson = sp.getString(KEY_DATA_UPDATE_KEY_RETURN, null)
|
|
|
+ try {
|
|
|
+ val tempList: MutableList<UpdateKeyReturnBO> =
|
|
|
+ Gson().fromJson(listJson, object : TypeToken<UpdateKeyReturnBO>() {}.type)
|
|
|
+ return tempList
|
|
|
+ } catch (e: Exception) {
|
|
|
+ LogUtil.e("${e.message}")
|
|
|
+ return Collections.emptyList()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun clearUpdateKeyReturn(context: Context) {
|
|
|
+ val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
|
|
|
+ val edit = sp.edit()
|
|
|
+ edit.putString(KEY_DATA_UPDATE_KEY_RETURN, null)
|
|
|
+ edit.apply()
|
|
|
+ }
|
|
|
}
|