Commit 928e7aa5 authored by zhaopengxiang's avatar zhaopengxiang

存储数据优化

parent 0bb3cb46
......@@ -18,6 +18,7 @@ import com.miya.fastcashier.utils.ContextUtils
import com.miya.fastcashier.utils.DateUtils
import com.miya.fastcashier.utils.DensityUtils
import com.miya.fastcashier.utils.LogFileUtils
import com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import com.miya.fastcashier.utils.manage.OrderRecordManageKit
import com.miya.print.PrinterManager
import com.sdy.miya.moblie.component.pay.core.net.MiYaPayMobileApiClient
......@@ -144,7 +145,7 @@ class BaseApplication : MultiDexApplication() {
}
fun resetConfig() {
MMKV.defaultMMKV().clearAll()
LocalKeyDataMKManageKit.clearCommonData()
//清除本地订单昨天的流水信息
OrderRecordManageKit.clearOrderDataYeaterday()
//清除本地个人信息
......
......@@ -33,9 +33,14 @@ object AccountService {
this.accountPassword = accountPassword
}
fun clear(){
fun clear() {
selfCashierAccountInfo = null
userName = ""
accountPassword = ""
}
fun init(selfCashierAccountInfo: SelfCashierAccountInfo?, userName: String) {
this.selfCashierAccountInfo = selfCashierAccountInfo
this.userName = userName
}
}
\ No newline at end of file
......@@ -21,7 +21,6 @@ import com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import com.miya.fastcashier.viewmodel.LoginViewModel
import com.permissionx.guolindev.PermissionX
import com.permissionx.guolindev.callback.RequestCallback
import com.tencent.mmkv.MMKV
class LoginActivity : AppCompatActivity() {
......@@ -29,7 +28,7 @@ class LoginActivity : AppCompatActivity() {
private lateinit var loginViewModel: LoginViewModel
private lateinit var binding: ActivityLoginBinding
companion object{
companion object {
fun start(context: Context, flags: Int) {
val intent = Intent(context, LoginActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or flags
......@@ -48,8 +47,6 @@ class LoginActivity : AppCompatActivity() {
val login = binding.login
val tvErrInfo = binding.tvErrInfo
val kv = MMKV.defaultMMKV()
loginViewModel = ViewModelProvider(this)
.get(LoginViewModel::class.java)
......@@ -66,18 +63,15 @@ class LoginActivity : AppCompatActivity() {
result.getOrNull().also {
it?.let { it1 ->
kv.encode("username", username.text.toString())
kv.encode("password", password.text.toString())
val userName = username.text.toString()
val passWord = password.text.toString()
AccountService.setUserName(username.text.toString())
AccountService.setAccountInfo(it1)
LocalKeyDataMKManageKit.putLoginIngfo(userName, passWord)
AccountService.init(it1, userName)
//根据本地存储时间,MMKV初始化合理的结算时间
LocalKeyDataMKManageKit.handleCompliantBalanceDate()
val intent = Intent()
intent.setClass(this@LoginActivity, MainActivity::class.java)
startActivity(intent)
MainActivity.start(this@LoginActivity)
finish()
}
}
......@@ -140,18 +134,19 @@ class LoginActivity : AppCompatActivity() {
}
}
kv.decodeString("username")?.let {
LocalKeyDataMKManageKit.getLoginUserName()?.let {
username.setText(it)
}
kv.decodeString("password")?.let {
LocalKeyDataMKManageKit.getLoginUserPassword()?.let {
password.setText(it)
}
if (!TextUtils.isEmpty(username.text)
&& !TextUtils.isEmpty(password.text)
) {
if (!TextUtils.isEmpty(username.text) && !TextUtils.isEmpty(password.text)) {
loading.visibility = View.VISIBLE;
loginViewModel.login(username.text.toString(), password.text.toString())
loginViewModel.login(
username.text.toString(),
password.text.toString()
)
}
}
......
package com.miya.fastcashier.ui
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
......@@ -26,6 +27,15 @@ class MainActivity : BaseActivity() {
private lateinit var viewModel: MainViewModel
private var dateSelectHelper: DateSelectHelper? = null
companion object {
@JvmStatic
fun start(context: Context) {
val intent = Intent()
intent.setClass(context, MainActivity::class.java)
context.startActivity(intent)
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
......
......@@ -18,6 +18,7 @@ class LocalKeyDataMKManageKit {
companion object {
/***************************************** 分账户的关键数据,分区存储ID为MMKV_ID *****************************************/
private val MMKV_ID = "fastcashier_key_data"
private val BALANCEDATE_ID = "balanceDate"
......@@ -53,16 +54,16 @@ class LocalKeyDataMKManageKit {
}
var minimumTime: Long = System.currentTimeMillis() - 3 * 24 * 3600 * 1000
if (balanceTime <= minimumTime){
if (balanceTime <= minimumTime) {
putBalanceDate(minimumTime)
LogUtils.e(BALANCEDATE_ID, "minimumTime:${DateUtils.format18(Date(minimumTime))}")
}
}
/**
* 清除关键数据
* 清除关键数据的mmkv存储
*/
fun clear() {
fun clearKeyData() {
getKeyDataMK().clearAll()
}
......@@ -70,5 +71,36 @@ class LocalKeyDataMKManageKit {
val MMKV_ID_WITH_USER = MMKV_ID.plus("_${AccountService.getUserName()}")
return MMKV.mmkvWithID(MMKV_ID_WITH_USER)
}
/***************************************** 普通存储的关键数据,分区存储ID为默认 *****************************************/
private val USERNAME_ID = "username"
private val USERPASSWORD_ID = "password"
/**
* 存储登录信息:姓名、密码
*/
fun putLoginIngfo(userName: String, password: String) {
MMKV.defaultMMKV().encode(USERNAME_ID, userName)
MMKV.defaultMMKV().encode(USERPASSWORD_ID, password)
}
/**
* 获取登录姓名
*/
fun getLoginUserName(): String? {
return MMKV.defaultMMKV().decodeString(USERNAME_ID)
}
/**
* 获取登录密码
*/
fun getLoginUserPassword(): String? {
return MMKV.defaultMMKV().decodeString(USERPASSWORD_ID)
}
fun clearCommonData() {
MMKV.defaultMMKV().clearAll()
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment