package com.xw.yunwei.ui.user.mine.checkin
|
|
import android.os.Bundle
|
import androidx.appcompat.widget.AppCompatTextView
|
import com.amap.api.location.AMapLocation
|
import com.amap.api.maps.model.LatLng
|
import com.xw.common.CommonDialog
|
import com.xw.common.base.BaseActivity
|
import com.xw.common.utils.BindUtils.getResColor
|
import com.xw.common.utils.GpsHelper
|
import com.xw.common.utils.ToastUtilCommon
|
import com.xw.yunwei.BR
|
import com.xw.yunwei.R
|
import com.xw.yunwei.databinding.ActivityCheckInBinding
|
import com.xw.yunwei.ui.work.AMapFragment
|
|
/**
|
* 打卡
|
*/
|
class CheckInActivity : BaseActivity<ActivityCheckInBinding, CheckInVM>(), GpsHelper.OnMapLocation {
|
override fun getBindingVariable() = BR.viewModel
|
|
// var gpsHelper: GpsHelper? = null
|
val mapFrag: AMapFragment by lazy { AMapFragment(R.mipmap.ic_map_location_my, false) }
|
|
override fun myCreate(savedInstanceState: Bundle?) {
|
super.myCreate(savedInstanceState)
|
// gpsHelper = GpsHelper(
|
// this,
|
// this,
|
// isOnceLocation = true,
|
// isAutomatic = true,
|
// savedInstanceState = savedInstanceState
|
// )
|
// lifecycle.addObserver(gpsHelper!!)
|
showDialog("定位中...")
|
}
|
|
override fun init() {
|
super.init()
|
viewModel.enterType = intent.getIntExtra("enterType", 0).takeIf { it != 0 }
|
viewModel.clockModel.value = intent.getParcelableExtra("clockModel")
|
viewModel.locationCheck()
|
|
val transaction = supportFragmentManager.beginTransaction()
|
transaction.add(R.id.map_container, mapFrag)
|
transaction.commit()
|
|
mapFrag.locationChangeCallback = {
|
dismissDialog()
|
if (it == null) {
|
CommonDialog.showTipsDialog(
|
this@CheckInActivity,
|
"您未开启gps权限,无法获取当前定位,请打开后重新操作",
|
null
|
)
|
} else {
|
if (viewModel.pageType.value == 2) {
|
mapMarkRefresh()
|
} else {
|
viewModel.location = it
|
viewModel.locationCheck()
|
if (!viewModel.firstLocationStatus) {
|
viewModel.firstLocationStatus = true
|
}
|
}
|
}
|
}
|
}
|
|
override fun setListener() {
|
super.setListener()
|
binding.refreshLayout.setOnClickListener {
|
// gpsHelper?.startLocation()
|
ToastUtilCommon.show("刷新成功")
|
}
|
binding.viewDetail.setOnClickListener { // 加载地图
|
viewModel.pageType.value = 2
|
}
|
binding.clockIn.setOnClickListener {
|
if (binding.clockIn.isSelected) {
|
viewModel.clockIn()
|
}
|
}
|
binding.clockOut.setOnClickListener {
|
if (binding.clockOut.isSelected) {
|
viewModel.clockOut()
|
}
|
}
|
}
|
|
override fun setObservable() {
|
super.setObservable()
|
viewModel.pageType.observe(this) {
|
if (it == 2) {
|
mapMarkRefresh()
|
}
|
}
|
|
val setStatus: (AppCompatTextView, Int, Int, String) -> Unit = { tv, color, bg, text ->
|
tv.setTextColor(color)
|
tv.setBackgroundResource(bg)
|
tv.text = text
|
}
|
viewModel.clockModel.observe(this) {
|
it?.let {
|
val clockType = if (it.clockIn != true) 1 else 2
|
val isClock = if (clockType == 1) it.clockIn ?: false else it.clockOut ?: false
|
|
if (isClock) {
|
it.xpClockIn?.let {
|
when (it.clockInResult) { // 上班打卡结果 1 = 正常 2 = 迟到 3 = 缺卡
|
1 -> setStatus(
|
binding.clockIntStatus,
|
getResColor(com.xw.common.R.color.blue_5),
|
com.xw.common.R.color.blue_1,
|
"正常"
|
)
|
|
2 -> setStatus(
|
binding.clockIntStatus,
|
getResColor(com.xw.common.R.color.red_5),
|
com.xw.common.R.color.red_1,
|
"迟到"
|
)
|
|
3 -> setStatus(
|
binding.clockIntStatus,
|
getResColor(com.xw.common.R.color.red_5),
|
com.xw.common.R.color.red_1,
|
"缺卡"
|
)
|
|
}
|
when (it.clockOutResult) { // 上班打卡结果 1 = 正常 2 = 早退 3 = 缺卡
|
1 -> setStatus(
|
binding.clockOutStatus,
|
getResColor(com.xw.common.R.color.blue_5),
|
com.xw.common.R.color.blue_1,
|
"正常"
|
)
|
|
2 -> setStatus(
|
binding.clockOutStatus,
|
getResColor(com.xw.common.R.color.red_5),
|
com.xw.common.R.color.red_1,
|
"早退"
|
)
|
|
3 -> setStatus(
|
binding.clockOutStatus,
|
getResColor(com.xw.common.R.color.red_5),
|
com.xw.common.R.color.red_1,
|
"缺卡"
|
)
|
}
|
|
}
|
}
|
}
|
}
|
}
|
|
private fun mapMarkRefresh() {
|
val lat = viewModel.clockModel.value?.xpCheckLocation?.locationLat ?: 0.0
|
val lon = viewModel.clockModel.value?.xpCheckLocation?.locationLon ?: 0.0
|
if (lat == 0.0 || lon == 0.0) {
|
ToastUtilCommon.showError("打卡数据异常!")
|
} else {
|
// 绘制
|
if (mapFrag.polylines.isNotEmpty()) {
|
mapFrag.polylines.forEach { it.remove() }
|
mapFrag.polylines.clear()
|
}
|
|
viewModel.location?.let {
|
mapFrag.drawDottedLine(
|
listOf(
|
LatLng(it.latitude, it.longitude),
|
LatLng(lat, lon)
|
)
|
)
|
|
if (mapFrag.circles.isEmpty()){
|
mapFrag.moveCameraToArea(
|
LatLng(it.latitude, it.longitude),
|
LatLng(lat, lon)
|
)
|
}
|
}
|
|
if (mapFrag.circles.isEmpty()) {
|
mapFrag.drawCircle(
|
LatLng(lat, lon),
|
viewModel.clockModel.value?.xpCheckLocation?.locationRange ?: 0.0
|
)
|
}
|
if (mapFrag.customMarkers.isEmpty()) {
|
mapFrag.drawCustomMarker(LatLng(lat, lon), R.mipmap.ic_map_location_company, "1")
|
}
|
}
|
}
|
|
override fun location(pLocation: AMapLocation?) {
|
// 直接用地图的地位
|
}
|
|
override fun onBackPressedHandel() {
|
if (viewModel.pageType.value == 2) {
|
viewModel.pageType.value = 1
|
} else {
|
super.onBackPressedHandel()
|
}
|
}
|
}
|