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,7 +4,7 @@
<uses-sdk tools:overrideLibrary="androidx.camera.view,androidx.camera:camera-camera2,androidx.camera.camera2,androidx.camera.lifecycle,androidx.camera.core" /> <uses-sdk tools:overrideLibrary="androidx.camera.view,androidx.camera:camera-camera2,androidx.camera.camera2,androidx.camera.lifecycle,androidx.camera.core" />
<permission <permission
android:name="${applicationId}.permission.JPUSH_MESSAGE" android:name="com.za.rescue.dealer.permission.JPUSH_MESSAGE"
android:protectionLevel="signature" /> <!-- 位置相关权限 --> android:protectionLevel="signature" /> <!-- 位置相关权限 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
@ -243,7 +243,10 @@
<category android:name="${applicationId}" /> <category android:name="${applicationId}" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<service
android:name="cn.jpush.android.service.DaemonService"
android:enabled="true"
android:exported="true" />
</application> </application>
</manifest> </manifest>

View File

@ -78,9 +78,9 @@ object AppConfig {
*/ */
fun getTrainUrl(keyWord: String = ""): String { fun getTrainUrl(keyWord: String = ""): String {
if (keyWord.isEmpty()) { if (keyWord.isEmpty()) {
return TRAIN_URL + "?token=${GlobalData.token}&driverId=${GlobalData.driverInfo?.userId}" return TRAIN_URL + "?token=${GlobalData.token}&driverId=${GlobalData.driverInfoBean?.userId}"
} }
return TRAIN_URL + "?token=${GlobalData.token}&driverId=${GlobalData.driverInfo?.userId}&keyword=$keyWord" return TRAIN_URL + "?token=${GlobalData.token}&driverId=${GlobalData.driverInfoBean?.userId}&keyword=$keyWord"
} }
/** /**
@ -91,8 +91,8 @@ object AppConfig {
*/ */
fun getDocmentUrl(keyWord: String = ""): String { fun getDocmentUrl(keyWord: String = ""): String {
if (keyWord.isEmpty()) { if (keyWord.isEmpty()) {
return DOCMENT_URL + "?token=${GlobalData.token}&driverId=${GlobalData.driverInfo?.userId}" return DOCMENT_URL + "?token=${GlobalData.token}&driverId=${GlobalData.driverInfoBean?.userId}"
} }
return DOCMENT_URL + "?token=${GlobalData.token}&driverId=${GlobalData.driverInfo?.userId}&keyword=$keyWord" return DOCMENT_URL + "?token=${GlobalData.token}&driverId=${GlobalData.driverInfoBean?.userId}&keyword=$keyWord"
} }
} }

View File

@ -12,64 +12,14 @@ data class DriverInfo(
var userName : String? = null, //用户姓名 var userName : String? = null, //用户姓名
var userPhone : String? = null, //用户手机号 var userPhone : String? = null, //用户手机号
var callphone : String? = null, var callphone : String? = null,
var supplierId : String? = null, //经销商id var supplierId : Int? = null, //经销商id
var supplierName : String? = null, //经销商名称 var supplierName : String? = null, //经销商名称
var supplierType : Int? = null, //经销商类型 1子公司 2供应商 var supplierType : Int? = null, //经销商类型 1子公司 2供应商
var loginLogId : Int? = null, var loginLogId : Int? = null,
var serviceList : List<String>? = null, //车辆服务列表 var serviceList : List<String>? = null, //车辆服务列表
var assistUserCode : String? = null, var assistUserCode : String? = null,
val authStatus : Int? = null, // 0 未认证 1 已认证 val authStatus : Int? = null, // 0 未认证 1 已认证
) : Parcelable { )
constructor(parcel : Parcel) : this(parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.createStringArrayList(),
parcel.readString(),
parcel.readValue(Int::class.java.classLoader) as? Int) {
}
override fun writeToParcel(parcel : Parcel, flags : Int) {
parcel.writeString(userPortrait)
parcel.writeString(token)
parcel.writeString(rongyunToken)
parcel.writeString(logTime)
parcel.writeValue(userId)
parcel.writeString(userName)
parcel.writeString(userPhone)
parcel.writeString(callphone)
parcel.writeString(supplierId)
parcel.writeString(supplierName)
parcel.writeValue(supplierType)
parcel.writeValue(loginLogId)
parcel.writeStringList(serviceList)
parcel.writeString(assistUserCode)
parcel.writeValue(authStatus)
}
override fun describeContents() : Int {
return 0
}
companion object CREATOR : Parcelable.Creator<DriverInfo> {
override fun createFromParcel(parcel : Parcel) : DriverInfo {
return DriverInfo(parcel)
}
override fun newArray(size : Int) : Array<DriverInfo?> {
return arrayOfNulls(size)
}
}
}
data class GeneralInfo( data class GeneralInfo(
var userId : Int? = null, //用户id var userId : Int? = null, //用户id
@ -214,3 +164,56 @@ data class LoginWithTaskBean(val supplierName : String? = null,
val jobNumber : String? = null, val jobNumber : String? = null,
val vehicleId : Int? = null, val vehicleId : Int? = null,
val supplierType : Int? = null) val supplierType : Int? = null)
data class AppNewDriverInfoDTO(val userId : Int? = null,
val userName : String? = null,
val userPhone : String? = null,
val supplierCode : String? = null,
val appLoginCode : String? = null,
val supplierId : Int? = null,
val supplierName : String? = null,
val supplierType : Int? = null,
val authStatus : Int? = null,
val tiedVehicle : VehicleInfo? = null, //绑定的车辆,如果该服务商下面绑定的有车辆,则返回绑定车辆信息
val loginTime : String? = null) : Parcelable {
constructor(parcel : Parcel) : this(parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readString(),
parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readParcelable(VehicleInfo::class.java.classLoader),
parcel.readString()) {
}
override fun writeToParcel(parcel : Parcel, flags : Int) {
parcel.writeValue(userId)
parcel.writeString(userName)
parcel.writeString(userPhone)
parcel.writeString(supplierCode)
parcel.writeString(appLoginCode)
parcel.writeValue(supplierId)
parcel.writeString(supplierName)
parcel.writeValue(supplierType)
parcel.writeValue(authStatus)
parcel.writeParcelable(tiedVehicle, flags)
parcel.writeString(loginTime)
}
override fun describeContents() : Int {
return 0
}
companion object CREATOR : Parcelable.Creator<AppNewDriverInfoDTO> {
override fun createFromParcel(parcel : Parcel) : AppNewDriverInfoDTO {
return AppNewDriverInfoDTO(parcel)
}
override fun newArray(size : Int) : Array<AppNewDriverInfoDTO?> {
return arrayOfNulls(size)
}
}
}

View File

@ -4,53 +4,83 @@ import android.os.Parcel
import android.os.Parcelable import android.os.Parcelable
data class VehicleInfo( data class VehicleInfo(
var vehicleId: Int? = null, //车辆id var vehicleId : Int? = null, //车辆id
var vehicleName: String? = null,//车辆名称(车牌号) var vehicleName : String? = null, //车辆名称(车牌号)
var userName: String? = null, //当前用车司机姓名(工号) var userName : String? = null, //当前用车司机姓名(工号)
var userPhone: String? = null, //当前用车司机电话 var userPhone : String? = null, //当前用车司机电话
var status: Int? = null, //车辆状态 0 不在线 1 在线 var status : Int? = null, //车辆状态 0 不在线 1 在线
val plateNumber: String? = null, //车牌号 val plateNumber : String? = null, //车牌号
var vehicleState: Int? = null, //车辆是否空闲 0 空闲 1 忙碌 2置忙 8维修 var vehicleState : Int? = null, //车辆是否空闲 0 空闲 1 忙碌 2置忙 8维修
var terminalId: Long? = null, //车辆高德tid var terminalId : Long? = null, //车辆高德tid
var exitMileage: Int? = null, //上次退出公里数 var exitMileage : Int? = null, //上次退出公里数
var supplierType: Int? = null, //经销商类型 var supplierType : Int? = null, //经销商类型
) : Parcelable { ) : Parcelable {
constructor(parcel : Parcel) : this(parcel.readValue(Int::class.java.classLoader) as? Int, constructor(parcel : Parcel) : this(parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readString(), parcel.readString(),
parcel.readString(), parcel.readString(),
parcel.readString(), parcel.readString(),
parcel.readValue(Int::class.java.classLoader) as? Int, parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readString(), parcel.readString(),
parcel.readValue(Int::class.java.classLoader) as? Int, parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readValue(Long::class.java.classLoader) as? Long, parcel.readValue(Long::class.java.classLoader) as? Long,
parcel.readValue(Int::class.java.classLoader) as? Int, parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readValue(Int::class.java.classLoader) as? Int) { parcel.readValue(Int::class.java.classLoader) as? Int) {
} }
override fun writeToParcel(parcel : Parcel, flags : Int) { override fun writeToParcel(parcel : Parcel, flags : Int) {
parcel.writeValue(vehicleId) parcel.writeValue(vehicleId)
parcel.writeString(vehicleName) parcel.writeString(vehicleName)
parcel.writeString(userName) parcel.writeString(userName)
parcel.writeString(userPhone) parcel.writeString(userPhone)
parcel.writeValue(status) parcel.writeValue(status)
parcel.writeString(plateNumber) parcel.writeString(plateNumber)
parcel.writeValue(vehicleState) parcel.writeValue(vehicleState)
parcel.writeValue(terminalId) parcel.writeValue(terminalId)
parcel.writeValue(exitMileage) parcel.writeValue(exitMileage)
parcel.writeValue(supplierType) parcel.writeValue(supplierType)
} }
override fun describeContents() : Int { override fun describeContents() : Int {
return 0 return 0
} }
companion object CREATOR : Parcelable.Creator<VehicleInfo> { companion object CREATOR : Parcelable.Creator<VehicleInfo> {
override fun createFromParcel(parcel : Parcel) : VehicleInfo { override fun createFromParcel(parcel : Parcel) : VehicleInfo {
return VehicleInfo(parcel) return VehicleInfo(parcel)
} }
override fun newArray(size : Int) : Array<VehicleInfo?> { override fun newArray(size : Int) : Array<VehicleInfo?> {
return arrayOfNulls(size) return arrayOfNulls(size)
} }
} }
}
data class LastLoginBean(val phone : String? = null,
val supplierId : Int? = null,
val vehicleId : Int?):Parcelable {
constructor(parcel : Parcel) : this(parcel.readString(),
parcel.readValue(Int::class.java.classLoader) as? Int,
parcel.readValue(Int::class.java.classLoader) as? Int) {
}
override fun writeToParcel(parcel : Parcel, flags : Int) {
parcel.writeString(phone)
parcel.writeValue(supplierId)
parcel.writeValue(vehicleId)
}
override fun describeContents() : Int {
return 0
}
companion object CREATOR : Parcelable.Creator<LastLoginBean> {
override fun createFromParcel(parcel : Parcel) : LastLoginBean {
return LastLoginBean(parcel)
}
override fun newArray(size : Int) : Array<LastLoginBean?> {
return arrayOfNulls(size)
}
}
} }

View File

@ -0,0 +1,3 @@
package com.za.bean.request
data class AppNewOrderVoiceRequest(var voiceWords : String? = null)

View File

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

View File

@ -3,7 +3,6 @@ package com.za.common
import android.app.Application import android.app.Application
import com.tencent.bugly.Bugly import com.tencent.bugly.Bugly
import com.tencent.mmkv.MMKV import com.tencent.mmkv.MMKV
import com.tencent.mmkv.MMKVLogLevel
import com.za.base.AppConfig import com.za.base.AppConfig
import com.za.common.log.LogUtil import com.za.common.log.LogUtil
import com.za.room.RoomHelper import com.za.room.RoomHelper
@ -11,6 +10,7 @@ import com.za.service.location.ZdLocationManager
object ZDManager { object ZDManager {
lateinit var application : Application lateinit var application : Application
fun init(application : Application, isRelease : Boolean = false) { fun init(application : Application, isRelease : Boolean = false) {
this.application = application this.application = application
thirdSdkInit(isRelease) thirdSdkInit(isRelease)
@ -22,8 +22,9 @@ object ZDManager {
} else { } else {
AppConfig.crm1() AppConfig.crm1()
} }
GlobalData.application = application GlobalData.application = application // 在 Application 中初始化 MMKV所有进程共享同一存储路径
MMKV.initialize(application, MMKVLogLevel.LevelInfo) val rootDir = application.filesDir.absolutePath + "/mmkv"
MMKV.initialize(application, rootDir)
Bugly.init(application, "6972a6b56d", true) Bugly.init(application, "6972a6b56d", true)
LogUtil.init(application) LogUtil.init(application)
RoomHelper.init(application) RoomHelper.init(application)

View File

@ -15,7 +15,6 @@ import com.blankj.utilcode.util.FileUtils
import com.blankj.utilcode.util.TimeUtils import com.blankj.utilcode.util.TimeUtils
import com.za.common.GlobalData import com.za.common.GlobalData
import com.za.common.util.AppFileManager import com.za.common.util.AppFileManager
import com.za.servicing.BuildConfig
import io.reactivex.rxjava3.schedulers.Schedulers import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -40,278 +39,272 @@ import java.util.concurrent.atomic.AtomicBoolean
import kotlin.concurrent.thread import kotlin.concurrent.thread
object LogUtil { object LogUtil {
private var context: Application? = null private var context : Application? = null
private var logDestinationPath: String? = null private var logDestinationPath : String? = null
private var orderLogDirPath: String? = null private var orderLogDirPath : String? = null
private var normalLogDirPath: String? = null private var normalLogDirPath : String? = null
private val coroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()) private val coroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
private val logBuffer = StringBuilder() private val logBuffer = StringBuilder()
private val isWriting = AtomicBoolean(false) private val isWriting = AtomicBoolean(false)
fun init(context: Application) { fun init(context : Application) {
this.context = context this.context = context
logDestinationPath = AppFileManager.getLogPath(context).also { path -> logDestinationPath = AppFileManager.getLogPath(context).also { path ->
createDirectoryIfNotExists(path) createDirectoryIfNotExists(path)
orderLogDirPath = "$path${File.separator}order_log".also { createDirectoryIfNotExists(it) } orderLogDirPath =
normalLogDirPath = "$path${File.separator}normal_log".also { createDirectoryIfNotExists(it) } "$path${File.separator}order_log".also { createDirectoryIfNotExists(it) }
} normalLogDirPath =
"$path${File.separator}normal_log".also { createDirectoryIfNotExists(it) }
}
initializeWorkManager(context) initializeWorkManager(context)
} }
private fun createDirectoryIfNotExists(path: String) { private fun createDirectoryIfNotExists(path : String) {
File(path).apply { if (!exists()) mkdir() } File(path).apply { if (! exists()) mkdir() }
} }
private fun initializeWorkManager(context: Application) { private fun initializeWorkManager(context : Application) {
if (!WorkManager.isInitialized()) { if (! WorkManager.isInitialized()) {
WorkManager.initialize(context, Configuration.Builder() WorkManager.initialize(context,
.setMinimumLoggingLevel(Log.INFO) Configuration.Builder().setMinimumLoggingLevel(Log.INFO).build())
.build()) }
}
WorkManager.getInstance(context).apply { WorkManager.getInstance(context).apply {
cancelAllWorkByTag("logWorkRequest") cancelAllWorkByTag("logWorkRequest")
enqueue(PeriodicWorkRequest.Builder(LogTask::class.java, 20, TimeUnit.MINUTES) enqueue(PeriodicWorkRequest.Builder(LogTask::class.java, 20, TimeUnit.MINUTES)
.addTag("logWorkRequest") .addTag("logWorkRequest").build())
.build()) }
} }
}
fun print(tag: String, content: String) { fun print(tag : String, content : String) {
val time = getCurrentTime() val time = getCurrentTime()
val logEntry = "$time---$tag---$content\n" val logEntry = "$time---$tag---$content\n"
Log.e("normal", "$tag---$content")
synchronized(logBuffer) {
logBuffer.append(logEntry)
}
if (BuildConfig.DEBUG) { if (logBuffer.length > 4096) {
Log.e("normal", "$tag---$content") coroutineScope.launch {
} flushBuffer()
}
}
}
synchronized(logBuffer) { fun print(tag : String, throwable : Throwable) {
logBuffer.append(logEntry) val content = StringWriter()
} val printWriter = PrintWriter(content)
throwable.printStackTrace(printWriter)
print(tag, content.toString())
}
if (logBuffer.length > 4096) { private suspend fun flushBuffer() = withContext(Dispatchers.IO) {
coroutineScope.launch { if (! isWriting.compareAndSet(false, true)) return@withContext
flushBuffer()
}
}
}
fun print(tag: String, throwable: Throwable) { val logContent : String
val content = StringWriter() synchronized(logBuffer) {
val printWriter = PrintWriter(content) if (logBuffer.isEmpty()) {
throwable.printStackTrace(printWriter) isWriting.set(false)
print(tag, content.toString()) return@withContext
} }
logContent = logBuffer.toString()
logBuffer.clear()
}
private suspend fun flushBuffer() = withContext(Dispatchers.IO) { try {
if (!isWriting.compareAndSet(false, true)) return@withContext val fileName = "normal_log.txt"
val logFile = File("$normalLogDirPath${File.separator}$fileName")
val logContent: String logFile.parentFile?.mkdirs()
synchronized(logBuffer) {
if (logBuffer.isEmpty()) {
isWriting.set(false)
return@withContext
}
logContent = logBuffer.toString()
logBuffer.clear()
}
try { if (! logFile.exists()) {
val fileName = "normal_log.txt" logFile.createNewFile()
val logFile = File("$normalLogDirPath${File.separator}$fileName") addLogHead(logFile, getCurrentTime())
}
logFile.parentFile?.mkdirs() BufferedWriter(FileWriter(logFile, true)).use { writer ->
writer.write(logContent)
writer.flush()
}
if (!logFile.exists()) { if (logFile.length() >= 8 * MemoryConstants.MB) {
logFile.createNewFile() rotateLogFile(logFile)
addLogHead(logFile, getCurrentTime()) }
} } catch (e : IOException) {
Log.e("LogUtil", "Error in flushBuffer: ${e.message}")
} catch (e : Exception) {
Log.e("LogUtil", "Error in flushBuffer: ${e.message}")
} finally {
isWriting.set(false)
}
}
BufferedWriter(FileWriter(logFile, true)).use { writer -> private fun rotateLogFile(file : File) {
writer.write(logContent) if (! file.exists()) return
writer.flush()
}
if (logFile.length() >= 8 * MemoryConstants.MB) { val newFileName = buildString {
rotateLogFile(logFile) append(AppUtils.getAppVersionCode())
} append("_")
} catch (e: IOException) { append(GlobalData.driverInfoBean?.vehicleName ?: "unknown")
Log.e("LogUtil", "Error in flushBuffer: ${e.message}") append("_")
} catch (e: Exception) { append(GlobalData.driverInfoBean?.userName ?: "unknown")
Log.e("LogUtil", "Error in flushBuffer: ${e.message}") append("_")
} finally { append(TimeUtils.getNowString())
isWriting.set(false) append(".txt")
} }
}
private fun rotateLogFile(file: File) { val newFile = File("$normalLogDirPath${File.separator}$newFileName")
if (!file.exists()) return
val newFileName = buildString { try {
append(AppUtils.getAppVersionCode()) if (file.renameTo(newFile)) {
append("_") compressAndUploadLog(newFile) // 创建新的日志文件
append(GlobalData.vehicleInfo?.vehicleName ?: "unknown") file.createNewFile()
append("_") addLogHead(file, getCurrentTime())
append(GlobalData.driverInfo?.userName ?: "unknown") } else {
append("_") print("LogUtil", "Failed to rename log file")
append(TimeUtils.getNowString()) }
append(".txt") } catch (e : Exception) {
} print("LogUtil", "Error during log rotation: ${e.message}")
}
}
val newFile = File("$normalLogDirPath${File.separator}$newFileName") private fun compressAndUploadLog(logFile : File) = coroutineScope.launch {
try {
val compressedFile = File("${logFile.absolutePath}.7z")
compress(logFile, compressedFile.absolutePath)
upload(logFile, compressedFile)
} catch (e : Exception) {
print("LogUtil", e.toString())
}
}
try { private fun deleteLog(file : File) {
if (file.renameTo(newFile)) { try {
compressAndUploadLog(newFile) FileUtils.delete(file.absolutePath)
// 创建新的日志文件 } catch (e : Exception) {
file.createNewFile() e.printStackTrace()
addLogHead(file, getCurrentTime()) }
} else { }
print("LogUtil", "Failed to rename log file")
}
} catch (e: Exception) {
print("LogUtil", "Error during log rotation: ${e.message}")
}
}
private fun compressAndUploadLog(logFile: File) = coroutineScope.launch { fun updateNormalLog() {
try { thread {
val compressedFile = File("${logFile.absolutePath}.7z") if (GlobalData.token.isNullOrBlank()) {
compress(logFile, compressedFile.absolutePath) return@thread
upload(logFile, compressedFile) }
} catch (e: Exception) { val fileName = "normal_log.txt"
print("LogUtil", e.toString()) val file = File("$normalLogDirPath${File.separator}$fileName")
} val reName =
} "${AppUtils.getAppVersionCode()}_${GlobalData.driverInfoBean?.vehicleName}_${GlobalData.driverInfoBean?.userName}_${TimeUtils.getNowString()}.txt"
val reNamePath = "$normalLogDirPath${File.separator}$reName"
file.renameTo(File(reNamePath))
normalLogDirPath?.let { it ->
File(it).listFiles()?.forEach {
if (it.length() / MemoryConstants.MB >= 10) {
deleteLog(it)
return@thread
}
if (it.exists() && ! it.name.contains("normal_log")) {
if (it.name.contains("7z")) {
upload(null, desFile = it)
} else {
val zipNamePath = it.absolutePath + ".7z"
val zipFile = File(zipNamePath)
if (! zipFile.exists()) {
try {
zipFile.createNewFile()
} catch (e : IOException) {
e.printStackTrace()
}
}
compress(it, zipNamePath)
}
}
}
}
}
}
private fun deleteLog(file: File) { private fun compress(srcFile : File, desFilePath : String) {
try { try {
FileUtils.delete(file.absolutePath) val out = XZCompressorOutputStream(FileOutputStream(desFilePath))
} catch (e: Exception) { addToArchiveCompression(out, srcFile, File(desFilePath))
e.printStackTrace() } catch (e : Exception) {
} e.printStackTrace()
} }
}
fun updateNormalLog() { private fun addToArchiveCompression(sevenZOutputFile : XZCompressorOutputStream,
thread { srcFile : File,
if (GlobalData.token.isNullOrBlank()) { desFile : File) {
return@thread if (srcFile.isFile) {
} var inputStream : FileInputStream? = null
val fileName = "normal_log.txt" try {
val file = File("$normalLogDirPath${File.separator}$fileName") inputStream = FileInputStream(srcFile)
val reName = "${AppUtils.getAppVersionCode()}_${GlobalData.vehicleInfo?.vehicleName}_${GlobalData.driverInfo?.userName}_${TimeUtils.getNowString()}.txt" val b = ByteArray(2048)
val reNamePath = "$normalLogDirPath${File.separator}$reName" var count : Int
file.renameTo(File(reNamePath)) while (inputStream.read(b).also { count = it } != - 1) {
normalLogDirPath?.let { it -> sevenZOutputFile.write(b, 0, count)
File(it).listFiles()?.forEach { }
if (it.length() / MemoryConstants.MB >= 10) { sevenZOutputFile.close()
deleteLog(it) inputStream.close()
return@thread upload(srcFile, desFile)
} } catch (e : Exception) {
if (it.exists() && !it.name.contains("normal_log")) { e.printStackTrace()
if (it.name.contains("7z")) { } finally {
upload(null, desFile = it) try {
} else { sevenZOutputFile.close()
val zipNamePath = it.absolutePath + ".7z" inputStream !!.close()
val zipFile = File(zipNamePath) } catch (e : Exception) {
if (!zipFile.exists()) { e.printStackTrace()
try { }
zipFile.createNewFile() }
} catch (e: IOException) { }
e.printStackTrace() }
}
}
compress(it, zipNamePath)
}
}
}
}
}
}
private fun compress(srcFile: File, desFilePath: String) { private fun upload(srcFile : File?, desFile : File) {
try { val requestBody : RequestBody = desFile.asRequestBody("multipart/form-data".toMediaType())
val out = XZCompressorOutputStream(FileOutputStream(desFilePath)) val part = MultipartBody.Part.createFormData("file", desFile.name, requestBody)
addToArchiveCompression(out, srcFile, File(desFilePath))
} catch (e: Exception) {
e.printStackTrace()
}
}
private fun addToArchiveCompression( val disposable =
sevenZOutputFile: XZCompressorOutputStream, LogRetrofitHelper.getDefaultService().uploadLog(part, desFile.name, "rescue-app")
srcFile: File, desFile: File .subscribeOn(Schedulers.io()).subscribe({ it ->
) { if (it.code == 200) {
if (srcFile.isFile) { deleteLog(desFile)
var inputStream: FileInputStream? = null }
try { srcFile?.let {
inputStream = FileInputStream(srcFile) deleteLog(it)
val b = ByteArray(2048) }
var count: Int }, {}, {})
while (inputStream.read(b).also { count = it } != -1) { }
sevenZOutputFile.write(b, 0, count)
}
sevenZOutputFile.close()
inputStream.close()
upload(srcFile, desFile)
} catch (e: Exception) {
e.printStackTrace()
} finally {
try {
sevenZOutputFile.close()
inputStream!!.close()
} catch (e: Exception) {
e.printStackTrace()
}
}
}
}
private fun upload(srcFile: File?, desFile: File) { private fun addLogHead(file : File, time : String) {
val requestBody: RequestBody = desFile.asRequestBody("multipart/form-data".toMediaType()) file.appendBytes("${time}---应用版本---${AppUtils.getAppVersionName()}".toByteArray())
val part = MultipartBody.Part.createFormData("file", desFile.name, requestBody) file.appendBytes("\n".toByteArray())
file.appendBytes("$time---系统版本---Android${DeviceUtils.getSDKVersionName()} ${DeviceUtils.getSDKVersionCode()}".toByteArray())
file.appendBytes("\n".toByteArray())
file.appendBytes("$time---ROM---${DeviceUtils.getManufacturer()} ${DeviceUtils.getModel()}".toByteArray())
file.appendBytes("\n".toByteArray())
file.appendBytes("$time---build---${AppUtils.getAppVersionCode()}".toByteArray())
file.appendBytes("\n".toByteArray())
file.appendBytes("$time---APP名称---中道救援-司机端".toByteArray())
file.appendBytes("\n".toByteArray())
file.appendBytes("$time---车辆名称---${GlobalData.driverInfoBean?.vehicleName}".toByteArray())
file.appendBytes("\n".toByteArray())
file.appendBytes("$time---司机名称---${GlobalData.driverInfoBean?.userName ?: GlobalData.driverInfoBean?.userName}".toByteArray())
file.appendBytes("\n".toByteArray())
}
val disposable = LogRetrofitHelper.getDefaultService() private fun getCurrentTime() : String {
.uploadLog(part, desFile.name, "rescue-app") return TimeUtils.millis2String(System.currentTimeMillis(), "yyyy/MM/dd HH:mm:ss.SSS")
.subscribeOn(Schedulers.io()) }
.subscribe({ it ->
if (it.code == 200) {
deleteLog(desFile)
}
srcFile?.let {
deleteLog(it)
}
}, {
}, {})
}
private fun addLogHead(file: File, time: String) { class LogTask(appContext : Context, workerParams : WorkerParameters) :
file.appendBytes("${time}---应用版本---${AppUtils.getAppVersionName()}".toByteArray()) Worker(appContext, workerParams) {
file.appendBytes("\n".toByteArray()) override fun doWork() : Result {
file.appendBytes("$time---系统版本---Android${DeviceUtils.getSDKVersionName()} ${DeviceUtils.getSDKVersionCode()}".toByteArray()) updateNormalLog()
file.appendBytes("\n".toByteArray()) return Result.success()
file.appendBytes("$time---ROM---${DeviceUtils.getManufacturer()} ${DeviceUtils.getModel()}".toByteArray()) }
file.appendBytes("\n".toByteArray()) }
file.appendBytes("$time---build---${AppUtils.getAppVersionCode()}".toByteArray())
file.appendBytes("\n".toByteArray())
file.appendBytes("$time---APP名称---中道救援-司机端".toByteArray())
file.appendBytes("\n".toByteArray())
file.appendBytes("$time---车辆名称---${GlobalData.vehicleInfo?.vehicleName}".toByteArray())
file.appendBytes("\n".toByteArray())
file.appendBytes("$time---司机名称---${GlobalData.driverInfo?.userName ?: GlobalData.vehicleInfo?.userName}".toByteArray())
file.appendBytes("\n".toByteArray())
}
private fun getCurrentTime(): String {
return TimeUtils.millis2String(System.currentTimeMillis(), "yyyy/MM/dd HH:mm:ss.SSS")
}
class LogTask(appContext: Context, workerParams: WorkerParameters) : Worker(appContext, workerParams) {
override fun doWork(): Result {
updateNormalLog()
return Result.success()
}
}
} }

View File

@ -8,6 +8,7 @@ import android.content.pm.PackageManager
import android.net.Uri import android.net.Uri
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.ToastUtils import com.blankj.utilcode.util.ToastUtils
import com.za.call.CallLogManager import com.za.call.CallLogManager
import com.za.call.ContactRecordBean import com.za.call.ContactRecordBean

View File

@ -26,26 +26,35 @@ fun Any?.toJson() : String? {
return JSON.toJSON(this).toString() return JSON.toJSON(this).toString()
} }
fun OrderInfo.goStatusPage(context : Context) { fun OrderInfo.goStatusPage(context : Context, isFinishActivity : Boolean? = true) {
when (this.taskState) { //等待发车 when (this.taskState) { //等待发车
"START" -> { "START" -> {
if (! RoomHelper.db?.photoTemplateDao() if (! RoomHelper.db?.photoTemplateDao()
?.getOrderPhotoTemplateFromTaskNode(10100, userOrderId ?: 0).isNullOrEmpty() ?.getOrderPhotoTemplateFromTaskNode(10100, userOrderId ?: 0).isNullOrEmpty()
) { ) {
context.navigationActivity(DeparturePhotoActivity::class.java) context.navigationActivity(DeparturePhotoActivity::class.java,
isFinish = isFinishActivity)
return return
} }
context.navigationActivity(WaitToStartActivity::class.java) context.navigationActivity(WaitToStartActivity::class.java, isFinish = isFinishActivity)
} }
"GOTO" -> context.navigationActivity(GoAccidentSiteActivity::class.java) //验证服务资格 "GOTO" -> context.navigationActivity(GoAccidentSiteActivity::class.java,
"VERIFY" -> context.navigationActivity(VerifyOrderActivity::class.java) //检查车辆 isFinish = isFinishActivity) //验证服务资格
"EXAMINE" -> context.navigationActivity(CheckVehicleActivity::class.java) //作业中 "VERIFY" -> context.navigationActivity(VerifyOrderActivity::class.java,
"OPERATION" -> context.navigationActivity(InOperationActivity::class.java) //前往目的地 isFinish = isFinishActivity) //检查车辆
"SENDTO" -> context.navigationActivity(GoToDestinationActivity::class.java) //目的地照片 "EXAMINE" -> context.navigationActivity(CheckVehicleActivity::class.java,
"DESTPHOTO" -> context.navigationActivity(DestinationPhotoActivity::class.java) //结算 isFinish = isFinishActivity) //作业
"SETTLEMENT" -> context.navigationActivity(OrderConfirmActivity::class.java) //任务结束 "OPERATION" -> context.navigationActivity(InOperationActivity::class.java,
"FINISH" -> context.navigationActivity(WaitToStartActivity::class.java) isFinish = isFinishActivity) //前往目的地
"SENDTO" -> context.navigationActivity(GoToDestinationActivity::class.java,
isFinish = isFinishActivity) //目的地照片
"DESTPHOTO" -> context.navigationActivity(DestinationPhotoActivity::class.java,
isFinish = isFinishActivity) //结算中
"SETTLEMENT" -> context.navigationActivity(OrderConfirmActivity::class.java,
isFinish = isFinishActivity) //任务结束
"FINISH" -> context.navigationActivity(WaitToStartActivity::class.java,
isFinish = isFinishActivity)
} }
} }
@ -61,25 +70,34 @@ fun OrderInfo.getNextStatus() : String? {
return flowStr return flowStr
} }
fun goNextPage(status : String?, context : Context) { fun goNextPage(status : String?, context : Context, isFinishActivity : Boolean? = true) {
when (status) { //等待发车 when (status) { //等待发车
"START" -> { "START" -> {
if (! RoomHelper.db?.photoTemplateDao()?.getOrderPhotoTemplateFromTaskNode(10100, if (! RoomHelper.db?.photoTemplateDao()?.getOrderPhotoTemplateFromTaskNode(10100,
GlobalData.currentOrder?.userOrderId ?: 0).isNullOrEmpty() GlobalData.currentOrder?.userOrderId ?: 0).isNullOrEmpty()
) { ) {
context.navigationActivity(DeparturePhotoActivity::class.java) context.navigationActivity(DeparturePhotoActivity::class.java,
isFinish = isFinishActivity)
return return
} }
context.navigationActivity(WaitToStartActivity::class.java) context.navigationActivity(WaitToStartActivity::class.java, isFinish = isFinishActivity)
} //前往事发地 } //前往事发地
"GOTO" -> context.navigationActivity(GoAccidentSiteActivity::class.java) //验证服务资格 "GOTO" -> context.navigationActivity(GoAccidentSiteActivity::class.java,
"VERIFY" -> context.navigationActivity(VerifyOrderActivity::class.java) //检查车辆 isFinish = isFinishActivity) //验证服务资格
"EXAMINE" -> context.navigationActivity(CheckVehicleActivity::class.java) //作业中 "VERIFY" -> context.navigationActivity(VerifyOrderActivity::class.java,
"OPERATION" -> context.navigationActivity(InOperationActivity::class.java) //前往目的地 isFinish = isFinishActivity) //检查车辆
"SENDTO" -> context.navigationActivity(GoToDestinationActivity::class.java) //目的地照片 "EXAMINE" -> context.navigationActivity(CheckVehicleActivity::class.java,
"DESTPHOTO" -> context.navigationActivity(DestinationPhotoActivity::class.java) //结算 isFinish = isFinishActivity) //作业
"SETTLEMENT" -> context.navigationActivity(OrderConfirmActivity::class.java) //任务结束 "OPERATION" -> context.navigationActivity(InOperationActivity::class.java,
"FINISH" -> context.navigationActivity(WaitToStartActivity::class.java) isFinish = true) //前往目的地
"SENDTO" -> context.navigationActivity(GoToDestinationActivity::class.java,
isFinish = isFinishActivity) //目的地照片
"DESTPHOTO" -> context.navigationActivity(DestinationPhotoActivity::class.java,
isFinish = isFinishActivity) //结算中
"SETTLEMENT" -> context.navigationActivity(OrderConfirmActivity::class.java,
isFinish = isFinishActivity) //任务结束
"FINISH" -> context.navigationActivity(WaitToStartActivity::class.java,
isFinish = isFinishActivity)
} }
} }

View File

@ -1,5 +1,6 @@
package com.za.net package com.za.net
import com.za.bean.AppNewDriverInfoDTO
import com.za.bean.BaseResponse import com.za.bean.BaseResponse
import com.za.bean.BatteryCostQueryBean import com.za.bean.BatteryCostQueryBean
import com.za.bean.BatteryCostQueryRequest import com.za.bean.BatteryCostQueryRequest
@ -30,6 +31,7 @@ import com.za.bean.VehicleInfo
import com.za.bean.db.order.OrderInfo import com.za.bean.db.order.OrderInfo
import com.za.bean.db.order.PhotoTemplateInfo import com.za.bean.db.order.PhotoTemplateInfo
import com.za.bean.request.AcceptOrderRequest import com.za.bean.request.AcceptOrderRequest
import com.za.bean.request.AppNewOrderVoiceRequest
import com.za.bean.request.CustomerPaymentCreateBean import com.za.bean.request.CustomerPaymentCreateBean
import com.za.bean.request.CustomerPaymentCreateRequest import com.za.bean.request.CustomerPaymentCreateRequest
import com.za.bean.request.DriverFaceCompareBean import com.za.bean.request.DriverFaceCompareBean
@ -114,6 +116,10 @@ interface ApiService {
@POST("/driverApp/task/login") @POST("/driverApp/task/login")
fun login(@Body info : LoginRequest) : Observable<BaseResponse<DriverInfo?>> fun login(@Body info : LoginRequest) : Observable<BaseResponse<DriverInfo?>>
//获取该手机号下面服务商列表
@POST("/driverApp/supplier/getDriverListInfo")
fun getDriverListInfo(@Body info : VerifyCodeRequest) : Observable<BaseResponse<List<AppNewDriverInfoDTO>>>
@POST("/driverApp/task/loginWithTask") @POST("/driverApp/task/loginWithTask")
fun loginWithTask(@Body loginWithTaskRequest : LoginWithTaskRequest) : Observable<BaseResponse<LoginWithTaskBean>> fun loginWithTask(@Body loginWithTaskRequest : LoginWithTaskRequest) : Observable<BaseResponse<LoginWithTaskBean>>
@ -262,4 +268,7 @@ interface ApiService {
//获取车辆维修历史 //获取车辆维修历史
@POST("/driverApp/supplier/v2/vehicleMaintenanceList") @POST("/driverApp/supplier/v2/vehicleMaintenanceList")
fun vehicleMaintenanceList(@Body info : FetchVehicleMaintenanceSubmitHistoryRequestBean) : Observable<BaseResponse<List<VehicleMaintenanceHistoryBean>>> fun vehicleMaintenanceList(@Body info : FetchVehicleMaintenanceSubmitHistoryRequestBean) : Observable<BaseResponse<List<VehicleMaintenanceHistoryBean>>>
@POST("driverApp/base/getVoiceUrl")
fun getVoiceUrl(@Body info : AppNewOrderVoiceRequest) : Observable<BaseResponse<String>>
} }

View File

@ -5,12 +5,10 @@ import android.graphics.BitmapFactory
import com.blankj.utilcode.util.ActivityUtils import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.ImageUtils import com.blankj.utilcode.util.ImageUtils
import com.za.base.Const import com.za.base.Const
import com.za.bean.DriverInfo
import com.za.bean.GeneralInfo import com.za.bean.GeneralInfo
import com.za.bean.ImageBean import com.za.bean.ImageBean
import com.za.bean.JpushBean import com.za.bean.JpushBean
import com.za.bean.NewOrderRequestBean import com.za.bean.NewOrderRequestBean
import com.za.bean.VehicleInfo
import com.za.bean.db.ele.EleCarDamagePhotoBean import com.za.bean.db.ele.EleCarDamagePhotoBean
import com.za.bean.db.ele.EleWorkOrderBean import com.za.bean.db.ele.EleWorkOrderBean
import com.za.bean.db.order.OrderInfo import com.za.bean.db.order.OrderInfo
@ -120,8 +118,8 @@ object CommonMethod {
success : (GeneralInfo) -> Unit = {}, success : (GeneralInfo) -> Unit = {},
failed : (String?) -> Unit = {}) { failed : (String?) -> Unit = {}) {
val generalInfoRequest = val generalInfoRequest =
GeneralInfoRequest(vehicleId = vehicleId ?: GlobalData.vehicleInfo?.vehicleId, GeneralInfoRequest(vehicleId = vehicleId ?: GlobalData.driverInfoBean?.vehicleId,
driverId = userId ?: GlobalData.driverInfo?.userId, driverId = userId ?: GlobalData.driverInfoBean?.userId,
deviceId = DeviceUtil.getAndroidId(ActivityUtils.getTopActivity())) deviceId = DeviceUtil.getAndroidId(ActivityUtils.getTopActivity()))
RetrofitHelper.getDefaultService().generalInfo(generalInfoRequest) RetrofitHelper.getDefaultService().generalInfo(generalInfoRequest)
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
@ -129,51 +127,27 @@ object CommonMethod {
override fun doSuccess(it : GeneralInfo?) { override fun doSuccess(it : GeneralInfo?) {
if (it == null) { if (it == null) {
failed("获取车辆信息失败") failed("获取车辆信息失败")
LogUtil.print("getGenerateInfo", "获取车辆信息失败")
return return
} }
if (GlobalData.vehicleInfo == null) { val driverInfoBean = GlobalData.driverInfoBean
GlobalData.vehicleInfo = VehicleInfo(vehicleId = it.vehicleId, GlobalData.driverInfoBean = driverInfoBean?.copy(vehicleId = it.vehicleId,
vehicleName = it.vehicleName, vehicleName = it.vehicleName,
userName = it.userName, userName = it.userName,
userPhone = it.userPhone, userPhone = it.userPhone,
status = it.vehicleState, plateNumber = it.plateNumber,
plateNumber = it.plateNumber, vehicleState = it.vehicleState,
vehicleState = it.vehicleState, supplierType = it.supplierType,
supplierType = it.supplierType) userPortrait = it.userPortrait,
} else { userId = it.userId,
GlobalData.vehicleInfo = supplierId = it.supplierId,
GlobalData.vehicleInfo?.copy(vehicleId = it.vehicleId, deviceId = it.deviceId,
vehicleName = it.vehicleName, supplierName = it.supplierName,
userName = it.userName, authStatus = it.authStatus,
userPhone = it.userPhone, serviceList = it.serviceList?.toString())
status = it.vehicleState,
plateNumber = it.plateNumber,
vehicleState = it.vehicleState,
supplierType = it.supplierType)
}
if (GlobalData.driverInfo == null) { LogUtil.print("GlobalData.driverInfoBean",
GlobalData.driverInfo = DriverInfo(userPortrait = it.userPortrait, "${GlobalData.driverInfoBean?.toJson()}}")
userName = it.userName,
userId = it.userId,
userPhone = it.userPhone,
supplierId = it.supplierId.toString(),
supplierName = it.supplierName,
authStatus = it.authStatus,
supplierType = it.supplierType,
serviceList = it.serviceList)
} else {
GlobalData.driverInfo =
GlobalData.driverInfo?.copy(userPortrait = it.userPortrait,
userName = it.userName,
userId = it.userId,
userPhone = it.userPhone,
supplierId = it.supplierId.toString(),
supplierName = it.supplierName,
authStatus = it.authStatus,
supplierType = it.supplierType,
serviceList = it.serviceList)
}
success(it) success(it)
} }
@ -187,7 +161,7 @@ object CommonMethod {
} }
fun getNewOrder(context : Context) { fun getNewOrder(context : Context) {
val newOrderRequestBean = NewOrderRequestBean(GlobalData.vehicleInfo?.vehicleId) val newOrderRequestBean = NewOrderRequestBean(GlobalData.driverInfoBean?.vehicleId)
RetrofitHelper.getDefaultService().getNewOrder(newOrderRequestBean) RetrofitHelper.getDefaultService().getNewOrder(newOrderRequestBean)
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(object : BaseObserver<JpushBean>() { .subscribe(object : BaseObserver<JpushBean>() {
@ -229,7 +203,7 @@ object CommonMethod {
success : (OrderInfo?, List<OrderInfo>?) -> Unit, success : (OrderInfo?, List<OrderInfo>?) -> Unit,
failed : (String?) -> Unit) { failed : (String?) -> Unit) {
RetrofitHelper.getDefaultService() RetrofitHelper.getDefaultService()
.queryOrderList(OrderListRequest(vehicleId = GlobalData.vehicleInfo?.vehicleId, .queryOrderList(OrderListRequest(vehicleId = GlobalData.driverInfoBean?.vehicleId,
deviceId = DeviceUtil.getAndroidId(ActivityUtils.getTopActivity()))) deviceId = DeviceUtil.getAndroidId(ActivityUtils.getTopActivity())))
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
.subscribe(object : BaseObserver<List<OrderInfo>?>() { .subscribe(object : BaseObserver<List<OrderInfo>?>() {
@ -246,33 +220,6 @@ object CommonMethod {
val waitServiceOrders = it.filter { it.isCurrent == false } val waitServiceOrders = it.filter { it.isCurrent == false }
if (inServicingOrder == null) { if (inServicingOrder == null) {
context?.let { context ->
val order = it[0]
NewOrderActivity.goNewOrderActivity(context,
jpushBean = JpushBean(taskId = order.taskId,
taskCode = order.taskCode,
customerName = order.customerName,
customerPhone = order.customerPhone,
carBrand = order.carBrand,
carModel = order.carModel,
carNo = order.carNo,
taskState = order.taskState,
address = order.address,
addressProperty = order.addressProperty,
hotline = order.hotline,
expectArriveTime = order.expectArriveTime,
serviceTypeName = order.serviceTypeName,
dispatchTime = order.dispatchTime,
lat = order.lat,
lng = order.lng,
distLat = order.distLat,
distLng = order.distLng,
importantTip = order.importantTip,
hasReplaceBatteryCapable = order.hasReplaceBatteryCapable,
distAddress = order.distAddress,
distAddressRemark = order.distAddressRemark,
addressRemark = order.addressRemark))
}
success(null, waitServiceOrders) success(null, waitServiceOrders)
return return
} }

View File

@ -2,6 +2,7 @@ package com.za.net
import android.util.Log import android.util.Log
import com.za.base.AppConfig import com.za.base.AppConfig
import com.za.common.log.LogUtil
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit import retrofit2.Retrofit
@ -12,72 +13,55 @@ import java.net.URLDecoder
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
object RetrofitHelper { object RetrofitHelper {
private var retrofit: Retrofit? = null private var retrofit : Retrofit? = null
private var apiService: ApiService? = null private var apiService : ApiService? = null
private val loggerInterceptor = HttpLoggingInterceptor { private val loggerInterceptor = HttpLoggingInterceptor {
try { try {
if (it.contains("image/*") || it.contains("form-data; name=\"file\"") if (it.contains("image/*") || it.contains("form-data; name=\"file\"") || it.startsWith("Content-Type") || it.startsWith(
|| it.startsWith("Content-Type") "Content-Length") || it.startsWith("Server") || it.startsWith("Date") || it.startsWith(
|| it.startsWith("Content-Length") "Transfer-Encoding") || it.startsWith("Connection") || it.startsWith("X-") || it.startsWith(
|| it.startsWith("Server") "token") || it.startsWith("Cache-Control") || it.startsWith("Expires") || it.startsWith(
|| it.startsWith("Date") "Accept") || it.startsWith("Vary") || it.isEmpty() || it.startsWith("Pragma")
|| it.startsWith("Transfer-Encoding") ) {
|| it.startsWith("Connection") return@HttpLoggingInterceptor
|| it.startsWith("X-") }
|| it.startsWith("token")
|| it.startsWith("Cache-Control")
|| it.startsWith("Expires")
|| it.startsWith("Accept")
|| it.startsWith("Vary")
|| it.isEmpty()
|| it.startsWith("Pragma")
) {
return@HttpLoggingInterceptor
}
if (it.contains("name=\"file\"; filename")) { if (it.contains("name=\"file\"; filename")) {
return@HttpLoggingInterceptor return@HttpLoggingInterceptor
} }
Log.e( LogUtil.print("--network--",
"--network--", URLDecoder.decode(it.replace(Regex("%(?![0-9a-fA-F]{2})"), ""), "utf-8"))
URLDecoder.decode(it.replace(Regex("%(?![0-9a-fA-F]{2})"), ""), "utf-8") } catch (e : UnsupportedEncodingException) {
) e.printStackTrace()
} catch (e: UnsupportedEncodingException) { }
e.printStackTrace()
}
}.setLevel(HttpLoggingInterceptor.Level.BODY) }.setLevel(HttpLoggingInterceptor.Level.BODY)
fun getDefaultService(): ApiService { fun getDefaultService() : ApiService {
return if (apiService == null) { return if (apiService == null) {
apiService = getDefaultRetrofit().create(ApiService::class.java) apiService = getDefaultRetrofit().create(ApiService::class.java)
apiService!! apiService !!
} else { } else {
apiService!! apiService !!
} }
} }
private fun getDefaultRetrofit(): Retrofit { private fun getDefaultRetrofit() : Retrofit {
return if (retrofit == null) { return if (retrofit == null) {
retrofit = Retrofit.Builder().baseUrl(AppConfig.BASE_URL) retrofit = Retrofit.Builder().baseUrl(AppConfig.BASE_URL)
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava3CallAdapterFactory.create()) .addCallAdapterFactory(RxJava3CallAdapterFactory.create()).client(getOkHttpClient())
.client(getOkHttpClient()) .build()
.build() retrofit !!
retrofit!! } else {
} else { retrofit !!
retrofit!! }
} }
}
private fun getOkHttpClient(): OkHttpClient { private fun getOkHttpClient() : OkHttpClient {
return OkHttpClient.Builder() return OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS)
.connectTimeout(30, TimeUnit.SECONDS) .writeTimeout(60, TimeUnit.SECONDS).readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS) .addInterceptor(RequestEncryptInterceptor()).addInterceptor(loggerInterceptor).build()
.readTimeout(60, TimeUnit.SECONDS) }
.addInterceptor(RequestEncryptInterceptor())
.addInterceptor(loggerInterceptor)
.build()
}
} }

View File

@ -176,7 +176,7 @@ object OfflineManager {
lng = offlineUpdateTaskBean.imageLng.toDouble(), lng = offlineUpdateTaskBean.imageLng.toDouble(),
address = it, address = it,
time = offlineUpdateTaskBean.time, time = offlineUpdateTaskBean.time,
driverName = GlobalData.driverInfo?.userName, driverName = GlobalData.driverInfoBean?.userName,
taskCode = offlineUpdateTaskBean.taskCode) taskCode = offlineUpdateTaskBean.taskCode)
val offlineTemp = offlineUpdateTaskBean.copy(imageAddress = it) val offlineTemp = offlineUpdateTaskBean.copy(imageAddress = it)
file = File(PhotoMarkerManager.addPhotoMarker(ActivityUtils.getTopActivity(), file = File(PhotoMarkerManager.addPhotoMarker(ActivityUtils.getTopActivity(),

View File

@ -11,7 +11,7 @@ import com.za.room.db.GlobalRoom
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
object RoomHelper { object RoomHelper {
const val VERSION: Int = 35 const val VERSION: Int = 37
private lateinit var mContext: Context private lateinit var mContext: Context
var db: GlobalRoom? = null var db: GlobalRoom? = null

View File

@ -2,7 +2,6 @@ package com.za.room.db
import androidx.room.Database import androidx.room.Database
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.za.bean.db.ChangeBatteryPhoto import com.za.bean.db.ChangeBatteryPhoto
import com.za.bean.db.NewPhotoTemplateBean import com.za.bean.db.NewPhotoTemplateBean
import com.za.bean.db.ele.EleCarDamagePhotoBean import com.za.bean.db.ele.EleCarDamagePhotoBean
@ -11,7 +10,6 @@ import com.za.bean.db.order.OrderInfo
import com.za.bean.db.order.PhotoTemplateInfo import com.za.bean.db.order.PhotoTemplateInfo
import com.za.bean.db.water_marker.WaterMarkerItemBean import com.za.bean.db.water_marker.WaterMarkerItemBean
import com.za.bean.db.water_marker.WaterMarkerTemplateBean import com.za.bean.db.water_marker.WaterMarkerTemplateBean
import com.za.offline.InspectionConverter
import com.za.offline.OfflineDao import com.za.offline.OfflineDao
import com.za.offline.OfflineUpdateTaskBean import com.za.offline.OfflineUpdateTaskBean
import com.za.room.RoomHelper import com.za.room.RoomHelper
@ -20,30 +18,32 @@ import com.za.room.db.ele_work.EleWorkOrderDao
import com.za.room.db.order.ChangeBatteryDao import com.za.room.db.order.ChangeBatteryDao
import com.za.room.db.order.OrderDao import com.za.room.db.order.OrderDao
import com.za.room.db.order.PhotoTemplateDao import com.za.room.db.order.PhotoTemplateDao
import com.za.room.db.user.DriverInfoBean
import com.za.room.db.user.DriverInfoDao
import com.za.room.db.user.LocalResourceBean
import com.za.room.db.user.LocalResourceDao
import com.za.room.db.water_marker.WaterMarkerDao import com.za.room.db.water_marker.WaterMarkerDao
@Database(entities = [EleWorkOrderBean::class, @Database(entities = [EleWorkOrderBean::class, EleCarDamagePhotoBean::class, LocalResourceBean::class, WaterMarkerTemplateBean::class, WaterMarkerItemBean::class, ChangeBatteryPhoto::class, NewPhotoTemplateBean::class, OrderInfo::class, OfflineUpdateTaskBean::class, DriverInfoBean::class, PhotoTemplateInfo::class],
EleCarDamagePhotoBean::class, version = RoomHelper.VERSION,
WaterMarkerTemplateBean::class, exportSchema = false)
WaterMarkerItemBean::class,
ChangeBatteryPhoto::class,
NewPhotoTemplateBean::class,
OrderInfo::class,
OfflineUpdateTaskBean::class,
PhotoTemplateInfo::class], version = RoomHelper.VERSION, exportSchema = false)
abstract class GlobalRoom : RoomDatabase() { abstract class GlobalRoom : RoomDatabase() {
abstract fun eleWorkOrderDao(): EleWorkOrderDao abstract fun eleWorkOrderDao() : EleWorkOrderDao
abstract fun eleCarDamagePhotoDao(): EleCarDamagePhotoDao abstract fun eleCarDamagePhotoDao() : EleCarDamagePhotoDao
abstract fun waterMarkerDao(): WaterMarkerDao abstract fun waterMarkerDao() : WaterMarkerDao
abstract fun changeBatteryDao(): ChangeBatteryDao abstract fun changeBatteryDao() : ChangeBatteryDao
abstract fun orderDao(): OrderDao abstract fun orderDao() : OrderDao
abstract fun photoTemplateDao(): PhotoTemplateDao abstract fun photoTemplateDao() : PhotoTemplateDao
abstract fun offlineTaskDao(): OfflineDao abstract fun offlineTaskDao() : OfflineDao
abstract fun driverInfoDao() : DriverInfoDao
abstract fun localResourceDao() : LocalResourceDao
} }

View File

@ -0,0 +1,26 @@
package com.za.room.db.user
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "driver_info")
data class DriverInfoBean(
@PrimaryKey(autoGenerate = false) val userId : Int? = null, //用户id
val userName : String? = null, //用户姓名
val userPhone : String? = null, //用户手机号
val userPortrait : String? = null, //用户头像
val rongyunToken : String? = null,
val logTime : String? = null,
val supplierId : Int? = null, //经销商id
val supplierName : String? = null, //经销商名称
val supplierType : Int? = null, //经销商类型 1子公司 2供应商
val loginLogId : Int? = null,
val serviceList : String? = null, //车辆服务列表
val assistUserCode : String? = null,
val authStatus : Int? = null, // 0 未认证 1 已认证
val vehicleId : Int? = null,
val vehicleName : String? = null,
val vehicleState : Int? = null, //车辆状态 0 空闲 1 忙碌
val plateNumber : String? = null, //车牌号
val deviceId : String? = null,
)

View File

@ -0,0 +1,40 @@
package com.za.room.db.user
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import com.za.common.log.LogUtil
@Dao
interface DriverInfoDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(driverInfoBean : DriverInfoBean)
@Query("SELECT * FROM driver_info")
fun getDriverInfoFromUserId() : DriverInfoBean?
@Query("DELETE FROM driver_info")
fun deleteAll()
@Update(onConflict = OnConflictStrategy.REPLACE)
fun update(driverInfoBean : DriverInfoBean)
@Transaction
fun updateDriverInfo(driverInfoBean : DriverInfoBean?) {
if (driverInfoBean == null) {
LogUtil.print("DriverInfoDao", "updateDriverInfo driverInfoBean is null")
return
}
val driverInfo = getDriverInfoFromUserId()
if (driverInfo != null && driverInfo.userId == driverInfoBean.userId) {
update(driverInfoBean)
return
}
deleteAll()
insert(driverInfoBean)
}
}

View File

@ -0,0 +1,10 @@
package com.za.room.db.user
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "local_resource_bean")
data class LocalResourceBean(@PrimaryKey val resourceName : String,
val resourceType : Int = 0,
val resourceUrl : String? = null,
val resourceDescription : String? = null)

View File

@ -0,0 +1,32 @@
package com.za.room.db.user
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
@Dao
interface LocalResourceDao {
@Insert
fun insert(localResourceBean : LocalResourceBean)
@Update
fun update(localResourceBean : LocalResourceBean)
@Delete
fun delete(localResourceBean : LocalResourceBean)
@get:Query("SELECT * FROM local_resource_bean")
val allLocalResources : List<LocalResourceBean?>?
@Query("SELECT * FROM local_resource_bean WHERE resourceName = :resourceName")
fun getLocalResourceByName(resourceName : String?) : LocalResourceBean?
@Query("SELECT * FROM local_resource_bean WHERE resourceType = :resourceType")
fun getLocalResourcesByType(resourceType : Int) : List<LocalResourceBean>?
@Query("DELETE FROM local_resource_bean")
fun deleteAllLocalResources()
}

View File

@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import cn.jpush.android.api.JPushInterface import cn.jpush.android.api.JPushInterface
import com.za.common.GlobalData
import com.za.common.log.LogUtil import com.za.common.log.LogUtil
import com.za.service.ServiceManager import com.za.service.ServiceManager
@ -11,28 +12,33 @@ import com.za.service.ServiceManager
* Created by zhangj on 2019/4/4. * Created by zhangj on 2019/4/4.
*/ */
class JPushReceiver : BroadcastReceiver() { class JPushReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context : Context, intent : Intent) {
val bundle = intent.extras val bundle = intent.extras
LogUtil.print("JpushMessage ", "onReceive==" + "action:" + intent.action) LogUtil.print("JpushMessage ", "onReceive==" + "action:" + intent.action)
if (intent.action == null || bundle == null) { return } if (intent.action == null || bundle == null) {
when (intent.action) { return
JPushInterface.ACTION_REGISTRATION_ID -> { }
val regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID) when (intent.action) {
LogUtil.print("JpushMessage ", "Registration successful: $regId") JPushInterface.ACTION_REGISTRATION_ID -> {
} val regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID)
GlobalData.regid = regId
LogUtil.print("JpushMessage ", "Registration successful: $regId")
}
JPushInterface.ACTION_MESSAGE_RECEIVED -> { JPushInterface.ACTION_MESSAGE_RECEIVED -> {
val msg = bundle.getString(JPushInterface.EXTRA_MESSAGE) val msg = bundle.getString(JPushInterface.EXTRA_MESSAGE)
if (msg.isNullOrBlank()) { return } if (msg.isNullOrBlank()) {
ServiceManager.handlerPushMsg(msg) return
} }
ServiceManager.handlerPushMsg(msg)
}
JPushInterface.ACTION_NOTIFICATION_RECEIVED -> { JPushInterface.ACTION_NOTIFICATION_RECEIVED -> {
val title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE) val title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE)
LogUtil.print("JPushReceiver:", "ACTION_NOTIFICATION_RECEIVED title: $title") LogUtil.print("JPushReceiver:", "ACTION_NOTIFICATION_RECEIVED title: $title")
} }
else -> {} else -> {}
} }
} }
} }

View File

@ -123,8 +123,8 @@ object ZdLocationManager : AMapLocationListener {
val request = UploadGpsRequest().apply { val request = UploadGpsRequest().apply {
lat = location.latitude lat = location.latitude
lng = location.longitude lng = location.longitude
userId = GlobalData.driverInfo?.userId userId = GlobalData.driverInfoBean?.userId
vehicleId = GlobalData.vehicleInfo?.vehicleId vehicleId = GlobalData.driverInfoBean?.vehicleId
working = GlobalData.currentOrder != null working = GlobalData.currentOrder != null
direction = location.bearing.toDouble() direction = location.bearing.toDouble()
speed = location.speed.toDouble() speed = location.speed.toDouble()

View File

@ -103,8 +103,8 @@ class CommonH5Activity : BaseActivity() {
append("/training/training.html") append("/training/training.html")
append("?id=").append(articleId) append("?id=").append(articleId)
append("&source=driverApp") append("&source=driverApp")
append("&driverId=").append(GlobalData.driverInfo?.userId) append("&driverId=").append(GlobalData.driverInfoBean?.userId)
append("&userId=").append(GlobalData.driverInfo?.userId) append("&userId=").append(GlobalData.driverInfoBean?.userId)
} }
override fun onDestroy() { override fun onDestroy() {

View File

@ -170,7 +170,6 @@ class ServiceLauncherActivity : BaseActivity() {
private fun navigateToNextScreen() { private fun navigateToNextScreen() {
if (GlobalData.isMaster) { if (GlobalData.isMaster) {
GlobalData.currentOrder?.goStatusPage(this) GlobalData.currentOrder?.goStatusPage(this)
finish()
return return
} }
val driverName = intent.getStringExtra("driverName") val driverName = intent.getStringExtra("driverName")

View File

@ -81,7 +81,6 @@ private fun ServicingMainScreen(jobCode : String? = null,
} }
} else { } else {
GlobalData.currentOrder?.goStatusPage(ActivityUtils.getTopActivity()) GlobalData.currentOrder?.goStatusPage(ActivityUtils.getTopActivity())
context.finish()
} }
} }

View File

@ -86,9 +86,15 @@ class NewOrderActivity : BaseActivity() {
} else { } else {
intent.getSerializableExtra("jpushBean") intent.getSerializableExtra("jpushBean")
} }
GlobalData.isHandlerNewOrder = false
AcceptOrderScreen(jpushBean = jpushBean as JpushBean) AcceptOrderScreen(jpushBean = jpushBean as JpushBean)
} }
override fun onStop() {
super.onStop()
GlobalData.isHandlerNewOrder = true
}
companion object { companion object {
fun goNewOrderActivity(context : Context, jpushBean : JpushBean) { fun goNewOrderActivity(context : Context, jpushBean : JpushBean) {
val intent = Intent(context, NewOrderActivity::class.java) val intent = Intent(context, NewOrderActivity::class.java)
@ -196,24 +202,24 @@ private fun AcceptOrderScreen(jpushBean : JpushBean?, vm : NewOrderVm = viewMode
topBar = { HeadViewNotBack(title = "新订单") }, topBar = { HeadViewNotBack(title = "新订单") },
sheetContent = { sheetContent = {
Column(modifier = Modifier Column(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.wrapContentHeight() .wrapContentHeight()
.background(Color.White) .background(Color.White)
.verticalScroll(rememberScrollState())) { // 滑动指示器 .verticalScroll(rememberScrollState())) { // 滑动指示器
Box(modifier = Modifier Box(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(vertical = 8.dp) .padding(vertical = 8.dp)
.background(Color.White), contentAlignment = Alignment.Center) { .background(Color.White), contentAlignment = Alignment.Center) {
Box(modifier = Modifier Box(modifier = Modifier
.width(32.dp) .width(32.dp)
.height(4.dp) .height(4.dp)
.background(color = Color(0xFFE0E0E0), shape = RoundedCornerShape(2.dp))) .background(color = Color(0xFFE0E0E0), shape = RoundedCornerShape(2.dp)))
} }
// 滑动指示器和订单类型行 // 滑动指示器和订单类型行
Row(modifier = Modifier Row(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 12.dp), .padding(horizontal = 16.dp, vertical = 12.dp),
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically) { verticalAlignment = Alignment.CenterVertically) {
Text(text = uiState.value.jpushBean?.serviceTypeName ?: "", Text(text = uiState.value.jpushBean?.serviceTypeName ?: "",
@ -230,8 +236,8 @@ private fun AcceptOrderScreen(jpushBean : JpushBean?, vm : NewOrderVm = viewMode
// 添加距离和时间信息 // 添加距离和时间信息
Row(modifier = Modifier Row(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 12.dp), .padding(horizontal = 16.dp, vertical = 12.dp),
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically) { verticalAlignment = Alignment.CenterVertically) {
Text(text = "预计到达: ${uiState.value.estimatedArrivalTime}", Text(text = "预计到达: ${uiState.value.estimatedArrivalTime}",
@ -244,13 +250,13 @@ private fun AcceptOrderScreen(jpushBean : JpushBean?, vm : NewOrderVm = viewMode
} }
HorizontalDivider(modifier = Modifier HorizontalDivider(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.alpha(0.1f)) .alpha(0.1f))
// 订单信息 // 订单信息
Column(modifier = Modifier Column(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 12.dp)) { // 订单标签 .padding(horizontal = 16.dp, vertical = 12.dp)) { // 订单标签
Row(verticalAlignment = Alignment.CenterVertically, Row(verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)) { horizontalArrangement = Arrangement.spacedBy(8.dp)) {
@ -338,13 +344,13 @@ private fun AcceptOrderScreen(jpushBean : JpushBean?, vm : NewOrderVm = viewMode
// 修改按钮状态 // 修改按钮状态
Row(modifier = Modifier Row(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 16.dp), .padding(horizontal = 16.dp, vertical = 16.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp)) { // 拒单按钮 horizontalArrangement = Arrangement.spacedBy(12.dp)) { // 拒单按钮
Button(onClick = { vm.dispatch(NewOrderVm.Action.RefuseOrder) }, Button(onClick = { vm.dispatch(NewOrderVm.Action.RefuseOrder) },
modifier = Modifier modifier = Modifier
.weight(1f) .weight(1f)
.height(44.dp), .height(44.dp),
colors = ButtonDefaults.buttonColors(containerColor = Color.White, colors = ButtonDefaults.buttonColors(containerColor = Color.White,
contentColor = Color(0xFF666666)), contentColor = Color(0xFF666666)),
border = BorderStroke(1.dp, Color(0xFFE5E5E5)), border = BorderStroke(1.dp, Color(0xFFE5E5E5)),
@ -355,8 +361,8 @@ private fun AcceptOrderScreen(jpushBean : JpushBean?, vm : NewOrderVm = viewMode
// 接单按钮 // 接单按钮
Button(onClick = { vm.dispatch(NewOrderVm.Action.AcceptOrder) }, Button(onClick = { vm.dispatch(NewOrderVm.Action.AcceptOrder) },
modifier = Modifier modifier = Modifier
.weight(1f) .weight(1f)
.height(44.dp), .height(44.dp),
colors = ButtonDefaults.buttonColors(containerColor = headBgColor), colors = ButtonDefaults.buttonColors(containerColor = headBgColor),
shape = RoundedCornerShape(8.dp)) { shape = RoundedCornerShape(8.dp)) {
Text(text = "接单", Text(text = "接单",
@ -375,8 +381,8 @@ private fun AcceptOrderScreen(jpushBean : JpushBean?, vm : NewOrderVm = viewMode
sheetDragHandle = null, sheetDragHandle = null,
sheetSwipeEnabled = true) { paddingValues -> sheetSwipeEnabled = true) { paddingValues ->
Box(modifier = Modifier Box(modifier = Modifier
.fillMaxSize() .fillMaxSize()
.padding(paddingValues)) { .padding(paddingValues)) {
AndroidView(modifier = Modifier.fillMaxSize(), factory = { AndroidView(modifier = Modifier.fillMaxSize(), factory = {
AMapLocationClient.updatePrivacyShow(context, true, true) AMapLocationClient.updatePrivacyShow(context, true, true)
AMapLocationClient.updatePrivacyAgree(context, true) AMapLocationClient.updatePrivacyAgree(context, true)
@ -423,7 +429,7 @@ private fun AcceptOrderScreen(jpushBean : JpushBean?, vm : NewOrderVm = viewMode
// 添加当前位置标记 // 添加当前位置标记
currentLocation?.let { currentLocation?.let {
mapView.map.addMarker(MarkerOptions().position(it).title("当前位置") mapView.map.addMarker(MarkerOptions().position(it).title("当前位置")
.icon(ImageUtil.vectorToBitmap(context,R.drawable.ic_current_location)) .icon(ImageUtil.vectorToBitmap(context, R.drawable.ic_current_location))
.anchor(0.5f, 0.5f).visible(true)) .anchor(0.5f, 0.5f).visible(true))
allPoints.add(it) allPoints.add(it)
} }
@ -477,14 +483,14 @@ private fun AcceptOrderScreen(jpushBean : JpushBean?, vm : NewOrderVm = viewMode
private fun OrderItemView(jpushBean : JpushBean?, remainingTime : Int = 50) { private fun OrderItemView(jpushBean : JpushBean?, remainingTime : Int = 50) {
val context = LocalContext.current val context = LocalContext.current
Column(modifier = Modifier Column(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.background(color = Color.White) .background(color = Color.White)
.padding(bottom = 16.dp)) { // 订单类型和倒计时 .padding(bottom = 16.dp)) { // 订单类型和倒计时
Row(modifier = Modifier Row(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.background(brush = Brush.verticalGradient(colors = arrayListOf(Color(0xFFFFEDE3), .background(brush = Brush.verticalGradient(colors = arrayListOf(Color(0xFFFFEDE3),
Color.White))) Color.White)))
.padding(horizontal = 16.dp, vertical = 12.dp), .padding(horizontal = 16.dp, vertical = 12.dp),
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically) { verticalAlignment = Alignment.CenterVertically) {
Text(text = jpushBean?.serviceTypeName ?: "", Text(text = jpushBean?.serviceTypeName ?: "",
@ -498,19 +504,19 @@ private fun OrderItemView(jpushBean : JpushBean?, remainingTime : Int = 50) {
} }
HorizontalDivider(modifier = Modifier HorizontalDivider(modifier = Modifier
.padding(horizontal = 16.dp) .padding(horizontal = 16.dp)
.alpha(0.08f)) .alpha(0.08f))
// 订单标签 // 订单标签
Row(modifier = Modifier Row(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 12.dp), .padding(horizontal = 16.dp, vertical = 12.dp),
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically) { verticalAlignment = Alignment.CenterVertically) {
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
Box(modifier = Modifier Box(modifier = Modifier
.background(Color(0xFF9BA1B2), RoundedCornerShape(4.dp)) .background(Color(0xFF9BA1B2), RoundedCornerShape(4.dp))
.padding(horizontal = 6.dp, vertical = 2.dp)) { .padding(horizontal = 6.dp, vertical = 2.dp)) {
Text(text = "月结", color = Color.White, fontSize = 12.sp) Text(text = "月结", color = Color.White, fontSize = 12.sp)
} }
Spacer(modifier = Modifier.width(8.dp)) Spacer(modifier = Modifier.width(8.dp))
@ -524,9 +530,9 @@ private fun OrderItemView(jpushBean : JpushBean?, remainingTime : Int = 50) {
// 订单号 // 订单号
Row(modifier = Modifier Row(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp) .padding(horizontal = 16.dp)
.clickable { jpushBean?.taskCode?.copy(context) }, .clickable { jpushBean?.taskCode?.copy(context) },
verticalAlignment = Alignment.CenterVertically) { verticalAlignment = Alignment.CenterVertically) {
Text(text = "单号", color = Color(0xFF999999), fontSize = 13.sp) Text(text = "单号", color = Color(0xFF999999), fontSize = 13.sp)
Spacer(modifier = Modifier.width(8.dp)) Spacer(modifier = Modifier.width(8.dp))
@ -544,8 +550,8 @@ private fun OrderItemView(jpushBean : JpushBean?, remainingTime : Int = 50) {
// 救援地址 // 救援地址
Row(modifier = Modifier Row(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
verticalAlignment = Alignment.Top) { verticalAlignment = Alignment.Top) {
AsyncImage(model = R.drawable.sv_rescuing, AsyncImage(model = R.drawable.sv_rescuing,
contentDescription = "rescue", contentDescription = "rescue",
@ -561,12 +567,12 @@ private fun OrderItemView(jpushBean : JpushBean?, remainingTime : Int = 50) {
if (! jpushBean?.distAddress.isNullOrBlank()) { if (! jpushBean?.distAddress.isNullOrBlank()) {
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
HorizontalDivider(modifier = Modifier HorizontalDivider(modifier = Modifier
.padding(horizontal = 24.dp) .padding(horizontal = 24.dp)
.alpha(0.1f)) .alpha(0.1f))
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
Row(modifier = Modifier Row(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
verticalAlignment = Alignment.Top) { verticalAlignment = Alignment.Top) {
AsyncImage(model = R.drawable.sv_dist, AsyncImage(model = R.drawable.sv_dist,
contentDescription = "destination", contentDescription = "destination",

View File

@ -93,8 +93,8 @@ class NewOrderVm : BaseVm<NewOrderVm.Action, NewOrderVm.UiState>() {
val orderInfo = uiState.value.jpushBean val orderInfo = uiState.value.jpushBean
val acceptOrderRequest = AcceptOrderRequest() val acceptOrderRequest = AcceptOrderRequest()
acceptOrderRequest.taskId = orderInfo?.taskId acceptOrderRequest.taskId = orderInfo?.taskId
acceptOrderRequest.vehicleId = GlobalData.vehicleInfo?.vehicleId acceptOrderRequest.vehicleId = GlobalData.driverInfoBean?.vehicleId
acceptOrderRequest.userId = GlobalData.driverInfo?.userId acceptOrderRequest.userId = GlobalData.driverInfoBean?.userId
acceptOrderRequest.taskCode = orderInfo?.taskCode acceptOrderRequest.taskCode = orderInfo?.taskCode
acceptOrderRequest.deviceId = DeviceUtil.getAndroidId(ActivityUtils.getTopActivity()) acceptOrderRequest.deviceId = DeviceUtil.getAndroidId(ActivityUtils.getTopActivity())
acceptOrderRequest.lat = it.latitude acceptOrderRequest.lat = it.latitude
@ -123,9 +123,9 @@ class NewOrderVm : BaseVm<NewOrderVm.Action, NewOrderVm.UiState>() {
private fun refuseOrder() { private fun refuseOrder() {
LoadingManager.showLoading() LoadingManager.showLoading()
RetrofitHelper.getDefaultService().refuseOrder(RefuseOrderRequest(taskId = uiState.value.jpushBean?.taskId, RetrofitHelper.getDefaultService().refuseOrder(RefuseOrderRequest(taskId = uiState.value.jpushBean?.taskId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
taskCode = uiState.value.jpushBean?.taskCode, taskCode = uiState.value.jpushBean?.taskCode,
userId = GlobalData.driverInfo?.userId)) userId = GlobalData.driverInfoBean?.userId))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(object : BaseObserver<String>() { .subscribe(object : BaseObserver<String>() {
@ -147,7 +147,7 @@ class NewOrderVm : BaseVm<NewOrderVm.Action, NewOrderVm.UiState>() {
timerJob?.cancel() timerJob?.cancel()
timerJob = viewModelScope.launch { timerJob = viewModelScope.launch {
try { try {
var timeLeft = 50 var timeLeft = 120
while (timeLeft > 0 && isActive) { while (timeLeft > 0 && isActive) {
delay(1000) delay(1000)
timeLeft-- timeLeft--

View File

@ -108,7 +108,7 @@ private fun handlerInServicingPhoto(
lng = localPhotoTemplateInfo.lng?.toDouble(), lng = localPhotoTemplateInfo.lng?.toDouble(),
address = localPhotoTemplateInfo.address, address = localPhotoTemplateInfo.address,
time = localPhotoTemplateInfo.time, time = localPhotoTemplateInfo.time,
driverName = GlobalData.driverInfo?.userName, driverName = GlobalData.driverInfoBean?.userName,
taskCode = localPhotoTemplateInfo.taskCode) taskCode = localPhotoTemplateInfo.taskCode)
File(PhotoMarkerManager.addPhotoMarker(context = context, photoMarkerInfo)) File(PhotoMarkerManager.addPhotoMarker(context = context, photoMarkerInfo))
} else { } else {
@ -188,7 +188,7 @@ private fun handlerChangeBatteryPhoto(context : Context,
lng = localPhotoTemplateInfo.lng?.toDouble(), lng = localPhotoTemplateInfo.lng?.toDouble(),
address = localPhotoTemplateInfo.address, address = localPhotoTemplateInfo.address,
time = localPhotoTemplateInfo.time, time = localPhotoTemplateInfo.time,
driverName = GlobalData.driverInfo?.userName, driverName = GlobalData.driverInfoBean?.userName,
taskCode = localPhotoTemplateInfo.taskCode) taskCode = localPhotoTemplateInfo.taskCode)
File(PhotoMarkerManager.addPhotoMarker(context = context, photoMarkerInfo)) File(PhotoMarkerManager.addPhotoMarker(context = context, photoMarkerInfo))
} else { } else {
@ -270,7 +270,7 @@ private fun handlerNormalPhoto(context : Context,
lng = localPhotoTemplateInfo.lng?.toDouble(), lng = localPhotoTemplateInfo.lng?.toDouble(),
address = localPhotoTemplateInfo.address, address = localPhotoTemplateInfo.address,
time = localPhotoTemplateInfo.time, time = localPhotoTemplateInfo.time,
driverName = GlobalData.driverInfo?.userName, driverName = GlobalData.driverInfoBean?.userName,
taskCode = localPhotoTemplateInfo.taskCode) taskCode = localPhotoTemplateInfo.taskCode)
File(PhotoMarkerManager.addPhotoMarker(context = context, photoMarkerInfo)) File(PhotoMarkerManager.addPhotoMarker(context = context, photoMarkerInfo))
} else { } else {

View File

@ -42,7 +42,6 @@ fun CheckVehicleScreen(vm: CheckVehicleVm = viewModel()) {
if (uiState.value.goNextPage != null) { if (uiState.value.goNextPage != null) {
goNextPage(uiState.value.goNextPage?.nextState, context) goNextPage(uiState.value.goNextPage?.nextState, context)
context.finish()
} }
if (uiState.value.isGoNextPageDialog == true) { if (uiState.value.isGoNextPageDialog == true) {

View File

@ -97,8 +97,8 @@ class CheckVehicleVm : IServicingVm<CheckVehicleVm.Action, CheckVehicleVm.UiStat
private fun doUploadOfflineTask(it : AMapLocation?, tempPhotoList : ArrayList<String?>) { private fun doUploadOfflineTask(it : AMapLocation?, tempPhotoList : ArrayList<String?>) {
val taskRequest = UpdateTaskRequest(type = "CHECK_VEHICLE", val taskRequest = UpdateTaskRequest(type = "CHECK_VEHICLE",
taskId = getCurrentOrder()?.taskId, taskId = getCurrentOrder()?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = "EXAMINE", currentState = "EXAMINE",
offlineMode = 0, offlineMode = 0,
operateTime = System.currentTimeMillis().toString(), operateTime = System.currentTimeMillis().toString(),
@ -197,8 +197,8 @@ class CheckVehicleVm : IServicingVm<CheckVehicleVm.Action, CheckVehicleVm.UiStat
LoadingManager.hideLoading() LoadingManager.hideLoading()
val taskRequest = UpdateTaskRequest(type = "CHECK_VEHICLE", val taskRequest = UpdateTaskRequest(type = "CHECK_VEHICLE",
taskId = getCurrentOrder()?.taskId, taskId = getCurrentOrder()?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = "EXAMINE", currentState = "EXAMINE",
offlineMode = 0, offlineMode = 0,
operateTime = System.currentTimeMillis().toString(), operateTime = System.currentTimeMillis().toString(),

View File

@ -42,7 +42,6 @@ fun DeparturePhotoScreen(vm : DeparturePhotoVm = viewModel()) {
if (uiState.value.goNextPage != null) { if (uiState.value.goNextPage != null) {
goNextPage(uiState.value.goNextPage?.nextState, context) goNextPage(uiState.value.goNextPage?.nextState, context)
context.finish()
} }
if (uiState.value.isGoNextPageDialog == true) { if (uiState.value.isGoNextPageDialog == true) {

View File

@ -91,8 +91,8 @@ class DeparturePhotoVm : IServicingVm<DeparturePhotoVm.Action, DeparturePhotoVm.
LoadingManager.hideLoading() LoadingManager.hideLoading()
val taskRequest = UpdateTaskRequest(type = "START", val taskRequest = UpdateTaskRequest(type = "START",
taskId = getCurrentOrder()?.taskId, taskId = getCurrentOrder()?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = GlobalData.currentOrder?.taskState, currentState = GlobalData.currentOrder?.taskState,
offlineMode = 0, offlineMode = 0,
operateTime = System.currentTimeMillis().toString(), operateTime = System.currentTimeMillis().toString(),

View File

@ -42,7 +42,6 @@ fun DestinationPhotoScreen(vm: DestinationPhotoVm = viewModel()) {
if (uiState.value.goNextPage != null) { if (uiState.value.goNextPage != null) {
goNextPage(uiState.value.goNextPage?.nextState, context) goNextPage(uiState.value.goNextPage?.nextState, context)
context.finish()
} }
if (uiState.value.isGoNextPageDialog == true) { if (uiState.value.isGoNextPageDialog == true) {

View File

@ -103,9 +103,9 @@ class DestinationPhotoVm : IServicingVm<DestinationPhotoVm.Action, DestinationPh
private fun doUploadOfflineTask(it: AMapLocation?, tempPhotoList: ArrayList<String?>) { private fun doUploadOfflineTask(it: AMapLocation?, tempPhotoList: ArrayList<String?>) {
val taskRequest = UpdateTaskRequest(type = "DEST_PHOTO", val taskRequest = UpdateTaskRequest(type = "DEST_PHOTO",
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
flowType = GlobalData.currentOrder?.flowType, flowType = GlobalData.currentOrder?.flowType,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = "DESTPHOTO", currentState = "DESTPHOTO",
offlineMode = 0, offlineMode = 0,
operateTime = System.currentTimeMillis().toString(), operateTime = System.currentTimeMillis().toString(),
@ -198,9 +198,9 @@ class DestinationPhotoVm : IServicingVm<DestinationPhotoVm.Action, DestinationPh
LoadingManager.hideLoading() LoadingManager.hideLoading()
val taskRequest = UpdateTaskRequest(type = "DEST_PHOTO", val taskRequest = UpdateTaskRequest(type = "DEST_PHOTO",
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
flowType = GlobalData.currentOrder?.flowType, flowType = GlobalData.currentOrder?.flowType,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = "DESTPHOTO", currentState = "DESTPHOTO",
offlineMode = 0, offlineMode = 0,
operateTime = System.currentTimeMillis().toString(), operateTime = System.currentTimeMillis().toString(),

View File

@ -87,7 +87,6 @@ fun EleSignCheckScreen(vm: EleSignCheckVm = viewModel()) {
if (uiState.value.goNextPage != null) { if (uiState.value.goNextPage != null) {
uiState.value.orderInfo?.goStatusPage(context) uiState.value.orderInfo?.goStatusPage(context)
context.finish()
} }
if (uiState.value.showCallPhoneDialog == true) { if (uiState.value.showCallPhoneDialog == true) {

View File

@ -107,7 +107,6 @@ fun GoAccidentSiteScreen(vm : GoAccidentSiteVm = viewModel()) {
if (uiState.value.goNextPage != null) { if (uiState.value.goNextPage != null) {
goNextPage(uiState.value.goNextPage?.nextState, context) goNextPage(uiState.value.goNextPage?.nextState, context)
context.finish()
} }
if (uiState.value.isGoNextPageDialog == true) { if (uiState.value.isGoNextPageDialog == true) {

View File

@ -59,8 +59,8 @@ class GoAccidentSiteVm : IServicingVm<GoAccidentSiteVm.Action, GoAccidentSiteVm.
LoadingManager.hideLoading() LoadingManager.hideLoading()
val temp = taskRequest ?: UpdateTaskRequest(type = "VERIFY", val temp = taskRequest ?: UpdateTaskRequest(type = "VERIFY",
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = GlobalData.currentOrder?.taskState, currentState = GlobalData.currentOrder?.taskState,
offlineMode = 0, offlineMode = 0,
operateTime = System.currentTimeMillis().toString(), operateTime = System.currentTimeMillis().toString(),
@ -97,8 +97,8 @@ class GoAccidentSiteVm : IServicingVm<GoAccidentSiteVm.Action, GoAccidentSiteVm.
LoadingManager.hideLoading() LoadingManager.hideLoading()
val taskRequest = UpdateTaskRequest(type = "VERIFY", val taskRequest = UpdateTaskRequest(type = "VERIFY",
taskId = getCurrentOrder()?.taskId, taskId = getCurrentOrder()?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = getCurrentOrder()?.taskState, currentState = getCurrentOrder()?.taskState,
offlineMode = 0, offlineMode = 0,
operateTime = System.currentTimeMillis().toString(), operateTime = System.currentTimeMillis().toString(),

View File

@ -39,7 +39,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -131,7 +130,6 @@ fun GoToDestinationScreen(vm: GoToDestinationVm = viewModel()) {
// 对话框处理 // 对话框处理
if (uiState.value.goNextPage != null) { if (uiState.value.goNextPage != null) {
goNextPage(uiState.value.goNextPage?.nextState, context) goNextPage(uiState.value.goNextPage?.nextState, context)
context.finish()
} }
if (uiState.value.isGoNextPageDialog == true) { if (uiState.value.isGoNextPageDialog == true) {

View File

@ -60,8 +60,8 @@ class GoToDestinationVm : IServicingVm<GoToDestinationVm.Action, GoToDestination
val temp = taskRequest ?: UpdateTaskRequest( val temp = taskRequest ?: UpdateTaskRequest(
type = "ARRIVE_DEST", type = "ARRIVE_DEST",
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
flowType = GlobalData.currentOrder?.flowType, flowType = GlobalData.currentOrder?.flowType,
currentState = GlobalData.currentOrder?.taskState, currentState = GlobalData.currentOrder?.taskState,
offlineMode = 0, offlineMode = 0,
@ -102,8 +102,8 @@ class GoToDestinationVm : IServicingVm<GoToDestinationVm.Action, GoToDestination
val taskRequest = UpdateTaskRequest( val taskRequest = UpdateTaskRequest(
type = "ARRIVE_DEST", type = "ARRIVE_DEST",
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
flowType = GlobalData.currentOrder?.flowType, flowType = GlobalData.currentOrder?.flowType,
currentState = GlobalData.currentOrder?.taskState, currentState = GlobalData.currentOrder?.taskState,
offlineMode = 0, offlineMode = 0,

View File

@ -34,7 +34,6 @@ fun InOperationScreen(vm: InOperationVm = viewModel()) {
if (uiState.value.goNextPage != null) { if (uiState.value.goNextPage != null) {
goNextPage(uiState.value.goNextPage?.nextState, context) goNextPage(uiState.value.goNextPage?.nextState, context)
context.finish()
} }
if (uiState.value.isGoNextPageDialog == true) { if (uiState.value.isGoNextPageDialog == true) {

View File

@ -104,9 +104,9 @@ class InOperationVm : IServicingVm<InOperationVm.Action, InOperationVm.UiState>(
private fun doUploadOfflineTask(it: AMapLocation?, tempPhotoList: ArrayList<String?>) { private fun doUploadOfflineTask(it: AMapLocation?, tempPhotoList: ArrayList<String?>) {
val taskRequest = UpdateTaskRequest(type = "OPERATION", val taskRequest = UpdateTaskRequest(type = "OPERATION",
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
flowType = GlobalData.currentOrder?.flowType, flowType = GlobalData.currentOrder?.flowType,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = "OPERATION", currentState = "OPERATION",
offlineMode = 0, offlineMode = 0,
operateTime = System.currentTimeMillis().toString(), operateTime = System.currentTimeMillis().toString(),
@ -202,9 +202,9 @@ class InOperationVm : IServicingVm<InOperationVm.Action, InOperationVm.UiState>(
LoadingManager.hideLoading() LoadingManager.hideLoading()
val taskRequest = UpdateTaskRequest(type = "OPERATION", val taskRequest = UpdateTaskRequest(type = "OPERATION",
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
flowType = GlobalData.currentOrder?.flowType, flowType = GlobalData.currentOrder?.flowType,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = "OPERATION", currentState = "OPERATION",
offlineMode = 0, offlineMode = 0,
operateTime = System.currentTimeMillis().toString(), operateTime = System.currentTimeMillis().toString(),

View File

@ -42,7 +42,6 @@ fun ChangeBatteryScreen(vm: ChangeBatteryVm = viewModel()) {
if (uiState.value.goNextPage != null) { if (uiState.value.goNextPage != null) {
uiState.value.orderInfo?.goStatusPage(context) uiState.value.orderInfo?.goStatusPage(context)
context.finish()
} }
Scaffold(topBar = { Scaffold(topBar = {

View File

@ -78,10 +78,8 @@ fun ConfirmEleScreen(vm : ConfirmEleVm = viewModel()) {
} }
} }
if (uiState.value.goNextPage != null) { if (uiState.value.goNextPage != null) {
goNextPage(uiState.value.goNextPage?.nextState, context) goNextPage(uiState.value.goNextPage?.nextState, context)
context.finish()
} }
if (uiState.value.isGoNextPageDialog == true) { if (uiState.value.isGoNextPageDialog == true) {

View File

@ -48,7 +48,6 @@ import com.za.base.view.CommonDialog
import com.za.base.view.HeadView import com.za.base.view.HeadView
import com.za.base.view.LoadingState import com.za.base.view.LoadingState
import com.za.common.log.LogUtil import com.za.common.log.LogUtil
import com.za.ext.finish
import com.za.ext.getEleOrderH5Url import com.za.ext.getEleOrderH5Url
import com.za.ext.goStatusPage import com.za.ext.goStatusPage
import com.za.servicing.R import com.za.servicing.R
@ -115,7 +114,6 @@ fun ConfirmH5SuccessScreen(vm : ConfirmH5SuccessVm = viewModel()) {
if (uiState.value.goNextPage == true) { if (uiState.value.goNextPage == true) {
uiState.value.orderInfo?.goStatusPage(context) uiState.value.orderInfo?.goStatusPage(context)
context.finish()
} }
if (uiState.value.showSignDialog != null) { if (uiState.value.showSignDialog != null) {

View File

@ -82,401 +82,339 @@ val primaryColor = Color(0xFF3B82F6)
val gradientColors = listOf(Color(0xFF3B82F6), Color(0xFF60A5FA)) val gradientColors = listOf(Color(0xFF3B82F6), Color(0xFF60A5FA))
class InputMoneyActivity : BaseActivity() { class InputMoneyActivity : BaseActivity() {
@Composable @Composable
override fun ContentView() { override fun ContentView() {
InputMoneyScreen(userOrderId = intent.getIntExtra("userOrderId", 0), taskId = intent.getIntExtra("taskId", 0)) InputMoneyScreen(userOrderId = intent.getIntExtra("userOrderId", 0),
} taskId = intent.getIntExtra("taskId", 0))
}
companion object { companion object {
fun goInputMoney(context: Context, userOrderId: Int, taskId: Int) { fun goInputMoney(context : Context, userOrderId : Int, taskId : Int) {
context.startActivity(Intent(context, InputMoneyActivity::class.java).apply { context.startActivity(Intent(context, InputMoneyActivity::class.java).apply {
putExtra("userOrderId", userOrderId) putExtra("userOrderId", userOrderId)
putExtra("taskId", taskId) putExtra("taskId", taskId)
}) })
} }
} }
} }
@Preview(showBackground = true) @Preview(showBackground = true)
@Composable @Composable
fun PreviewInputMoneyScreen() { fun PreviewInputMoneyScreen() {
InputMoneyScreen(userOrderId = 1, taskId = 1) InputMoneyScreen(userOrderId = 1, taskId = 1)
} }
@Composable @Composable
fun InputMoneyScreen(userOrderId: Int, taskId: Int, fun InputMoneyScreen(userOrderId : Int, taskId : Int, vm : InputMoneyVm = viewModel()) {
vm: InputMoneyVm = viewModel()) { val context = LocalContext.current
val context = LocalContext.current val uiState = vm.uiState.collectAsStateWithLifecycle()
val uiState = vm.uiState.collectAsStateWithLifecycle() var showSuccessDialog by remember { mutableStateOf(false) }
var showSuccessDialog by remember { mutableStateOf(false) }
val lifecycleOwner = LocalLifecycleOwner.current val lifecycleOwner = LocalLifecycleOwner.current
DisposableEffect(key1 = lifecycleOwner) { DisposableEffect(key1 = lifecycleOwner) {
val observer = LifecycleEventObserver { _, event -> val observer = LifecycleEventObserver { _, event ->
if (event == Lifecycle.Event.ON_RESUME) { if (event == Lifecycle.Event.ON_RESUME) {
vm.dispatch(action = InputMoneyVm.Action.Init(userOrderId, taskId)) vm.dispatch(action = InputMoneyVm.Action.Init(userOrderId, taskId))
} }
} }
lifecycleOwner.lifecycle.addObserver(observer) lifecycleOwner.lifecycle.addObserver(observer)
onDispose { onDispose {
lifecycleOwner.lifecycle.removeObserver(observer) lifecycleOwner.lifecycle.removeObserver(observer)
} }
} }
if (showSuccessDialog) { if (showSuccessDialog) {
SuccessDialog( SuccessDialog(amount = "${uiState.value.paymentInfoBean?.amount ?: 0.00}", onDismiss = {
amount = "${uiState.value.paymentInfoBean?.amount ?: 0.00}", showSuccessDialog = false
onDismiss = { context.finish()
showSuccessDialog = false })
context.finish() }
}
)
}
if (uiState.value.payState == 3) { if (uiState.value.payState == 3) {
CommonDialog(title = "收款成功", message = "收款成功", cancelEnable = false, CommonDialog(title = "收款成功", message = "收款成功", cancelEnable = false, confirm = {
confirm = { goNextPage(GlobalData.currentOrder?.taskState, context)
goNextPage(GlobalData.currentOrder?.taskState, context) }, dismiss = {
context.finish() goNextPage(GlobalData.currentOrder?.taskState, context)
}, dismiss = { })
goNextPage(GlobalData.currentOrder?.taskState, context) }
context.finish()
})
}
Scaffold( Scaffold(topBar = { HeadView(title = "客户收款", onBack = { context.finish() }) }, bottomBar = {
topBar = { HeadView(title = "客户收款", onBack = { context.finish() }) }, Surface(modifier = Modifier
bottomBar = { .fillMaxWidth()
Surface( .padding(16.dp),
modifier = Modifier tonalElevation = 8.dp,
.fillMaxWidth() shadowElevation = 8.dp,
.padding(16.dp), color = backgroundColor,
tonalElevation = 8.dp, shape = RoundedCornerShape(24.dp)) {
shadowElevation = 8.dp, Row(modifier = Modifier
color = backgroundColor, .fillMaxWidth()
shape = RoundedCornerShape(24.dp) .padding(16.dp),
) { horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Row( Button(onClick = {
modifier = Modifier goNextPage(GlobalData.currentOrder?.taskState, context)
.fillMaxWidth() },
.padding(16.dp), modifier = Modifier
horizontalArrangement = Arrangement.spacedBy(12.dp) .weight(1f)
) { .height(48.dp)
Button( .animateContentSize(),
onClick = { shape = RoundedCornerShape(24.dp),
goNextPage(GlobalData.currentOrder?.taskState, context) colors = ButtonDefaults.buttonColors(containerColor = Color(0xFF64748B),
context.finish() contentColor = Color.White),
}, elevation = ButtonDefaults.buttonElevation(4.dp),
modifier = Modifier interactionSource = remember { MutableInteractionSource() }) {
.weight(1f) Text("无须收款", fontSize = 12.sp, fontWeight = FontWeight.Medium)
.height(48.dp) }
.animateContentSize(),
shape = RoundedCornerShape(24.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xFF64748B),
contentColor = Color.White
),
elevation = ButtonDefaults.buttonElevation(4.dp),
interactionSource = remember { MutableInteractionSource() }
) {
Text("无须收款", fontSize = 12.sp, fontWeight = FontWeight.Medium)
}
Button( Button(onClick = {
onClick = { if (uiState.value.receiveMoney == null || uiState.value.receiveMoney == 0f) {
if (uiState.value.receiveMoney == null || uiState.value.receiveMoney == 0f) { ToastUtils.showLong("请输入收款金额")
ToastUtils.showLong("请输入收款金额") return@Button
return@Button }
} if (uiState.value.isOnSite == 2 && uiState.value.userPhone.isNullOrEmpty()) {
if (uiState.value.isOnSite == 2 && uiState.value.userPhone.isNullOrEmpty()) { ToastUtils.showLong("请输入客户手机号")
ToastUtils.showLong("请输入客户手机号") return@Button
return@Button }
} vm.dispatch(InputMoneyVm.Action.Save)
vm.dispatch(InputMoneyVm.Action.Save) },
}, modifier = Modifier
modifier = Modifier .fillMaxWidth()
.fillMaxWidth() .height(48.dp)
.height(48.dp) .weight(1f),
.weight(1f), shape = RoundedCornerShape(24.dp),
shape = RoundedCornerShape(24.dp), colors = ButtonDefaults.buttonColors(containerColor = primaryColor),
colors = ButtonDefaults.buttonColors( elevation = ButtonDefaults.buttonElevation(4.dp)) {
containerColor = primaryColor Text("发送短信链接".takeIf { uiState.value.isOnSite != 1 } ?: "生成收款二维码",
), fontSize = 12.sp,
elevation = ButtonDefaults.buttonElevation(4.dp) fontWeight = FontWeight.Medium)
) { }
Text("发送短信链接".takeIf { uiState.value.isOnSite != 1 } }
?: "生成收款二维码", fontSize = 12.sp, fontWeight = FontWeight.Medium) }
} }, containerColor = backgroundColor) {
} Column(modifier = Modifier
} .fillMaxSize()
}, .padding(it)
containerColor = backgroundColor .verticalScroll(rememberScrollState())
) { .padding(16.dp)) {
Column( Column(modifier = Modifier.fillMaxWidth(),
modifier = Modifier horizontalAlignment = Alignment.CenterHorizontally) {
.fillMaxSize() Spacer(modifier = Modifier.height(12.dp))
.padding(it) Text("收款金额",
.verticalScroll(rememberScrollState()) color = Color.Gray,
.padding(16.dp) fontSize = 18.sp,
) { fontWeight = FontWeight.Medium,
Column(modifier = Modifier.fillMaxWidth(), modifier = Modifier.padding(bottom = 16.dp))
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(modifier = Modifier.height(12.dp))
Text("收款金额",
color = Color.Gray,
fontSize = 18.sp,
fontWeight = FontWeight.Medium,
modifier = Modifier.padding(bottom = 16.dp)
)
OutlinedTextField( OutlinedTextField(value = uiState.value.receiveMoneyText ?: "",
value = uiState.value.receiveMoneyText ?: "", onValueChange = { newValue ->
onValueChange = { newValue -> vm.updateState(uiState.value.copy(receiveMoney = newValue.toFloatOrNull(),
vm.updateState(uiState.value.copy(receiveMoney = newValue.toFloatOrNull(), receiveMoneyText = newValue)) receiveMoneyText = newValue))
}, },
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),
prefix = { Text("¥") }, prefix = { Text("¥") },
shape = RoundedCornerShape(12.dp), shape = RoundedCornerShape(12.dp),
colors = OutlinedTextFieldDefaults.colors( colors = OutlinedTextFieldDefaults.colors(focusedBorderColor = primaryColor,
focusedBorderColor = primaryColor, unfocusedBorderColor = Color.Gray.copy(alpha = 0.5f),
unfocusedBorderColor = Color.Gray.copy(alpha = 0.5f), focusedLabelColor = primaryColor,
focusedLabelColor = primaryColor, unfocusedLabelColor = Color.Gray))
unfocusedLabelColor = Color.Gray }
)
)
}
Spacer(modifier = Modifier.height(15.dp)) Spacer(modifier = Modifier.height(15.dp)) // Action Buttons
// Action Buttons Row(modifier = Modifier.fillMaxWidth(),
Row( horizontalArrangement = Arrangement.spacedBy(16.dp)) {
modifier = Modifier.fillMaxWidth(), Row(modifier = if (uiState.value.isOnSite == 1) {
horizontalArrangement = Arrangement.spacedBy(16.dp) Modifier
) { .weight(1f)
Row( .background(brush = Brush.linearGradient(gradientColors),
modifier = if (uiState.value.isOnSite == 1) { shape = RoundedCornerShape(12.dp))
Modifier .padding(vertical = 16.dp)
.weight(1f) } else {
.background( Modifier
brush = Brush.linearGradient(gradientColors), .weight(1f)
shape = RoundedCornerShape(12.dp) .noDoubleClick { vm.dispatch(InputMoneyVm.Action.ChangeOnSite(1)) }
) .border(1.dp, Color.Gray.copy(alpha = 0.5f), RoundedCornerShape(12.dp))
.padding(vertical = 16.dp) .padding(vertical = 16.dp)
} else { },
Modifier horizontalArrangement = Arrangement.Center,
.weight(1f) verticalAlignment = Alignment.CenterVertically) {
.noDoubleClick { vm.dispatch(InputMoneyVm.Action.ChangeOnSite(1)) } if (uiState.value.isOnSite == 1) {
.border(1.dp, Color.Gray.copy(alpha = 0.5f), RoundedCornerShape(12.dp)) Icon(imageVector = Icons.Default.LocationOn,
.padding(vertical = 16.dp) contentDescription = null,
}, tint = Color.White)
horizontalArrangement = Arrangement.Center, Text(text = "在现场", color = Color.White)
verticalAlignment = Alignment.CenterVertically } else {
) { Icon(imageVector = Icons.Default.LocationOn,
if (uiState.value.isOnSite == 1) { contentDescription = null,
Icon(imageVector = Icons.Default.LocationOn, contentDescription = null, tint = Color.White) tint = Color.Gray)
Text(text = "在现场", color = Color.White) Text(text = "在现场", color = Color.Gray)
} else { }
Icon(imageVector = Icons.Default.LocationOn, contentDescription = null, tint = Color.Gray) }
Text(text = "在现场", color = Color.Gray)
}
}
Row( Row(modifier = if (uiState.value.isOnSite == 2) {
modifier = if (uiState.value.isOnSite == 2) { Modifier
Modifier .weight(1f)
.weight(1f) .background(color = primaryColor, shape = RoundedCornerShape(3.dp))
.background(color = primaryColor, shape = RoundedCornerShape(3.dp)) .padding(vertical = 15.dp)
.padding(vertical = 15.dp) } else {
} else { Modifier
Modifier .weight(1f)
.weight(1f) .noDoubleClick {
.noDoubleClick { vm.dispatch(InputMoneyVm.Action.ChangeOnSite(2))
vm.dispatch(InputMoneyVm.Action.ChangeOnSite(2)) }
} .border(1.dp, color = Color.Gray, shape = RoundedCornerShape(3.dp))
.border(1.dp, color = Color.Gray, shape = RoundedCornerShape(3.dp)) .padding(vertical = 15.dp)
.padding(vertical = 15.dp) }, horizontalArrangement = Arrangement.Center) {
}, if (uiState.value.isOnSite == 2) {
horizontalArrangement = Arrangement.Center Icon(imageVector = Icons.Default.Notifications,
) { contentDescription = null,
if (uiState.value.isOnSite == 2) { tint = Color.White)
Icon(imageVector = Icons.Default.Notifications, contentDescription = null, tint = Color.White) Text(text = "不在现场", color = Color.White)
Text(text = "不在现场", color = Color.White) } else {
} else { Icon(imageVector = Icons.Default.Notifications,
Icon(imageVector = Icons.Default.Notifications, contentDescription = null, tint = Color.Gray) contentDescription = null,
Text(text = "不在现场", color = Color.Gray) tint = Color.Gray)
} Text(text = "不在现场", color = Color.Gray)
} }
} }
}
AnimatedVisibility(visible = uiState.value.isOnSite == 1) { AnimatedVisibility(visible = uiState.value.isOnSite == 1) {
QRCodeSection(uiState.value.qrCode QRCodeSection(uiState.value.qrCode ?: "",
?: "", createPayment = { vm.dispatch(InputMoneyVm.Action.CreatePaymentInfo) }) createPayment = { vm.dispatch(InputMoneyVm.Action.CreatePaymentInfo) })
} }
AnimatedVisibility(visible = uiState.value.isOnSite == 2) { AnimatedVisibility(visible = uiState.value.isOnSite == 2) {
Box(modifier = Modifier Box(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 10.dp, vertical = 15.dp)) { .padding(horizontal = 10.dp, vertical = 15.dp)) {
OutlinedTextField( OutlinedTextField(value = uiState.value.userPhone ?: "",
value = uiState.value.userPhone ?: "", keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Phone),
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Phone), onValueChange = { vm.updateState(uiState.value.copy(userPhone = it)) },
onValueChange = { vm.updateState(uiState.value.copy(userPhone = it)) }, label = { Text("请输入客户手机号") },
label = { Text("请输入客户手机号") }, leadingIcon = {
leadingIcon = { Icon(imageVector = Icons.Rounded.Phone,
Icon( contentDescription = null,
imageVector = Icons.Rounded.Phone, tint = primaryColor)
contentDescription = null, },
tint = primaryColor modifier = Modifier.fillMaxWidth(),
) shape = RoundedCornerShape(12.dp),
}, colors = OutlinedTextFieldDefaults.colors(focusedBorderColor = primaryColor,
modifier = Modifier.fillMaxWidth(), unfocusedBorderColor = Color.Gray,
shape = RoundedCornerShape(12.dp), focusedLabelColor = primaryColor,
colors = OutlinedTextFieldDefaults.colors( unfocusedLabelColor = Color.Gray),
focusedBorderColor = primaryColor, singleLine = true)
unfocusedBorderColor = Color.Gray, }
focusedLabelColor = primaryColor, }
unfocusedLabelColor = Color.Gray),
singleLine = true
)
}
}
if (uiState.value.payState == 1) { if (uiState.value.payState == 1) {
Column { Column {
Spacer(modifier = Modifier.height(15.dp)) Spacer(modifier = Modifier.height(15.dp))
CountdownRing { vm.updateState(uiState.value.copy(payState = 4, qrCode = null, qrCodeOutTime = true)) } CountdownRing {
} vm.updateState(uiState.value.copy(payState = 4,
} qrCode = null,
} qrCodeOutTime = true))
} }
}
}
}
}
} }
@Composable @Composable
private fun QRCodeSection(qrCode: String? = null, isOutTime: Boolean? = null, createPayment: () -> Unit = {}) { private fun QRCodeSection(qrCode : String? = null,
Column( isOutTime : Boolean? = null,
modifier = Modifier createPayment : () -> Unit = {}) {
.fillMaxWidth() Column(modifier = Modifier
.padding(12.dp), .fillMaxWidth()
horizontalAlignment = Alignment.CenterHorizontally .padding(12.dp),
) { horizontalAlignment = Alignment.CenterHorizontally) {
if (!qrCode.isNullOrEmpty()) { if (! qrCode.isNullOrEmpty()) {
Surface(modifier = Modifier Surface(modifier = Modifier
.size(200.dp) .size(200.dp)
.border(2.dp, primaryColor.copy(alpha = 0.1f), RoundedCornerShape(16.dp)), .border(2.dp, primaryColor.copy(alpha = 0.1f), RoundedCornerShape(16.dp)),
color = backgroundColor, color = backgroundColor,
shape = RoundedCornerShape(16.dp) shape = RoundedCornerShape(16.dp)) {
) { Box(modifier = Modifier
Box(modifier = Modifier .fillMaxSize()
.fillMaxSize() .padding(16.dp),
.padding(16.dp), contentAlignment = Alignment.Center) {
contentAlignment = Alignment.Center AsyncImage(model = qrCode,
) { contentDescription = null,
AsyncImage( modifier = Modifier.fillMaxSize(0.8f))
model = qrCode, }
contentDescription = null, }
modifier = Modifier.fillMaxSize(0.8f) Spacer(modifier = Modifier.height(16.dp))
) Text("请顾客扫码支付",
} color = Color.Gray,
} fontSize = 16.sp,
Spacer(modifier = Modifier.height(16.dp)) fontWeight = FontWeight.Medium)
Text( }
"请顾客扫码支付",
color = Color.Gray,
fontSize = 16.sp,
fontWeight = FontWeight.Medium
)
}
if (isOutTime == true) { if (isOutTime == true) {
LoadError(message = "收款码失效", onRetry = { createPayment() }) LoadError(message = "收款码失效", onRetry = { createPayment() })
} }
} }
} }
@Composable @Composable
private fun CountdownRing(outTime: () -> Unit) { private fun CountdownRing(outTime : () -> Unit) {
var countdown by remember { mutableIntStateOf(5 * 60) } var countdown by remember { mutableIntStateOf(5 * 60) }
val progress by animateFloatAsState( val progress by animateFloatAsState(targetValue = (countdown / 5 * 60) * 360f,
targetValue = (countdown / 5 * 60) * 360f, animationSpec = remember { androidx.compose.animation.core.tween(1000) })
animationSpec = remember { androidx.compose.animation.core.tween(1000) }
)
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
while (countdown > 0) { while (countdown > 0) {
delay(1000) delay(1000)
countdown-- countdown --
if (countdown == 0) { if (countdown == 0) {
outTime() outTime()
} }
} }
} }
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
Box(modifier = Modifier.size(50.dp), contentAlignment = Alignment.Center) { Box(modifier = Modifier.size(50.dp), contentAlignment = Alignment.Center) {
Canvas(modifier = Modifier.fillMaxSize()) { Canvas(modifier = Modifier.fillMaxSize()) {
drawArc( drawArc(brush = Brush.sweepGradient(0f to primaryColor, 1f to Color.LightGray),
brush = Brush.sweepGradient( startAngle = - 90f,
0f to primaryColor, sweepAngle = progress,
1f to Color.LightGray useCenter = false,
), style = Stroke(width = 8.dp.toPx(), cap = StrokeCap.Round))
startAngle = -90f, }
sweepAngle = progress, Surface(color = Color.White, shape = CircleShape, modifier = Modifier.size(50.dp)) {}
useCenter = false, Text(text = countdown.toString(),
style = Stroke(width = 8.dp.toPx(), cap = StrokeCap.Round) fontSize = 20.sp,
) color = black90,
} fontWeight = FontWeight.Medium)
Surface( }
color = Color.White, }
shape = CircleShape,
modifier = Modifier.size(50.dp)) {}
Text(
text = countdown.toString(),
fontSize = 20.sp,
color = black90,
fontWeight = FontWeight.Medium
)
}
}
} }
@Composable @Composable
private fun SuccessDialog(amount: String, onDismiss: () -> Unit) { private fun SuccessDialog(amount : String, onDismiss : () -> Unit) {
Dialog(onDismissRequest = onDismiss) { Dialog(onDismissRequest = onDismiss) {
Surface( Surface(shape = RoundedCornerShape(16.dp), color = Color.White) {
shape = RoundedCornerShape(16.dp), Column(modifier = Modifier.padding(24.dp),
color = Color.White horizontalAlignment = Alignment.CenterHorizontally) {
) { Box(modifier = Modifier
Column( .size(64.dp)
modifier = Modifier.padding(24.dp), .background(primaryColor.copy(alpha = 0.1f), CircleShape)
horizontalAlignment = Alignment.CenterHorizontally .clip(CircleShape),
) { contentAlignment = Alignment.Center) {
Box( Icon(Icons.Default.Check,
modifier = Modifier contentDescription = null,
.size(64.dp) tint = primaryColor,
.background(primaryColor.copy(alpha = 0.1f), CircleShape) modifier = Modifier.size(32.dp))
.clip(CircleShape), }
contentAlignment = Alignment.Center Spacer(modifier = Modifier.height(16.dp))
) { Text("收款成功", fontWeight = FontWeight.Medium, fontSize = 18.sp)
Icon( Text("已收款 ¥$amount", color = Color.Gray, fontSize = 14.sp)
Icons.Default.Check, Spacer(modifier = Modifier.height(16.dp))
contentDescription = null, Button(onClick = onDismiss, modifier = Modifier.fillMaxWidth()) {
tint = primaryColor, Text("完成")
modifier = Modifier.size(32.dp) }
) }
} }
Spacer(modifier = Modifier.height(16.dp)) }
Text("收款成功", fontWeight = FontWeight.Medium, fontSize = 18.sp)
Text("已收款 ¥$amount", color = Color.Gray, fontSize = 14.sp)
Spacer(modifier = Modifier.height(16.dp))
Button(
onClick = onDismiss,
modifier = Modifier.fillMaxWidth()
) {
Text("完成")
}
}
}
}
} }

View File

@ -133,7 +133,7 @@ fun BaseFeeView(flowType : Int,
.fillMaxWidth() .fillMaxWidth()
.padding(vertical = 5.dp), .padding(vertical = 5.dp),
color = black5) color = black5)
if (GlobalData.driverInfo?.supplierType == Const.CHILD_COMPANY) { if (GlobalData.driverInfoBean?.supplierType == Const.CHILD_COMPANY) {
Spacer(modifier = Modifier.height(5.dp)) Spacer(modifier = Modifier.height(5.dp))
OrderConfirmEditView(title = "起步价", value = "${startPrice ?: ""}", onValueChanged = { OrderConfirmEditView(title = "起步价", value = "${startPrice ?: ""}", onValueChanged = {
dispatch(OrderConfirmVm.Action.UpdateStartPrice(it.toIntOrNull() ?: 0)) dispatch(OrderConfirmVm.Action.UpdateStartPrice(it.toIntOrNull() ?: 0))
@ -204,7 +204,7 @@ fun AuxiliaryFeeView(dilemmaFee : Int?,
color = black5, color = black5,
thickness = 0.5.dp) thickness = 0.5.dp)
if (GlobalData.driverInfo?.supplierType == Const.CHILD_COMPANY) { if (GlobalData.driverInfoBean?.supplierType == Const.CHILD_COMPANY) {
Column(modifier = Modifier Column(modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(bottom = 12.dp), .padding(bottom = 12.dp),

View File

@ -82,7 +82,7 @@ class OrderConfirmVm : IServicingVm<OrderConfirmVm.Action, OrderConfirmVm.UiStat
} }
} }
if (GlobalData.driverInfo?.supplierType != Const.CHILD_COMPANY) { if (GlobalData.driverInfoBean?.supplierType != Const.CHILD_COMPANY) {
// AB段不为0 BC段拖车流程不为0 // AB段不为0 BC段拖车流程不为0
if (uiState.value.abKm == null || uiState.value.abKm == 0) { if (uiState.value.abKm == null || uiState.value.abKm == 0) {
@ -118,11 +118,11 @@ class OrderConfirmVm : IServicingVm<OrderConfirmVm.Action, OrderConfirmVm.UiStat
LoadingManager.hideLoading() LoadingManager.hideLoading()
val orderConfirmTaskRequest = UpdateOrderConfirmTaskRequest(type = "SETTLEMENT", val orderConfirmTaskRequest = UpdateOrderConfirmTaskRequest(type = "SETTLEMENT",
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = uiState.value.orderInfo?.taskState, currentState = uiState.value.orderInfo?.taskState,
operateTime = System.currentTimeMillis().toString(), operateTime = System.currentTimeMillis().toString(),
supplierType = GlobalData.driverInfo?.supplierType, supplierType = GlobalData.driverInfoBean?.supplierType,
settleType = GlobalData.currentOrder?.settleType, settleType = GlobalData.currentOrder?.settleType,
carryMileage = uiState.value.bcKm, carryMileage = uiState.value.bcKm,
startMileage = uiState.value.abKm, startMileage = uiState.value.abKm,
@ -130,10 +130,10 @@ class OrderConfirmVm : IServicingVm<OrderConfirmVm.Action, OrderConfirmVm.UiStat
carryRoadFee = uiState.value.bcRoadFee, carryRoadFee = uiState.value.bcRoadFee,
dilemmaFee = uiState.value.dilemmaFee, dilemmaFee = uiState.value.dilemmaFee,
basementFee = uiState.value.basementFee, basementFee = uiState.value.basementFee,
basePrice = if (GlobalData.driverInfo?.supplierType == Const.CHILD_COMPANY) { basePrice = if (GlobalData.driverInfoBean?.supplierType == Const.CHILD_COMPANY) {
computerBaseFee() computerBaseFee()
} else null, } else null,
assistFee = if (GlobalData.driverInfo?.supplierType == Const.CHILD_COMPANY) { assistFee = if (GlobalData.driverInfoBean?.supplierType == Const.CHILD_COMPANY) {
computerAssistantsFee() computerAssistantsFee()
} else null, } else null,
totalFee = computerTotalFee(), totalFee = computerTotalFee(),

View File

@ -125,10 +125,8 @@ fun ReceiveMoneyScreen(userOrderId: Int,
CommonDialog(title = "收款成功", message = "收款成功", cancelEnable = false, CommonDialog(title = "收款成功", message = "收款成功", cancelEnable = false,
confirm = { confirm = {
goNextPage(GlobalData.currentOrder?.taskState, context) goNextPage(GlobalData.currentOrder?.taskState, context)
context.finish()
}, dismiss = { }, dismiss = {
goNextPage(GlobalData.currentOrder?.taskState, context) goNextPage(GlobalData.currentOrder?.taskState, context)
context.finish()
}) })
} }

View File

@ -164,8 +164,8 @@ class OrderGiveUpVm : BaseVm<OrderGiveUpVm.Action, OrderGiveUpVm.UiState>() {
LoadingManager.hideLoading() LoadingManager.hideLoading()
val taskRequest = GiveUpTaskRequest( val taskRequest = GiveUpTaskRequest(
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
lat = it.latitude, lat = it.latitude,
address = it.address, address = it.address,
pushGiveUpFlag = 1, pushGiveUpFlag = 1,
@ -215,8 +215,8 @@ class OrderGiveUpVm : BaseVm<OrderGiveUpVm.Action, OrderGiveUpVm.UiState>() {
LoadingManager.hideLoading() LoadingManager.hideLoading()
val taskRequest = GiveUpTaskRequest( val taskRequest = GiveUpTaskRequest(
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
lat = it.latitude, lat = it.latitude,
address = it.address, address = it.address,
lng = it.longitude, lng = it.longitude,

View File

@ -80,7 +80,6 @@ fun VerifyOrderScreen(vm: VerifyOrderVm = viewModel()) {
if (uiState.value.goNextPage != null) { if (uiState.value.goNextPage != null) {
goNextPage(uiState.value.goNextPage?.nextState, context) goNextPage(uiState.value.goNextPage?.nextState, context)
context.finish()
} }
if (uiState.value.showCallPhoneDialog == true) { if (uiState.value.showCallPhoneDialog == true) {

View File

@ -59,8 +59,8 @@ class VerifyOrderVm : IServicingVm<VerifyOrderVm.Action, VerifyOrderVm.UiState>(
val temp = UpdateTaskRequest( val temp = UpdateTaskRequest(
type = "VERIFY", type = "VERIFY",
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = GlobalData.currentOrder?.taskState, currentState = GlobalData.currentOrder?.taskState,
offlineMode = 0, offlineMode = 0,
newCarCode = if (uiState.value.orderInfo?.verifyType == 5) { newCarCode = if (uiState.value.orderInfo?.verifyType == 5) {
@ -113,8 +113,8 @@ class VerifyOrderVm : IServicingVm<VerifyOrderVm.Action, VerifyOrderVm.UiState>(
val taskRequest = UpdateTaskRequest( val taskRequest = UpdateTaskRequest(
type = "VERIFY", type = "VERIFY",
taskId = GlobalData.currentOrder?.taskId, taskId = GlobalData.currentOrder?.taskId,
userId = GlobalData.driverInfo?.userId, userId = GlobalData.driverInfoBean?.userId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
currentState = GlobalData.currentOrder?.taskState, currentState = GlobalData.currentOrder?.taskState,
offlineMode = 0, offlineMode = 0,
newCarCode = if (uiState.value.orderInfo?.verifyType == 5) { newCarCode = if (uiState.value.orderInfo?.verifyType == 5) {

View File

@ -115,7 +115,6 @@ fun WaitToStartScreen(vm: WaitToStartVm = viewModel()) {
if (uiState.value.goNextPage != null) { if (uiState.value.goNextPage != null) {
goNextPage(uiState.value.goNextPage?.nextState, context) goNextPage(uiState.value.goNextPage?.nextState, context)
context.finish()
} }
if (uiState.value.isGoNextPageDialog == true) { if (uiState.value.isGoNextPageDialog == true) {
@ -188,7 +187,7 @@ fun WaitToStartScreen(vm: WaitToStartVm = viewModel()) {
Text( Text(
text = if (uiState.value.remainingDistance > 0) text = if (uiState.value.remainingDistance > 0)
"总里程: %.1fkm".format(uiState.value.remainingDistance / 1000f) "距离救援地: %.1fkm".format(uiState.value.remainingDistance / 1000f)
else else
"计算中...", "计算中...",
color = Color(0xFFFF4D4F), color = Color(0xFFFF4D4F),

View File

@ -30,244 +30,211 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale
import java.util.Calendar import java.util.Calendar
import java.util.Locale
class WaitToStartVm : IServicingVm<WaitToStartVm.Action, WaitToStartVm.UiState>() { class WaitToStartVm : IServicingVm<WaitToStartVm.Action, WaitToStartVm.UiState>() {
private val _uiState = MutableStateFlow(UiState()) private val _uiState = MutableStateFlow(UiState())
val uiState get() = _uiState val uiState get() = _uiState
override fun updateState(uiState: UiState) { override fun updateState(uiState : UiState) {
_uiState.value = uiState _uiState.value = uiState
} }
override fun dispatch(action: Action) { override fun dispatch(action : Action) {
when (action) { when (action) {
is Action.Init -> init() is Action.Init -> init()
is Action.UpdateTask -> updateTask() is Action.UpdateTask -> updateTask()
is Action.UpdateState -> updateState(action.uiState) is Action.UpdateState -> updateState(action.uiState)
is Action.StartTimer -> startTimer() is Action.StartTimer -> startTimer()
is Action.UpdateTimer -> updateTimer() is Action.UpdateTimer -> updateTimer()
} }
} }
private fun updateTask() { private fun updateTask() {
LoadingManager.showLoading() LoadingManager.showLoading()
ZdLocationManager.getSingleLocation(success = { ZdLocationManager.getSingleLocation(success = {
LoadingManager.hideLoading() LoadingManager.hideLoading()
val taskRequest = UpdateTaskRequest( val taskRequest = UpdateTaskRequest(type = "START",
type = "START", taskId = getCurrentOrder()?.taskId,
taskId = getCurrentOrder()?.taskId, userId = GlobalData.driverInfoBean?.userId,
userId = GlobalData.driverInfo?.userId, vehicleId = GlobalData.driverInfoBean?.vehicleId,
vehicleId = GlobalData.vehicleInfo?.vehicleId, currentState = getCurrentOrder()?.taskState,
currentState = getCurrentOrder()?.taskState, offlineMode = 0,
offlineMode = 0, operateTime = System.currentTimeMillis().toString(),
operateTime = System.currentTimeMillis().toString(), lat = it.latitude,
lat = it.latitude, lng = it.longitude)
lng = it.longitude) doUploadTask(request = taskRequest)
doUploadTask(request = taskRequest) }, failed = {
}, failed = { LoadingManager.hideLoading()
LoadingManager.hideLoading() ToastUtils.showShort(it)
ToastUtils.showShort(it) })
}) }
}
private fun doUploadTask(request: UpdateTaskRequest) { private fun doUploadTask(request : UpdateTaskRequest) {
LoadingManager.showLoading() LoadingManager.showLoading()
CommonMethod.updateTask(request, success = { data -> CommonMethod.updateTask(request, success = { data ->
LoadingManager.hideLoading() LoadingManager.hideLoading()
updateOrder(getCurrentOrder()?.copy(taskState = data?.nextState)) updateOrder(getCurrentOrder()?.copy(taskState = data?.nextState))
updateState(uiState.value.copy(goNextPage = data, orderInfo = getCurrentOrder())) updateState(uiState.value.copy(goNextPage = data, orderInfo = getCurrentOrder()))
}, failed = { msg, _ -> }, failed = { msg, _ ->
LoadingManager.hideLoading() LoadingManager.hideLoading()
ToastUtils.showShort(msg) ToastUtils.showShort(msg)
LogUtil.print("$tag doUploadTask", "状态更新失败==${request.toJson()} msg==$msg") LogUtil.print("$tag doUploadTask", "状态更新失败==${request.toJson()} msg==$msg")
}) })
} }
private fun init() { private fun init() {
val order = getCurrentOrder() val order = getCurrentOrder()
updateState(uiState = uiState.value.copy(orderInfo = order)) updateState(uiState = uiState.value.copy(orderInfo = order))
buildMarkers(order) buildMarkers(order)
searchDrivingRoute(order) searchDrivingRoute(order)
dispatch(Action.StartTimer) dispatch(Action.StartTimer)
} }
private fun buildMarkers(orderInfo: OrderInfo?) { private fun buildMarkers(orderInfo : OrderInfo?) {
val markers = arrayListOf<MarkerOptions>() val markers = arrayListOf<MarkerOptions>()
// 添加救援地点标记 // 添加救援地点标记
if (orderInfo?.lat != null && orderInfo.lat != 0.0 && if (orderInfo?.lat != null && orderInfo.lat != 0.0 && orderInfo.lng != null && orderInfo.lng != 0.0) {
orderInfo.lng != null && orderInfo.lng != 0.0
) {
val startMarker = MarkerOptions() val startMarker = MarkerOptions().position(LatLng(orderInfo.lat !!, orderInfo.lng !!))
.position(LatLng(orderInfo.lat!!, orderInfo.lng!!)) .title(orderInfo.address).snippet("救援地点")
.title(orderInfo.address) .icon(BitmapDescriptorFactory.fromResource(R.mipmap.sv_rescuing_map))
.snippet("救援地点") .anchor(0.5f, 0.5f).zIndex(2f).visible(true)
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.sv_rescuing_map))
.anchor(0.5f, 0.5f)
.zIndex(2f)
.visible(true)
markers.add(startMarker) markers.add(startMarker)
} }
// 添加目的地标记 // 添加目的地标记
if (orderInfo?.distLat != null && orderInfo.distLat != 0.0 && if (orderInfo?.distLat != null && orderInfo.distLat != 0.0 && orderInfo.distLng != null && orderInfo.distLng != 0.0) {
orderInfo.distLng != null && orderInfo.distLng != 0.0
) {
val destMarker = MarkerOptions() val destMarker =
.position(LatLng(orderInfo.distLat!!, orderInfo.distLng!!)) MarkerOptions().position(LatLng(orderInfo.distLat !!, orderInfo.distLng !!))
.title(orderInfo.distAddress) .title(orderInfo.distAddress).snippet("目的地")
.snippet("目的地") .icon(BitmapDescriptorFactory.fromResource(R.mipmap.sv_dist_map))
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.sv_dist_map)) .anchor(0.5f, 0.5f).zIndex(2f).visible(true)
.anchor(0.5f, 0.5f)
.zIndex(2f)
.visible(true)
markers.add(destMarker) markers.add(destMarker)
} }
updateState(uiState.value.copy(markers = markers)) updateState(uiState.value.copy(markers = markers))
} }
private fun searchDrivingRoute(orderInfo: OrderInfo?) { private fun searchDrivingRoute(orderInfo : OrderInfo?) { // 如果没有当前位置,则不进行路径规划
// 如果没有当前位置,则不进行路径规划 if (GlobalData.currentLocation == null) return
if (GlobalData.currentLocation == null) return
val startPoint = LatLonPoint( val startPoint = LatLonPoint(GlobalData.currentLocation?.latitude ?: 0.0,
GlobalData.currentLocation?.latitude ?: 0.0, GlobalData.currentLocation?.longitude ?: 0.0)
GlobalData.currentLocation?.longitude ?: 0.0
)
// 确定终点:如果有目的地,否则用救援地点 // 获取救援地点坐标
val endPoint = when { val rescuePoint =
// 优先使用目的地 if (orderInfo?.lat != null && orderInfo.lat != 0.0 && orderInfo.lng != null && orderInfo.lng != 0.0) {
orderInfo?.distLat != null && orderInfo.distLat != 0.0 && LatLonPoint(orderInfo.lat !!, orderInfo.lng !!)
orderInfo.distLng != null && orderInfo.distLng != 0.0 -> { } else null
LatLonPoint(orderInfo.distLat!!, orderInfo.distLng!!)
}
// 其次使用救援地点
orderInfo?.lat != null && orderInfo.lat != 0.0 &&
orderInfo.lng != null && orderInfo.lng != 0.0 -> {
LatLonPoint(orderInfo.lat!!, orderInfo.lng!!)
}
else -> null // 如果没有救援地点,则不进行规划
} if (rescuePoint == null) {
LogUtil.print("searchDrivingRoute", "没有有效的终点")
return
}
if (endPoint == null) return // 使用 Application Context
RouteSearch(GlobalData.application).apply {
setRouteSearchListener(object : RouteSearch.OnRouteSearchListener {
override fun onDriveRouteSearched(result : DriveRouteResult?, errorCode : Int) {
if (errorCode == 1000 && result != null && result.paths.isNotEmpty()) {
val path = result.paths[0]
val points = path.steps.flatMap { step ->
step.polyline.map { LatLng(it.latitude, it.longitude) }
}
updateState(uiState.value.copy(routePoints = points))
} else {
LogUtil.print("searchDrivingRoute", "路径规划失败: errorCode=$errorCode")
}
}
val fromAndTo = RouteSearch.FromAndTo(startPoint, endPoint) override fun onBusRouteSearched(p0 : BusRouteResult?, p1 : Int) {}
val query = RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.DrivingDefault, null, null, "") override fun onWalkRouteSearched(p0 : WalkRouteResult?, p1 : Int) {}
override fun onRideRouteSearched(p0 : RideRouteResult?, p1 : Int) {}
})
// 使用 Application Context val fromAndTo = RouteSearch.FromAndTo(startPoint, rescuePoint)
RouteSearch(GlobalData.application).apply { val query =
setRouteSearchListener(object : RouteSearch.OnRouteSearchListener { RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.DrivingDefault, null, null, "")
override fun onDriveRouteSearched(result: DriveRouteResult?, errorCode: Int) { calculateDriveRouteAsyn(query)
if (errorCode == 1000 && result != null && result.paths.isNotEmpty()) { }
val path = result.paths[0] }
val points = path.steps.flatMap { step ->
step.polyline.map { LatLng(it.latitude, it.longitude) }
}
updateState(uiState.value.copy(routePoints = points))
} else {
LogUtil.print("searchDrivingRoute", "路径规划失败: errorCode=$errorCode")
}
}
override fun onBusRouteSearched(p0: BusRouteResult?, p1: Int) {} private var timerJob : Job? = null
override fun onWalkRouteSearched(p0: WalkRouteResult?, p1: Int) {}
override fun onRideRouteSearched(p0: RideRouteResult?, p1: Int) {}
})
calculateDriveRouteAsyn(query)
}
}
private var timerJob: Job? = null private fun startTimer() {
timerJob?.cancel()
timerJob = viewModelScope.launch {
while (isActive) { // 计算从当前位置到目标点的距离和到达时间
val (distance, arrivalTime) = calculateRemainingDistance()
_uiState.update {
it.copy(remainingDistance = distance, estimatedArrivalTime = arrivalTime)
}
delay(1000) // 每秒更新一次
}
}
}
private fun startTimer() { private fun calculateRemainingDistance() : Pair<Float, String> {
timerJob?.cancel() val currentLocation = GlobalData.currentLocation ?: return Pair(0f, "")
timerJob = viewModelScope.launch { val orderInfo = _uiState.value.orderInfo ?: return Pair(0f, "")
while (isActive) {
// 计算从当前位置到目标点的距离和到达时间
val (distance, arrivalTime) = calculateRemainingDistance()
_uiState.update {
it.copy(
remainingDistance = distance,
estimatedArrivalTime = arrivalTime
)
}
delay(1000) // 每秒更新一次
}
}
}
private fun calculateRemainingDistance(): Pair<Float, String> { // 计算到救援地点的距离
val currentLocation = GlobalData.currentLocation ?: return Pair(0f, "") val rescueDistance = if (orderInfo.lat != null && orderInfo.lng != null) {
val orderInfo = _uiState.value.orderInfo ?: return Pair(0f, "") AMapUtils.calculateLineDistance(LatLng(currentLocation.latitude,
currentLocation.longitude), LatLng(orderInfo.lat !!, orderInfo.lng !!))
} else 0f
// 计算到救援地点的距离 // 计算到目的地的距离
val rescueDistance = if (orderInfo.lat != null && orderInfo.lng != null) { val destDistance = if (orderInfo.distLat != null && orderInfo.distLng != null) {
AMapUtils.calculateLineDistance( AMapUtils.calculateLineDistance(LatLng(currentLocation.latitude,
LatLng(currentLocation.latitude, currentLocation.longitude), currentLocation.longitude), LatLng(orderInfo.distLat !!, orderInfo.distLng !!))
LatLng(orderInfo.lat!!, orderInfo.lng!!) } else 0f
)
} else 0f
// 计算到目的地的距离 // 取较短的距离
val destDistance = if (orderInfo.distLat != null && orderInfo.distLng != null) { val shortestDistance = minOf(rescueDistance.takeIf { it > 0f } ?: Float.MAX_VALUE,
AMapUtils.calculateLineDistance( destDistance.takeIf { it > 0f } ?: Float.MAX_VALUE)
LatLng(currentLocation.latitude, currentLocation.longitude),
LatLng(orderInfo.distLat!!, orderInfo.distLng!!)
)
} else 0f
// 取较短的距离 if (shortestDistance == Float.MAX_VALUE) {
val shortestDistance = minOf( return Pair(0f, "")
rescueDistance.takeIf { it > 0f } ?: Float.MAX_VALUE, }
destDistance.takeIf { it > 0f } ?: Float.MAX_VALUE
)
if (shortestDistance == Float.MAX_VALUE) { // 计算预计到达时间假设平均速度40km/h
return Pair(0f, "") val timeInSeconds = ((shortestDistance / 1000.0 * 60.0 / 40.0) * 60).toInt()
} val calendar = Calendar.getInstance()
calendar.add(Calendar.SECOND, timeInSeconds)
val arrivalTime = SimpleDateFormat("HH:mm", Locale.getDefault()).format(calendar.time)
// 计算预计到达时间假设平均速度40km/h return Pair(shortestDistance, arrivalTime)
val timeInSeconds = ((shortestDistance / 1000.0 * 60.0 / 40.0) * 60).toInt() }
val calendar = Calendar.getInstance()
calendar.add(Calendar.SECOND, timeInSeconds)
val arrivalTime = SimpleDateFormat("HH:mm", Locale.getDefault()).format(calendar.time)
return Pair(shortestDistance, arrivalTime) private fun updateTimer() { // 在这里处理倒计时更新逻辑
} }
private fun updateTimer() { override fun onCleared() {
// 在这里处理倒计时更新逻辑 super.onCleared()
} timerJob?.cancel()
}
override fun onCleared() { sealed class Action {
super.onCleared() data object Init : Action()
timerJob?.cancel() data object UpdateTask : Action()
} data class UpdateState(val uiState : UiState) : Action()
data object StartTimer : Action()
data object UpdateTimer : Action()
}
sealed class Action { data class UiState(val orderInfo : OrderInfo? = null,
data object Init : Action() val showCallPhoneDialog : Boolean? = false,
data object UpdateTask : Action() val markers : ArrayList<MarkerOptions>? = null,
data class UpdateState(val uiState: UiState) : Action() val goNextPage : UpdateTaskBean? = null,
data object StartTimer : Action() val isGoNextPageDialog : Boolean? = null,
data object UpdateTimer : Action() val routePoints : List<LatLng>? = null,
} val remainingDistance : Float = 0f,
val estimatedArrivalTime : String = "")
data class UiState(
val orderInfo: OrderInfo? = null,
val showCallPhoneDialog: Boolean? = false,
val markers: ArrayList<MarkerOptions>? = null,
val goNextPage: UpdateTaskBean? = null,
val isGoNextPageDialog: Boolean? = null,
val routePoints: List<LatLng>? = null,
val remainingDistance: Float = 0f,
val estimatedArrivalTime: String = ""
)
} }