refactor(user): 重构司机信息存储逻辑

- 将司机信息从 MMKV 迁移到 Room 数据库
- 新增 DriverInfoBean 实体类和 DriverInfoDao接口
- 更新 GlobalData 中的 driverInfo 相关逻辑- 修改相关 Activity 和 ViewModel 中的代码,使用新的数据库存储方式- 优化了司机信息的获取和更新流程
This commit is contained in:
songzhiling
2025-04-16 15:58:07 +08:00
parent d2f2752499
commit 0f24648cb1
53 changed files with 1259 additions and 1272 deletions

View File

@ -4,10 +4,9 @@ import android.app.Application
import com.amap.api.location.AMapLocation
import com.blankj.utilcode.util.AppUtils
import com.tencent.mmkv.MMKV
import com.za.bean.DriverInfo
import com.za.bean.VehicleInfo
import com.za.bean.db.order.OrderInfo
import com.za.room.RoomHelper
import com.za.room.db.user.DriverInfoBean
object GlobalData {
lateinit var application : Application
@ -16,20 +15,19 @@ object GlobalData {
var token : String? = null
get() {
return MMKV.defaultMMKV().decodeString("TOKEN", null)
return MMKV.defaultMMKV().decodeString("ZD_TOKEN", null)
}
set(value) {
MMKV.defaultMMKV().encode("TOKEN", value)
MMKV.defaultMMKV().encode("ZD_TOKEN", value)
field = value
}
//记录上次登录的手机号
var lastLoginPhone : String? = null
var regid : String? = null
get() {
return MMKV.defaultMMKV().decodeString("lastLoginPhone", null)
return MMKV.defaultMMKV().decodeString("regid", null)
}
set(value) {
MMKV.defaultMMKV().encode("lastLoginPhone", value)
MMKV.defaultMMKV().encode("regid", value)
field = value
}
@ -42,25 +40,19 @@ object GlobalData {
field = value
}
var driverInfo : DriverInfo? = null
//新订单是否已经被处理
var isHandlerNewOrder : Boolean? = false
var driverInfoBean : DriverInfoBean? = null
get() {
return MMKV.defaultMMKV().decodeParcelable("driverInfo", DriverInfo::class.java)
val driverInfoBean = RoomHelper.db?.driverInfoDao()?.getDriverInfoFromUserId()
field = driverInfoBean
return driverInfoBean
}
set(value) {
MMKV.defaultMMKV().encode("driverInfo", value)
field = value
RoomHelper.db?.driverInfoDao()?.updateDriverInfo(value)
}
var vehicleInfo : VehicleInfo? = null
get() {
return MMKV.defaultMMKV().decodeParcelable("vehicleInfo", VehicleInfo::class.java)
}
set(value) {
MMKV.defaultMMKV().encode("vehicleInfo", value)
field = value
}
var currentOrder : OrderInfo? = null
get() {
return MMKV.defaultMMKV().decodeParcelable("currentOrder", OrderInfo::class.java)
@ -77,11 +69,10 @@ object GlobalData {
var currentLocation : AMapLocation? = null
get() {
return MMKV.defaultMMKV().decodeParcelable("currentLocation", AMapLocation::class.java)
return field
}
set(value) {
value?.time = System.currentTimeMillis()
MMKV.defaultMMKV().encode("currentLocation", value)
field = value
}
@ -97,8 +88,6 @@ object GlobalData {
fun clearUserCache() {
token = null
aesKey = null
driverInfo = null
vehicleInfo = null
currentLocation = null
loginTime = null
}