| | |
| | | import android.app.Application |
| | | import androidx.lifecycle.MutableLiveData |
| | | import androidx.lifecycle.viewModelScope |
| | | import com.amap.api.navi.model.AMapNaviLocation |
| | | import com.amap.api.navi.model.NaviPoi |
| | | import com.xw.common.base.BaseViewModel |
| | | import com.xw.yunwei.model.CheckInMissionPointInfo |
| | | import com.xw.yunwei.model.CruiseCheckInOperationInfo |
| | | import com.xw.yunwei.net.WorkRepository |
| | | import com.xw.yunwei.ui.work.checkInMission.CruiseCheckInOperationActivity |
| | | import kotlinx.coroutines.delay |
| | | import kotlinx.coroutines.launch |
| | | import org.koin.core.component.inject |
| | | |
| | | class CruiseCheckInViewModel(application: Application) : BaseViewModel(application) { |
| | | val workRepository: WorkRepository by inject() |
| | | var id: String = "" |
| | | var points = MutableLiveData(listOf<CheckInMissionPointInfo>()) |
| | | var startPoint: NaviPoi? = null |
| | | var endPoint: NaviPoi? = null |
| | | var passPoints: List<NaviPoi>? = null |
| | | var type: Int = 0 |
| | | |
| | | //是否需要算路 |
| | | var needCalculateRideRoute = MutableLiveData(false) |
| | | |
| | | //是否在播放语音 |
| | | var hadPlayTTS = false; |
| | |
| | | //是否能够打卡 |
| | | val couldCheckIn = MutableLiveData(false) |
| | | |
| | | //是否显示过悬浮信息 |
| | | val hadShowFloatHistory = mutableListOf<String>() |
| | | //高德导航定位 |
| | | var aMapNaviLocation: AMapNaviLocation? = null |
| | | |
| | | //是否将要超时 |
| | | val willTimeout = MutableLiveData(false) |
| | | //操作打卡信息 |
| | | val checkInOperationInfo = MutableLiveData<CruiseCheckInOperationInfo>() |
| | | |
| | | //选中点 |
| | | val choicePoint = MutableLiveData<CheckInMissionPointInfo>() |
| | | |
| | | //获取下一个点 |
| | | fun getNextPoint(): CheckInMissionPointInfo? { |
| | |
| | | } |
| | | } |
| | | |
| | | //是否悬浮提示过 |
| | | fun hadFloatNotice(): Boolean { |
| | | return getNextPoint()?.let { |
| | | hadShowFloatHistory.contains(it.locationId) |
| | | } ?: true |
| | | } |
| | | |
| | | //检测超时 |
| | | fun checkOutTimeOut() { |
| | | viewModelScope.launch { |
| | | while (true) { |
| | | delay(1000) |
| | | val nextPoint = getNextPoint() ?: break |
| | | val now = System.currentTimeMillis() |
| | | if (nextPoint.needNoticeTimeout1) { |
| | | if (nextPoint.timeoutTimestamp1 == null) { |
| | | if (nextPoint.getLatestTimestamp() <= (now - 10 * 60 * 1000)) { |
| | | nextPoint.timeoutTimestamp1 = now |
| | | willTimeout.postValue(true) |
| | | continue |
| | | delay(5000) |
| | | aMapNaviLocation?.also { it -> |
| | | workRepository.uploadRealTimePosition(id, it.coord.latitude, it.coord.longitude) |
| | | ?.also { |
| | | checkInOperationInfo.postValue(it) |
| | | } |
| | | } else { |
| | | willTimeout.postValue(now - nextPoint.timeoutTimestamp1!! <= 3000) |
| | | continue |
| | | } |
| | | } |
| | | if (nextPoint.needNoticeTimeout2) { |
| | | if (nextPoint.timeoutTimestamp2 == null) { |
| | | if (nextPoint.getLatestTimestamp() <= (now - 3 * 60 * 1000)) { |
| | | nextPoint.timeoutTimestamp2 = now |
| | | willTimeout.postValue(true) |
| | | continue |
| | | } |
| | | } else { |
| | | willTimeout.postValue(now - nextPoint.timeoutTimestamp2!! <= 3000) |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | this.checkInResult = checkInResult |
| | | } |
| | | points.postValue((points.value ?: mutableListOf()).toMutableList()) |
| | | if (getNextPoint() == null) { |
| | | finish() |
| | | } |
| | | } |
| | | } |