diff --git a/FastBleLib/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties b/FastBleLib/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties index 787270e..54e2e3e 100644 --- a/FastBleLib/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +++ b/FastBleLib/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties @@ -1 +1 @@ -#Fri Dec 26 18:05:45 CST 2025 +#Wed Feb 04 14:33:32 CST 2026 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0aa0666..6e86bf7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -387,10 +387,6 @@ android:name=".ui.activity.device.wifi.EditWifiPowerZoneActivity" android:exported="false" android:screenOrientation="portrait" /> - (ActivityHomeV2Binding } mChangePetListDialogAdapter.apply { setData(mPetList, true) + (mFragments[2] as MapV3Fragment).showPetNameAndHead(mSelectPetPosition) if (isFirst) { isFirst = false setSelectPetPos(mSelectPetPosition) @@ -477,7 +478,6 @@ class HomeV2Activity : BaseActivity(ActivityHomeV2Binding } } } - (mFragments[2] as MapV3Fragment).showPetNameAndHead(mSelectPetPosition) } } diff --git a/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV2.kt b/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV2.kt deleted file mode 100644 index 61807dd..0000000 --- a/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV2.kt +++ /dev/null @@ -1,1016 +0,0 @@ -package com.abbidot.tracker.ui.activity.map - -import android.content.Intent -import android.graphics.Typeface -import android.view.View -import android.widget.RelativeLayout -import androidx.activity.viewModels -import androidx.core.view.isGone -import androidx.fragment.app.Fragment -import androidx.fragment.app.commit -import androidx.lifecycle.lifecycleScope -import com.abbidot.baselibrary.constant.ConState -import com.abbidot.baselibrary.constant.EventName -import com.abbidot.baselibrary.constant.MMKVKey -import com.abbidot.baselibrary.eventbus.XEventBus -import com.abbidot.baselibrary.list.BaseRecyclerAdapter -import com.abbidot.baselibrary.util.AppUtils -import com.abbidot.baselibrary.util.LogUtil -import com.abbidot.baselibrary.util.MMKVUtil -import com.abbidot.tracker.R -import com.abbidot.tracker.adapter.HomeMapDeviceMsgAdapter -import com.abbidot.tracker.adapter.HomeMapDeviceStateAdapter -import com.abbidot.tracker.base.BaseActivity -import com.abbidot.tracker.base.BaseDialog -import com.abbidot.tracker.bean.BleReportDataBean -import com.abbidot.tracker.bean.BleTrackDeviceBean -import com.abbidot.tracker.bean.DataBean -import com.abbidot.tracker.bean.HistoryDataBean -import com.abbidot.tracker.bean.LiveDataBean -import com.abbidot.tracker.bean.MapDeviceBean -import com.abbidot.tracker.bean.PetBean -import com.abbidot.tracker.bean.ReceiveDeviceData -import com.abbidot.tracker.constant.ConstantInt -import com.abbidot.tracker.constant.ConstantString -import com.abbidot.tracker.constant.GetResultCallback -import com.abbidot.tracker.databinding.ActivityLiveV2Binding -import com.abbidot.tracker.deprecated.ui.activity.vm.LedLightViewModel -import com.abbidot.tracker.dialog.CommonDialog1 -import com.abbidot.tracker.dialog.SelectMapTypeDialog -import com.abbidot.tracker.ui.DebugActivity -import com.abbidot.tracker.ui.common.map.HomeMapCommon -import com.abbidot.tracker.util.Util -import com.abbidot.tracker.util.ViewUtil -import com.abbidot.tracker.util.bluetooth.SRBleCmdUtil -import com.abbidot.tracker.util.bluetooth.SRBleUtil -import com.abbidot.tracker.vm.ConnectionDeviceViewModel -import com.abbidot.tracker.vm.CountDownTimerViewModel -import com.abbidot.tracker.vm.FencesMapViewModel -import com.abbidot.tracker.vm.FindBleDeviceViewModel -import com.abbidot.tracker.vm.MapLiveViewModel -import com.abbidot.tracker.vm.MapViewModel -import com.abbidot.tracker.widget.MapDeviceNetView -import com.clj.fastble.BleManager -import com.daimajia.androidanimations.library.Techniques -import com.daimajia.androidanimations.library.YoYo -import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import javax.inject.Inject - -@AndroidEntryPoint -class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding::inflate) { - - private val mFencesMapViewModel: FencesMapViewModel by viewModels() - private val mMapViewModel: MapViewModel by viewModels() - private val mFindBleDeviceViewModel: FindBleDeviceViewModel by viewModels() - private val mMapLiveViewModel: MapLiveViewModel by viewModels() - private val mLedLightViewModel: LedLightViewModel by viewModels() - private val mCountDownViewModel: CountDownTimerViewModel by viewModels() - private val mConDeviceViewModel: ConnectionDeviceViewModel by viewModels() - - private var mSelectMapTypeDialog: SelectMapTypeDialog? = null - - private lateinit var mDeviceStateList: MutableList - private lateinit var mDeviceStateAdapter: HomeMapDeviceStateAdapter - private lateinit var mDeviceMsgList: MutableList - private lateinit var mDeviceMsgAdapter: HomeMapDeviceMsgAdapter - - @Inject - lateinit var mHomeMapCommon: HomeMapCommon - private lateinit var mFragment: Fragment - - private var mMapDeviceBean: MapDeviceBean? = null - - //启动动画移动地图摄像机 - private var isMoveCamera = true - - //是否显示围栏 - private var isShowFence = true - - //地图类型,标准和卫星地图 - private var mMapType = ConstantInt.Type0 - private var mShowCenterLocation = ConstantInt.PetLocationType - - //是否是直播跳转 - private var isLiveJump = true - private var mLiveStatus = 1 - private var mPetBean: PetBean? = null - private var mTrackBleDevice: BleTrackDeviceBean? = null - - //直播是否开始 - private var isStartLive = false - - // private val mLiveStateTips = mutableListOf( -// R.string.txt_starting_live, R.string.txt_con_network, R.string.txt_gps_position -// ) - private var mStartLiveIndex = 0 - - //直播时间 分钟 - private var mLiveTime = 5 - private lateinit var mSpeedUnit: String - private lateinit var mDistanceUnit: String - - //是否打开了找设备的声音 - private var isOpenSound = false - - //设备Led灯开关 - private var isLedOpen = false - private var mRequestModeType = ConstantInt.Type1 - - override fun getTopBar() = null - - override fun initData() { - super.initData() - mSpeedUnit = Util.getMetricUnits(mContext, ConstantInt.Type2) - mDistanceUnit = Util.getMetricUnits(mContext, ConstantInt.Type3) - intent.extras?.apply { - isLiveJump = getBoolean(ConstantString.JumpActivity, true) - mPetBean = Util.getParcelableAdaptive(intent, ConstantString.Pet, PetBean::class.java) - } - - isShowFence = Util.getShowFenceSp() - - mViewBinding.apply { - ilLiveV2BluetoothFindDevice.ivMapLiveV2BleConState.setValue(0) - mFragment = mHomeMapCommon.getMapFragment( - mContext, miLiveV2MapAddressView, dnLiveV2MapNetView - ) { mapLoadOk() } - dnLiveV2MapNetView.setShowNetType(MapDeviceNetView.NO_NET_TYPE) - ViewUtil.instance.setMapSwitchLocationButtonImage( - ivMapLiveV2RefreshBtn, mShowCenterLocation - ) - ilLiveV2OperateLayout.tvLiveV2Speed.text = "--$mSpeedUnit" - ilLiveV2OperateLayout.tvLiveV2Distance.text = "--$mDistanceUnit" - llLiveV2MapTopPet.ivTopPetBtnSmall.setImageResource(R.drawable.icon_map_type) - lavLiveV2StateAnim.let { - it.setAnimation("lottie/loading_dog.json") - it.playAnimation() - } - - mDeviceStateList = mutableListOf() - mDeviceMsgList = mutableListOf() - mMapViewModel.addDeviceDefaultStateData(mContext, mDeviceStateList) - mDeviceStateAdapter = HomeMapDeviceStateAdapter(mContext, mDeviceStateList) - ViewUtil.instance.setRecyclerViewVerticalLinearLayout( - mContext, rvMapLiveV2DeviceState, mDeviceStateAdapter, bottom = 10 - ) - - mDeviceMsgAdapter = HomeMapDeviceMsgAdapter(mContext, mDeviceMsgList) - ViewUtil.instance.setRecyclerViewVerticalLinearLayout( - mContext, rvLiveV2MapDeviceMsg, mDeviceMsgAdapter, bottom = 10 - ) - - ilLiveV2BluetoothFindDevice.liveV2BluetoothSignal.setValue(0) - ilLiveV2BluetoothFindDevice.findBleDeviceRadoView.setValue(0) - - setOnClickListenerViews( - ilLiveV2OperateLayout.llLiveV2StopLive, - ivMapLiveV2RefreshBtn, - ivMapLiveV2BluetoothBtn, - ilLiveV2BluetoothFindDevice.btnLiveV2StopRadar, - llLiveV2MapTopPet.ivTopPetBtnSmall, - ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.root, - ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.cbDeviceLightSwitch, - ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.cbDeviceLightSwitch, - ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.root, - ilLiveV2BluetoothFindDevice.ivLiveV2FindDeviceSound, - ilLiveV2OperateLayout.btnLiveV2Issue, - ilMapLiveV2IssueLayout.tvCloseIssueBtn - ) - - supportFragmentManager.commit { - add(R.id.fc_live_v2_map_fragment, mFragment) - } - - mPetBean?.let { pet -> - if (!isLiveJump) { - findBleDevice(pet.macID) - llLiveV2StateLayout.visibility = View.GONE - } - - if (AppUtils.isDebug()) { - llLiveV2MapTopPet.homeDataPetHeadSmall.root.setOnLongClickListener { - goToDebugActivity(pet) - true - } - } - } - } - } - - /** - * 地图加载好了 - */ - private fun mapLoadOk() { - showPetNameAndHead() - } - - override fun liveDataObserve() { - mCountDownViewModel.mCountDownEndLiveData.observe(this) { - when (mStartLiveIndex) { -// 0 -> { -// mStartLiveIndex++ -// //显示Connecting to network 30秒 -// mViewBinding.tvLiveV2StateContent.setText(mLiveStateTips[mStartLiveIndex]) -// mCountDownViewModel.startCountDown(30) -// } -// -// 1 -> { -// mStartLiveIndex++ -// //显示GPS positioning -// mCountDownViewModel.startCountDown(3 * 60) -// mViewBinding.tvLiveV2StateContent.setText(mLiveStateTips[mStartLiveIndex]) -// } -// -// 2 -> { -// if (isStartLive) { -// mStartLiveIndex++ -// //显示Starting 5-min Live -// val str = String.format(getString(R.string.txt_start_min_live), mLiveTime) -// mViewBinding.tvLiveV2StateContent.text = str -// mCountDownViewModel.startCountDown(2) -// } else { -// //直播超时 -// mLiveStatus = -1 -// stopLive() -// } -// } -// - 2 -> { - mViewBinding.llLiveV2StateLayout.visibility = View.VISIBLE - mStartLiveIndex++ - //显示Starting 5-min Live - val str = String.format(getString(R.string.txt_start_min_live), "$mLiveTime") - mViewBinding.tvLiveV2StateContent.text = str - mCountDownViewModel.startCountDown(5) - } - - 3 -> mViewBinding.llLiveV2StateLayout.visibility = View.GONE - } - } - //获取当前宠物位置和围栏信息 - mMapViewModel.mMapDeviceLiveData.observe(this) { - dealRequestResult(it, object : GetResultCallback { - override fun onResult(any: Any) { - val data = it.getOrNull() - data?.apply { - mMapDeviceBean = data - setMapData(data) - mMapViewModel.setDeviceStateAndWarningData( - mContext, - mPetBean, - data, - mDeviceStateList, - mDeviceStateAdapter, - mDeviceMsgList, - mDeviceMsgAdapter, - mViewBinding.rvLiveV2MapDeviceMsg, - true - ) - } - } - - override fun onRequestError(exceptionCode: String?) { - LogUtil.e("LiveV2Activity获取当前宠物位置和围栏信息onRequestError,再次请求") - if (exceptionCode == mNetworkRequestsFailLimit) { - finish() - } else { - mPetBean?.apply { - //获取首页设备信息状态 - mMapViewModel.getMapDeviceStatus(deviceId, false) - } - } - } - }, showLoading = false) - } - - mMapLiveViewModel.mMapLiveStatusLiveData.observe(this) { - dealRequestResult(it, object : GetResultCallback { - override fun onResult(any: Any) { - mPetBean?.apply { -// SRBleUtil.instance.isConnectBleSendNotifyData(macID) - when (mLiveStatus) { - //直播超时 - -1 -> { - XEventBus.post(EventName.LiveOpenTimeOut) - finish() - } - //直播结束 - 0 -> { - mViewBinding.llLiveV2StateLayout.visibility = View.GONE -// showToast(R.string.txt_change_successful, true) - finish() - } - //直播开始 - else -> { - //直播开启后,就去获取直播轨迹 - if (!BleManager.getInstance().isConnected(macID)) { - mMapLiveViewModel.mGetPetLivePointTimeStamp = - System.currentTimeMillis() / 1000 - mMapLiveViewModel.getPetLivePoint(deviceId) - } - } - } - } - } - - override fun onRequestError(exceptionCode: String?) { - LogUtil.e("HomeV2Activity直播开启错误onRequestError,再次请求") - if (exceptionCode == mNetworkRequestsFailLimit) { - finish() - } else { - mPetBean?.apply { - mMapLiveViewModel.setupDeviceLiveStatus( - this@LiveActivityV2, deviceId, mLiveStatus, mRequestModeType - ) - } - } - } - }) - } - - //获取直播轨迹 - mMapLiveViewModel.mMapLiveLiveData.observe(this) { - mHomeMapCommon.startRefreshUserLocation() - dealRequestResult(it, object : GetResultCallback { - override fun onResult(any: Any) { - it.getOrNull()?.apply { - setTrackData(this) - } - } - }, isShowRequestErrorTip = false) - } - - //接收蓝牙连接状态 - XEventBus.observe(this, EventName.ConnectDeviceState) { trackBle: BleTrackDeviceBean -> - mPetBean?.apply { - if (trackBle.mac == macID && trackBle.conState != ConState.CONNECTED) { - mViewBinding.rvLiveV2MapDeviceMsg.visibility = View.GONE - } - } - mMapDeviceBean?.apply { - if (trackBle.mac == deviceMacId) { - updateConState(trackBle) - } - } - } - //搜索蓝牙的设备状态 - XEventBus.observe(this, EventName.ActionConDeviceState) { conState: Int -> - if (conState == ConState.DEVICE_NOT_FOUND) { - openNetLive(ConstantInt.Type2) - } - } - - mLedLightViewModel.mLedSwitchLiveData.observe(this) { - dealRequestResult(it, object : GetResultCallback { - override fun onResult(any: Any) { -// mViewBinding.cbLiveV2DeviceLightSwitch.isChecked = -// !mViewBinding.cbLiveV2DeviceLightSwitch.isChecked -// showToast(R.string.txt_please_wait) - } - }) - } - - //蓝牙上报的数据 - XEventBus.observe(this, EventName.BleReportData) { reportData: BleReportDataBean -> - mPetBean?.apply { - if (macID == reportData.mac) updateBleReportData(reportData) - } - } - - //接收发送指令后设备返回的数据 - XEventBus.observe(this, EventName.DeviceReceiveData) { receiveData: ReceiveDeviceData -> - mPetBean?.apply { - if (macID == receiveData.mac) { - val data = receiveData.data - parseData(data) - } - } - } - } - - - /** - * 跳转debug调试页面 - */ - private fun goToDebugActivity(petBean: PetBean) { - val intent = Intent(mContext, DebugActivity::class.java) - ArrayList().apply { - add(petBean) - intent.putParcelableArrayListExtra(ConstantString.Pet, this) - } - intent.putExtra(ConstantString.Index, 0) - startActivity(intent) - } - - /** - * 解析蓝牙返回的数据 - */ - private fun parseData(data: ByteArray?) { - if (null != data && data.isNotEmpty()) { - val data0 = SRBleCmdUtil.instance.byteToInt(data[0]) - val data1 = SRBleCmdUtil.instance.byteToInt(data[1]) - val data2 = SRBleCmdUtil.instance.byteToInt(data[2]) - if (data0 == 0x06 && data1 == 1) { - val data3 = SRBleCmdUtil.instance.byteToInt(data[3]) - //开启直播 - if (data2 == 1) { - if (data3 == 0) { - LogUtil.e("蓝牙开启直播成功") - mPetBean?.apply { - mRequestModeType = ConstantInt.Type1 - mMapLiveViewModel.setupDeviceLiveStatus( - this@LiveActivityV2, deviceId, mLiveStatus, mRequestModeType - ) - } - } else { - LogUtil.e("蓝牙开启直播失败") - openNetLive(ConstantInt.Type3) - } - } else if (data2 == 0) { - mPetBean?.apply { - //停止Live直播 - mRequestModeType = if (data3 == 0) { - LogUtil.e("蓝牙停止直播成功") - ConstantInt.Type1 - } else { - LogUtil.e("蓝牙停止直播失败") - ConstantInt.Type3 - } - mMapLiveViewModel.setupDeviceLiveStatus( - this@LiveActivityV2, deviceId, 0, mRequestModeType - ) - } - } - } else if (data0 == 3 && data1 == 1) { - val modeType = if (data2 == 0) { - ConstantInt.Type1 - } else { - ConstantInt.Type3 - } - mMapDeviceBean?.apply { - mLedLightViewModel.setLedSwitch( - null, deviceServerId, ledSwitch, modeType - ) - } - } - } - } - - /** - * 开启网络上报直播 - */ - private fun openNetLive(modeType: Int) { - if (isLiveJump) { - mPetBean?.apply { - //刚开始显示Starting Live. - mCountDownViewModel.startCountDown(2) - mRequestModeType = modeType - mMapLiveViewModel.setupDeviceLiveStatus( - this@LiveActivityV2, deviceId, mLiveStatus, modeType - ) - } - } - } - - /** - * 更新蓝牙上报的数据 - */ - private fun updateBleReportData(bleReportDataBean: BleReportDataBean) { - mHomeMapCommon.startRefreshUserLocation() - bleReportDataBean.apply { - if (haveDeviceStateData) { - if (null == mMapDeviceBean) mMapDeviceBean = MapDeviceBean() - mMapDeviceBean?.let { - Util.bleReportDataToMapDevice(it, bleReportDataBean) - - val isOpen = ledSwitch > ConstantInt.Close - mViewBinding.ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.cbDeviceLightSwitch.isChecked = - isOpen - mViewBinding.ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.cbDeviceLightSwitch.isChecked = - isOpen - -// if (haveLocationData && liveFlag == ConstantInt.Type1) { - if (liveFlag == ConstantInt.Type1) { - if (!isStartLive) { - isStartLive = true - liveStartTip() - } - if (haveLocationData) { - lifecycleScope.launch { - locationList?.let { location -> - liveDrawLines(location) - } - } - } - mHomeMapCommon.setMapDeviceBean(it) - } else if (liveFlag == ConstantInt.Type0) { - //直播自动结束 - if (isStartLive) { - XEventBus.post(EventName.LiveAutoEnd) - finish() - } - } - } - - mMapViewModel.setDeviceStateAndWarningData( - mContext, - mPetBean, - mMapDeviceBean!!, - mDeviceStateList, - mDeviceStateAdapter, - mDeviceMsgList, - mDeviceMsgAdapter, - mViewBinding.rvLiveV2MapDeviceMsg - ) - } - } - } - - /** - * 远程设置led开关 - */ - private fun setLedSwitch() { - isLedOpen = !isLedOpen - mViewBinding.apply { - //屏蔽点击就变状态 -// cbLiveV2DeviceLightSwitch.isChecked = !cbLiveV2DeviceLightSwitch.isChecked - ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.cbDeviceLightSwitch.isChecked = isLedOpen - ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.cbDeviceLightSwitch.isChecked = - isLedOpen - val ledSwitch = if (isLedOpen) ConstantInt.Open - else ConstantInt.Close - - mMapDeviceBean?.apply { - this.ledSwitch = ledSwitch - if (BleManager.getInstance().isConnected(deviceMacId)) { - setLedSwitch(ledSwitch) - } else { - mLedLightViewModel.setLedSwitch( - null, deviceServerId, ledSwitch, ConstantInt.Type2 - ) - } - } - } - } - - /** - *发送设备开启关闭led蓝牙指令 - */ - private fun setLedSwitch(mode: Int) { - mTrackBleDevice?.apply { - SRBleUtil.instance.setBleLedSwitch(mContext, bleDevice, mode) - } - } - - /** - * 更新设备连接状态 - */ - private fun updateConState(trackBleDevice: BleTrackDeviceBean) { - mTrackBleDevice = trackBleDevice - if (trackBleDevice.conState == ConState.CONNECTED) { - LogUtil.e("更新设备连接状态") - if (isLiveJump) { - if (isStartLive) { - mMapLiveViewModel.stopGetData() - } else { - mCountDownViewModel.startCountDown(2) - lifecycleScope.launch { - //延时几秒发送消息 - delay(1000) - trackBleDevice.apply { - SRBleUtil.instance.writeData( - bleDevice, SRBleCmdUtil.instance.setLiveSwitch(1, mLiveTime * 60L) - ) - } - } - } - } -// showToast(R.string.tracker_manage_set_ble_connect) -// mViewBinding.ilLiveV2BluetoothFindDevice.ivMapLiveV2BleConState.setValue(2) - } else if (trackBleDevice.conState == ConState.CONNECTION_FAIL) { - if (isLiveJump) { - openNetLive(ConstantInt.Type2) - } - } else { - if (isLiveJump && isStartLive) { - mPetBean?.apply { - //直播开启后,就去获取直播轨迹 - mMapLiveViewModel.mGetPetLivePointTimeStamp = System.currentTimeMillis() / 1000 - mMapLiveViewModel.getPetLivePoint(deviceId) - } - } - } - } - - - /** - * 显示地图类型选择弹窗 - */ - private fun showMapTypeDialog() { - if (null == mSelectMapTypeDialog) { - mSelectMapTypeDialog = ViewUtil.instance.getMapTypeDialog( - mContext, object : BaseRecyclerAdapter.OnItemClickListener { - override fun onItemClick(itemView: View?, pos: Int) { - mMapType = Util.getMapTypeSp() - if (pos == mMapType) { - return - } - mHomeMapCommon.switchSatelliteAndNormalMapType() - } - }) { v, isChecked -> - if (v.id == R.id.cb_dialog_map_fences_switch) { - isShowFence = isChecked - MMKVUtil.putBoolean(MMKVKey.ShowFence, isChecked) - if (isChecked) { - mMapDeviceBean?.fences?.let { fences -> - mFencesMapViewModel.setFencesData(mContext, fences, mFragment) - } - } else { - mFencesMapViewModel.setFencesData(mContext, null, mFragment) - } - } - } - } else { - mSelectMapTypeDialog!!.mapTypeSpToUpdate() - } - mSelectMapTypeDialog?.show() - } - - /** - * 设置地图相关数据 - */ - private fun setMapData(mapDeviceBean: MapDeviceBean) { - mapDeviceBean.apply { - mLiveTime = liveTime / 60 - - mPetBean?.apply { - //查找是否连接了蓝牙 - val bleConDevice = SRBleUtil.instance.getConnectMacDevice(macID) - if (null == bleConDevice) { - if (isLiveJump) { - //没有连接,一进入页面就尝试连接 - if (SRBleUtil.instance.isBleEnable(mContext)) { - mConDeviceViewModel.connectDeviceToMac(this@LiveActivityV2, macID) - } else { - openNetLive(ConstantInt.Type2) - } - } - } else { - updateConState(bleConDevice) - } - } - - mViewBinding.let { - isLedOpen = ledSwitch == ConstantInt.Open - it.ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.cbDeviceLightSwitch.isChecked = - isLedOpen - it.ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.cbDeviceLightSwitch.isChecked = - isLedOpen -// it.tvLiveV2Speed.text = String.format( -// getString(R.string.txt_mph_unit), -// Utils.formatDecimal(Util.kmhToMph(speed.toDouble())) -// ) - } - - if (isShowFence) { - fences?.let { fences -> - mFencesMapViewModel.setFencesData(mContext, fences, mFragment) - } - } - - mHomeMapCommon.let { - it.setMapDeviceBean(this) - it.refreshPetCurrentLocation(latitude, longitude, isMoveCamera) - it.startRippleCircleAnim() - isMoveCamera = false -// val userAndPetDistance = it.getUserAndPetDistance() -// mViewBinding.tvLiveV2Distance.text = String.format( -// getString(R.string.txt_ft_unit), Utils.formatDecimal(userAndPetDistance) -// ) - } - } - } - - - /** - * 显示选择宠物弹窗 - */ - private fun showPetNameAndHead() { - mPetBean?.apply { - showLoading(true) - mViewBinding.llLiveV2MapTopPet.homeDataPetNameSmall.let { - it.text = petName - it.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) - } - mViewBinding.llLiveV2MapTopPet.homeDataPetHeadSmall.appHeadImage.let { - ViewUtil.instance.setPetTypeHead(it, imgurl, petType) - ViewUtil.instance.viewAlphaAndRotationObjectAnimator(it) - } - //重新设置地图宠物头像 - mHomeMapCommon.setPetHeadIcon(imgurl, petType) - - //获取首页设备信息状态 - mMapViewModel.getMapDeviceStatus(deviceId, false) - } - } - - private fun setTrackData(liveDataBean: LiveDataBean) { - //测试经纬度移动 -// mFencesViewModel.setFencesData(mContext!!, isInFence, mFencesList, mFragment) - - mViewBinding.apply { - - liveDataBean.deviceInfo?.apply { - if (liveFlag == ConstantInt.Type0) { - //直播自动结束 - if (isStartLive) { - XEventBus.post(EventName.LiveAutoEnd) - finish() - } - return - } else if (liveFlag == ConstantInt.Type1) { - if (!isStartLive) { - liveStartTip() - isStartLive = true - } - } - - val speedStr = Util.metricConvertUnits( - speed, ConstantInt.Type2, 2 - ).toString() + mSpeedUnit - ilLiveV2OperateLayout.tvLiveV2Speed.text = speedStr - - mHomeMapCommon.setMapDeviceBean(this) - val isOpen = ledSwitch == ConstantInt.Open - ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.cbDeviceLightSwitch.isChecked = isOpen - ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.cbDeviceLightSwitch.isChecked = - isOpen - mMapViewModel.setDeviceStateAndWarningData( - mContext, - mPetBean, - this, - mDeviceStateList, - mDeviceStateAdapter, - mDeviceMsgList, - mDeviceMsgAdapter, - rvLiveV2MapDeviceMsg, - true - ) - - liveDataBean.livePoints?.apply { - if (size > 0) { - mMapLiveViewModel.mGetPetLivePointTimeStamp = - System.currentTimeMillis() / 1000 - //只有一个点的时候,不用休眠 - val sleepTime = - if (size - 1 > 0) mMapLiveViewModel.mRefreshTime / (size - 1) * 1000L - else 0 - lifecycleScope.launch { - forEach { - liveDrawLine(it.latitude, it.longitude) - //休眠几秒再画线 - if (sleepTime > 0) delay(sleepTime) - } - } - } - } - } - } - } - - /** - * 直播开始提示 - */ - private fun liveStartTip() { - LogUtil.e("直播开始了") - if (mStartLiveIndex == 0) { - mStartLiveIndex = 2 - //直播开始显示Starting 5-min Live - mCountDownViewModel.startCountDown(1) - mHomeMapCommon.greenRippleCircleAnim() - } - } - - /** - * 直播画线 - */ - private fun liveDrawLine(latitude: Double, longitude: Double) { - mHomeMapCommon.addTrackLine(latitude, longitude) - val userAndPetDistance = mHomeMapCommon.getUserAndPetDistance() - val distanceStr = Util.metricConvertUnits( - userAndPetDistance.toFloat(), ConstantInt.Type3, 2 - ).toString() + mDistanceUnit - mViewBinding.ilLiveV2OperateLayout.tvLiveV2Distance.text = distanceStr - } - - /** - * 直播画线 - */ - private fun liveDrawLines(trackList: MutableList) { - mHomeMapCommon.addTrackLines(trackList) - val userAndPetDistance = mHomeMapCommon.getUserAndPetDistance() - val distanceStr = Util.metricConvertUnits( - userAndPetDistance.toFloat(), ConstantInt.Type3, 2 - ).toString() + mDistanceUnit - mViewBinding.ilLiveV2OperateLayout.tvLiveV2Distance.text = distanceStr - } - - /** - * 显示隐藏找蓝牙设备布局 - */ - private fun showAndHideFindLayout() { - mViewBinding.apply { - miLiveV2MapAddressView.visibility = View.GONE - val relativeLayout = ivMapLiveV2RefreshBtn.layoutParams as RelativeLayout.LayoutParams - ivMapLiveV2RefreshBtn.visibility = View.GONE - if (ilLiveV2BluetoothFindDevice.root.isGone) { - //找蓝牙设备布局显示 - YoYo.with(Techniques.BounceInUp).duration(800).onStart { - ilLiveV2OperateLayout.root.visibility = View.GONE - ilLiveV2BluetoothFindDevice.root.visibility = View.VISIBLE - }.onEnd { - //刷新定位按钮显示动画 - ViewUtil.instance.viewShowFadeInAnimation(ivMapLiveV2RefreshBtn) - }.playOn(ilLiveV2BluetoothFindDevice.root) - - ivMapLiveV2BluetoothBtn.visibility = View.GONE - relativeLayout.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM) - relativeLayout.addRule(RelativeLayout.ABOVE, R.id.il_live_v2_bluetooth_find_device) - } else { - //找蓝牙设备布局退出 - YoYo.with(Techniques.SlideOutDown).duration(600).onEnd { - ilLiveV2BluetoothFindDevice.root.visibility = View.GONE - ilLiveV2OperateLayout.root.visibility = View.VISIBLE - }.playOn(ilLiveV2BluetoothFindDevice.root) - //直播操作按钮布局显示 - YoYo.with(Techniques.BounceInUp).duration(800).delay(400).onEnd { - //蓝牙图标按钮显示动画 - ViewUtil.instance.viewShowFadeInAnimation(ivMapLiveV2BluetoothBtn) - //刷新定位按钮显示动画 - ViewUtil.instance.viewShowFadeInAnimation(ivMapLiveV2RefreshBtn) - }.playOn(ilLiveV2OperateLayout.root) - - relativeLayout.removeRule(RelativeLayout.ABOVE) - relativeLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM) - } - - root.postDelayed({ - miLiveV2MapAddressView.visibility = View.VISIBLE - mHomeMapCommon.setMarkerInfoViewOffset() - }, 1000) - } - } - - /** - * 显示直播问题 - */ - private fun showLiveIssue() { - mViewBinding.apply { - miLiveV2MapAddressView.visibility = View.GONE - if (ilMapLiveV2IssueLayout.root.isGone) { - YoYo.with(Techniques.BounceInUp).duration(700).onStart { - ilLiveV2OperateLayout.root.visibility = View.GONE - ilMapLiveV2IssueLayout.root.visibility = View.VISIBLE - }.playOn(ilMapLiveV2IssueLayout.root) - } else { - YoYo.with(Techniques.SlideOutDown).duration(600).onEnd { - ilMapLiveV2IssueLayout.root.visibility = View.GONE - YoYo.with(Techniques.BounceInUp).duration(600).onStart { - ilLiveV2OperateLayout.root.visibility = View.VISIBLE - }.playOn(ilLiveV2OperateLayout.root) - }.playOn(ilMapLiveV2IssueLayout.root) - } - - root.postDelayed({ - miLiveV2MapAddressView.visibility = View.VISIBLE - mHomeMapCommon.setMarkerInfoViewOffset() - }, 1000) - } - } - - /** - * 找蓝牙设备 - */ - private fun findBleDevice(mac: String) { - Util.checkBluetoothPermissionsEnabled(mContext, { - showAndHideFindLayout() - mViewBinding.ilLiveV2BluetoothFindDevice.apply { - mFindBleDeviceViewModel.startScanFind( - this@LiveActivityV2, - mac.uppercase(), - liveV2BluetoothSignal, - findBleDeviceRadoView, - ivMapLiveV2BleConState - ) - } - }) - } - - override fun listenBackPressed() { - if (isLiveJump) stopMapLive() - else super.listenBackPressed() - } - - private fun stopMapLive() { - CommonDialog1( - mContext, - "", - getString(R.string.txt_stop_live_tips), - false, - 5f, - Typeface.BOLD, - R.color.data_black_color, - canceledOnTouchOutside = true, - okClickListener = object : BaseDialog.OnDialogOkListener { - override fun onOkClick(dialog: BaseDialog<*>) { - mMapDeviceBean?.apply { - mLiveStatus = 0 - stopLive() - } - } - }).show() - } - - /** - * 停止直播 - */ - private fun stopLive() { - mPetBean?.apply { - setButtonEnabled(mViewBinding.ilLiveV2OperateLayout.llLiveV2StopLive, ConstantInt.Type0) - if (BleManager.getInstance().isConnected(macID)) { - SRBleUtil.instance.isConnectBleSendCmdData( - macID, SRBleCmdUtil.instance.setLiveSwitch(0, 0) - ) - } else { - mRequestModeType = ConstantInt.Type2 - mMapLiveViewModel.setupDeviceLiveStatus( - this@LiveActivityV2, mPetBean!!.deviceId, 0, mRequestModeType - ) - } - } - - } - - /** - * 设置找设备声音音量 - */ - private fun setSound() { - if (isOpenSound) { - mFindBleDeviceViewModel.setVolume(0) - mViewBinding.ilLiveV2BluetoothFindDevice.ivLiveV2FindDeviceSound.setImageResource(R.drawable.icon_sound_off_svg) - } else { - mFindBleDeviceViewModel.setVolume(mFindBleDeviceViewModel.mMaxVolume) - mViewBinding.ilLiveV2BluetoothFindDevice.ivLiveV2FindDeviceSound.setImageResource(R.drawable.icon_sound_on_svg) - } - isOpenSound = !isOpenSound - } - - override fun onClick(v: View?) { - mViewBinding.apply { - when (v!!) { - ivMapLiveV2RefreshBtn -> { - mShowCenterLocation = if (mShowCenterLocation == ConstantInt.PetLocationType) { - ConstantInt.UserLocationType - } else { - ConstantInt.PetLocationType - } - ViewUtil.instance.setMapSwitchLocationButtonImage( - ivMapLiveV2RefreshBtn, mShowCenterLocation - ) - mHomeMapCommon.switchShowLocation(mShowCenterLocation) - } - - ivMapLiveV2BluetoothBtn -> mPetBean?.apply { - findBleDevice(macID) - } - - ilLiveV2BluetoothFindDevice.btnLiveV2StopRadar -> { - if (isLiveJump) { - isOpenSound = true - setSound() - showAndHideFindLayout() - } else { - mFindBleDeviceViewModel.stopFindDevice() - finish() - } - } - - llLiveV2MapTopPet.ivTopPetBtnSmall -> showMapTypeDialog() - ilLiveV2OperateLayout.llLiveV2StopLive -> stopMapLive() - ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.root, ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.cbDeviceLightSwitch, ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.cbDeviceLightSwitch, ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.root -> setLedSwitch() - - ilLiveV2OperateLayout.btnLiveV2Issue -> showLiveIssue() - ilMapLiveV2IssueLayout.tvCloseIssueBtn -> showLiveIssue() - ilLiveV2BluetoothFindDevice.ivLiveV2FindDeviceSound -> setSound() - } - } - } - - override fun onDestroy() { - super.onDestroy() - mViewBinding.lavLiveV2StateAnim.cancelAnimation() -// stopLive() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/abbidot/tracker/ui/activity/subscribe/SureSubscriptionPlanActivity.kt b/app/src/main/java/com/abbidot/tracker/ui/activity/subscribe/SureSubscriptionPlanActivity.kt index d6dcf1e..1601e74 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/activity/subscribe/SureSubscriptionPlanActivity.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/activity/subscribe/SureSubscriptionPlanActivity.kt @@ -186,8 +186,9 @@ class SureSubscriptionPlanActivity : getString(R.string.txt_month_unit), "${p.planTimeMonthsCount}" ) val renewalString = if (p.mealUnit == ConstantString.PackageUnitYear) { - val renewalTimestamp = - Utils.getAfterHowTimestamp(nowTimestamp, p.period * 365L) + val renewalTimestamp = Utils.timestampAddHowTimestamp( + nowTimestamp, p.period, ConstantString.PackageUnitYear + ) val renewalDate = Utils.formatTime(renewalTimestamp, Utils.DATE_FORMAT_PATTERN_EN7) if (p.planTimeMonthsCount > 12) { @@ -214,8 +215,9 @@ class SureSubscriptionPlanActivity : renewalDate ) } else { - val renewalTimestamp = - Utils.getAfterHowTimestamp(nowTimestamp, 30L * p.planTimeMonthsCount) + val renewalTimestamp = Utils.timestampAddHowTimestamp( + nowTimestamp, p.planTimeMonthsCount, ConstantString.PackageUnitMonth + ) val renewalDate = Utils.formatTime(renewalTimestamp, Utils.DATE_FORMAT_PATTERN_EN7) if (p.planTimeMonthsCount > 1) { diff --git a/app/src/main/java/com/abbidot/tracker/ui/fragment/device/HomeTrackFragment.kt b/app/src/main/java/com/abbidot/tracker/ui/fragment/device/HomeTrackFragment.kt index 19814ae..73f0381 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/fragment/device/HomeTrackFragment.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/fragment/device/HomeTrackFragment.kt @@ -492,7 +492,7 @@ class HomeTrackFragment : ViewUtil.instance.addMenuBean(mTrackMenuList, getString(R.string.txt_live_duration)) ViewUtil.instance.addMenuBean( mTrackMenuList, - getString(R.string.txt_firmware_upgrade), + getString(R.string.txt_firmware_version), menuType = MultipleEntity.IMG_TEXT_IMG ) ViewUtil.instance.addMenuBean( diff --git a/app/src/main/java/com/abbidot/tracker/ui/fragment/map/MapV2Fragment.kt b/app/src/main/java/com/abbidot/tracker/ui/fragment/map/MapV2Fragment.kt deleted file mode 100644 index 65d0f87..0000000 --- a/app/src/main/java/com/abbidot/tracker/ui/fragment/map/MapV2Fragment.kt +++ /dev/null @@ -1,647 +0,0 @@ -package com.abbidot.tracker.ui.fragment.map - -import android.content.Context -import android.content.Intent -import android.location.LocationManager -import android.provider.Settings -import android.view.View -import androidx.core.view.WindowInsetsCompat -import androidx.fragment.app.Fragment -import androidx.fragment.app.commit -import androidx.fragment.app.viewModels -import androidx.lifecycle.lifecycleScope -import com.abbidot.baselibrary.constant.ConState -import com.abbidot.baselibrary.constant.EventName -import com.abbidot.baselibrary.constant.MMKVKey -import com.abbidot.baselibrary.eventbus.XEventBus -import com.abbidot.baselibrary.list.BaseRecyclerAdapter -import com.abbidot.baselibrary.util.AppUtils -import com.abbidot.baselibrary.util.LogUtil -import com.abbidot.baselibrary.util.MMKVUtil -import com.abbidot.tracker.R -import com.abbidot.tracker.adapter.HomeMapDeviceMsgAdapter -import com.abbidot.tracker.adapter.HomeMapDeviceStateAdapter -import com.abbidot.tracker.base.BaseDialog -import com.abbidot.tracker.base.BaseFragment -import com.abbidot.tracker.bean.BleReportDataBean -import com.abbidot.tracker.bean.BleTrackDeviceBean -import com.abbidot.tracker.bean.DataBean -import com.abbidot.tracker.bean.FamilyBean -import com.abbidot.tracker.bean.MapDeviceBean -import com.abbidot.tracker.constant.ConstantInt -import com.abbidot.tracker.constant.ConstantString -import com.abbidot.tracker.constant.GetResultCallback -import com.abbidot.tracker.database.MyDatabase -import com.abbidot.tracker.databinding.FragmentMapV2Binding -import com.abbidot.tracker.dialog.CommonDialog1 -import com.abbidot.tracker.dialog.SelectMapTypeDialog -import com.abbidot.tracker.ui.activity.HomeV2Activity -import com.abbidot.tracker.ui.activity.device.MyTrackerV2Activity -import com.abbidot.tracker.ui.activity.map.LiveActivityV2 -import com.abbidot.tracker.ui.common.map.HomeMapCommon -import com.abbidot.tracker.util.Util -import com.abbidot.tracker.util.ViewUtil -import com.abbidot.tracker.util.bluetooth.SRBleUtil -import com.abbidot.tracker.vm.FamilyViewModel -import com.abbidot.tracker.vm.FencesMapViewModel -import com.abbidot.tracker.vm.MapViewModel -import com.abbidot.tracker.widget.MapDeviceNetView -import com.clj.fastble.BleManager -import com.hjq.permissions.XXPermissions -import com.hjq.permissions.permission.PermissionLists -import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import javax.inject.Inject - - -/** - * 首页map - * create an instance of this fragment. - */ -@AndroidEntryPoint -class MapV2Fragment : BaseFragment(FragmentMapV2Binding::inflate) { - - private val mFencesMapViewModel: FencesMapViewModel by viewModels() - private val mMapViewModel: MapViewModel by viewModels() - private val mFamilyViewModel: FamilyViewModel by viewModels() - - private lateinit var mLocationManager: LocationManager - - private lateinit var mHomeV2Activity: HomeV2Activity - - private var mSelectMapTypeDialog: SelectMapTypeDialog? = null - - //当前这个页面显示的宠物下标 - private var mCurrentShowPetPos = -1 - - @Inject - lateinit var mHomeMapCommon: HomeMapCommon - private lateinit var mFragment: Fragment - private var mMapDeviceBean: MapDeviceBean? = null - - private lateinit var mDeviceStateList: MutableList - private lateinit var mDeviceStateAdapter: HomeMapDeviceStateAdapter - private lateinit var mDeviceMsgList: MutableList - private lateinit var mDeviceMsgAdapter: HomeMapDeviceMsgAdapter - - //启动移动地图摄像机 - private var isMoveCamera = true - private var mShowCenterLocationType = ConstantInt.PetLocationType - - //是否显示围栏 - private var isShowFence = true - - //地图类型,标准和卫星地图 - private var mMapType = ConstantInt.Type0 - - companion object { - @JvmStatic - fun newInstance(context: Context) = MapV2Fragment().apply { - mContext = context - } - } - - override fun initData() { - mLocationManager = mContext!!.getSystemService(Context.LOCATION_SERVICE) as LocationManager - mHomeV2Activity = activity as HomeV2Activity - mCurrentShowPetPos = mHomeV2Activity.mSelectPetPosition - - isShowFence = Util.getShowFenceSp() - - mViewBinding.apply { - mHomeV2Activity.edgeToEdgeAdapterBars( - rlHomeMapTopLayout, WindowInsetsCompat.Type.statusBars() - ) - mFragment = mHomeMapCommon.getMapFragment( - mContext!!, miHomeMapAddressView, dnHomeMapNetView - ) { mapLoadOk() } - - dnHomeMapNetView.setShowNetType(MapDeviceNetView.NO_NET_TYPE) - llHomeMapTopPet.ivTopPetBtnSmall.setImageResource(R.drawable.icon_map_type) - - ViewUtil.instance.setMapSwitchLocationButtonImage( - homeMapRefreshBtn, mShowCenterLocationType - ) - - mDeviceStateList = mutableListOf() - mDeviceMsgList = mutableListOf() - mMapViewModel.addDeviceDefaultStateData(mContext!!, mDeviceStateList) - mDeviceStateAdapter = HomeMapDeviceStateAdapter(mContext!!, mDeviceStateList) - ViewUtil.instance.setRecyclerViewVerticalLinearLayout( - mContext!!, rvHomeMapDeviceState, mDeviceStateAdapter, bottom = 10 - ) - - mDeviceMsgAdapter = HomeMapDeviceMsgAdapter(mContext!!, mDeviceMsgList) - ViewUtil.instance.setRecyclerViewVerticalLinearLayout( - mContext!!, rvHomeMapDeviceMsg, mDeviceMsgAdapter, bottom = 10 - ) - - setOnClickListenerViews( - homeMapRefreshBtn, - homeMapBluetoothBtn, - homeMapLiveBtn, - llHomeMapTopPet.ivTopPetBtnSmall, - llHomeMapTopPet.homeDataPetNameSmall, - llHomeMapTopPet.homeDataPetHeadSmall.root - ) - - if (AppUtils.isDebug()) { - llHomeMapTopPet.homeDataPetHeadSmall.appHeadImage.setOnLongClickListener { - mHomeV2Activity.goToDebugActivity() - true - } - } - } - - //解决报错java.lang.IllegalArgumentException - //No view found for id 0x7f090254 (com.abbidot.tracker:id/fc_home_map_fragment) for fragment HomeMapGoogleMapFragment - //https://www.jianshu.com/p/9235092f407a - childFragmentManager.commit { - add(R.id.fc_home_map_fragment, mFragment) - } -// (mActivity as FragmentActivity).supportFragmentManager.commit { -// add(R.id.fc_home_map_fragment, mFragment) -// } - - locationPermissionsTip(1) - } - - override fun onResume() { - super.onResume() - - //其他页面是否选择了宠物 - if (mCurrentShowPetPos != mHomeV2Activity.mSelectPetPosition) { - showPetNameAndHead(mHomeV2Activity.mSelectPetPosition) - } - mViewBinding.apply { - homeMapLiveBtn.isEnabled = true - homeMapBluetoothBtn.isEnabled = true - } - - val showFence = Util.getShowFenceSp() - //检测直播页面有没有修改围栏显示 - if (isShowFence != showFence) { - if (null == mSelectMapTypeDialog) { - setFencesShow(showFence) - } else { - mSelectMapTypeDialog?.setFencesSwitch(showFence) - } - } - } - - private fun getHomeV2Activity(): HomeV2Activity? { - return if (null == activity) { - LogUtil.e("getHomeV2Activity,null == activity") - null - } else { - activity as HomeV2Activity - } - } - - /** - * 地图加载好了 - */ - private fun mapLoadOk() { - LogUtil.e("MapV2Fragment 地图加载好了${mHomeV2Activity.mPetList}") -// mHomeV2Activity.mDataViewModel.getHomeBindPetList(mHomeV2Activity) - mHomeV2Activity.apply { - if (mPetList.size > 0) showPetNameAndHead(mSelectPetPosition) - mFamilyViewModel.getDeviceInviteInfo(this) - } - } - - override fun liveDataObserve() { - //获取设备邀请信息 - mFamilyViewModel.mInviteInfoLiveData.observe(this) { - dealRequestResult(it, object : GetResultCallback { - override fun onResult(any: Any) { - it.getOrNull()?.apply { - if (deleteArray.isNotEmpty()) showDeleteInviteDialog(deleteArray) - if (inviteArray.isNotEmpty()) showInviteDialog(inviteArray) - } - } - }) - } - //获取当前宠物位置和围栏信息 - mMapViewModel.mMapDeviceLiveData.observe(this) { - dealRequestResult(it, object : GetResultCallback { - override fun onResult(any: Any) { - val data = it.getOrNull() - data?.apply { - mMapDeviceBean = data - setMapData(data) - mMapViewModel.setDeviceStateAndWarningData( - mContext!!, - mHomeV2Activity.getPet(), - data, - mDeviceStateList, - mDeviceStateAdapter, - mDeviceMsgList, - mDeviceMsgAdapter, - mViewBinding.rvHomeMapDeviceMsg - ) - } - } - }, showLoading = false, isRequestErrorTip = false) - } - - //删除围栏通知 - XEventBus.observe(this, EventName.DeleteFences) { - updateMapDeviceStatus() - } - //添加编辑围栏通知 - XEventBus.observe(this, EventName.RefreshFences) { - updateMapDeviceStatus() - } - //直播自动结束提示 - XEventBus.observe(this, EventName.LiveAutoEnd) { - ViewUtil.instance.showDialog( - mContext!!, R.string.txt_live_ended, object : BaseDialog.OnDialogOkListener { - override fun onOkClick(dialog: BaseDialog<*>) { - dialog.dismiss() - } - }, okTextResId = R.string.txt_sure, cancelTextResId = R.string.txt_cancel - ) - } - //直播超时 - XEventBus.observe(this, EventName.LiveOpenTimeOut) { - ViewUtil.instance.showDialog( - mContext!!, - R.string.txt_time_out_try_again, - object : BaseDialog.OnDialogOkListener { - override fun onOkClick(dialog: BaseDialog<*>) { - dialog.dismiss() - locationPermissionsTip() - } - }, - okTextResId = R.string.txt_sure - ) - } - //蓝牙上报的数据 - XEventBus.observe(this, EventName.BleReportData) { reportData: BleReportDataBean -> - mHomeV2Activity.getPet(false)?.apply { - if (macID == reportData.mac) updateBleReportData(reportData) - } - } - //接收蓝牙连接状态 - XEventBus.observe(this, EventName.ConnectDeviceState) { trackBle: BleTrackDeviceBean -> - mHomeV2Activity.getPet(false)?.apply { - //蓝牙断开就重新获取服务器数据,蓝牙数据上报断开 - if (trackBle.mac == macID && trackBle.conState != ConState.CONNECTED) { - //隐藏蓝牙nearby - mViewBinding.rvHomeMapDeviceMsg.visibility = View.GONE - updateMapDeviceStatus() - } - } - } - } - - /** - * 更新蓝牙上报的数据 - */ - private fun updateBleReportData(bleReportDataBean: BleReportDataBean) { - bleReportDataBean.apply { - if (haveDeviceStateData) { - mMapViewModel.stopGetData() - if (null == mMapDeviceBean) mMapDeviceBean = MapDeviceBean() - mMapDeviceBean?.let { - Util.bleReportDataToMapDevice(it, bleReportDataBean) - if (haveLocationData) { - locationList?.let { list -> - val location = list[list.size - 1] - it.longitude = location.longitude - it.latitude = location.latitude - } - mHomeMapCommon.setMapDeviceBean(mMapDeviceBean) - mHomeMapCommon.refreshPetCurrentLocation( - it.latitude, it.longitude, isMoveCamera - ) - mHomeMapCommon.startRefreshUserLocation() - } - } - - mViewBinding.homeMapLiveBtn.visibility = View.VISIBLE - - mMapViewModel.setDeviceStateAndWarningData( - mContext!!, - mHomeV2Activity.getPet(), - mMapDeviceBean!!, - mDeviceStateList, - mDeviceStateAdapter, - mDeviceMsgList, - mDeviceMsgAdapter, - mViewBinding.rvHomeMapDeviceMsg - ) - } - } - } - - /** - * 显示被删除邀请的弹窗 - */ - private fun showDeleteInviteDialog(deleteArray: MutableList) { - lifecycleScope.launch(Dispatchers.IO) { - val myDeviceDb = MyDatabase.deviceDao().findAll(MyDatabase.DeviceTableName) - myDeviceDb?.apply { - for (deviceDb in myDeviceDb) { - for (item in deleteArray) { - if (deviceDb.deviceId == item.deviceId) { - MyDatabase.deviceDao().delete(deviceDb) - LogUtil.e("删除了邀请的设备") - } - } - } - } - val newDeviceDb = MyDatabase.deviceDao().findAll(MyDatabase.DeviceTableName) - newDeviceDb?.apply { - LogUtil.e("删去了邀请,还剩${newDeviceDb.size}下个设备") - } - } - CommonDialog1( - mContext!!, - getString(R.string.txt_setting_notification), - getString(R.string.txt_view_access), - false, - okClickListener = object : BaseDialog.OnDialogOkListener { - override fun onOkClick(dialog: BaseDialog<*>) { - if (mHomeV2Activity.mPetList.size == 0) { - mHomeV2Activity.noSharePet() - } else { - mHomeV2Activity.onChangeClick(0) - } - } - }).show() - } - - /** - * 显示被邀请通知弹窗 - */ - private fun showInviteDialog(inviteArray: MutableList) { - for (item in inviteArray) { - val content = String.format( - getString(R.string.txt_invites_you_check), item.userName, item.petName - ) - CommonDialog1( - mContext!!, - getString(R.string.txt_setting_notification), - content, - false, - okClickListener = object : BaseDialog.OnDialogOkListener { - override fun onOkClick(dialog: BaseDialog<*>) { - startActivity( - mHomeV2Activity, Intent( - mHomeV2Activity, MyTrackerV2Activity::class.java - ) - ) - } - }).show() - } - } - - private val mPermissionsTips = - "ABBIDOT APP collects location data,The route and distance between the current location and the device can be calculated." - - /** - * 弹窗说明需要位置权限做什么,上架市场需要 - */ - private fun locationPermissionsTip(type: Int = 0) { - if (XXPermissions.isGrantedPermissions( - mContext!!, mutableListOf( - PermissionLists.getAccessFineLocationPermission(), - PermissionLists.getAccessCoarseLocationPermission() - ) - ) - ) { - if (type == 0) checkPermissions(type) - } else { - ViewUtil.instance.showDialog( - mContext!!, mPermissionsTips, object : BaseDialog.OnDialogOkListener { - override fun onOkClick(dialog: BaseDialog<*>) { - dialog.dismiss() - if (type == 0) checkPermissions(type) - else Util.checkLocationPermissionsGpsEnabled(mContext!!, {}) - } - }, okTextResId = R.string.txt_accept, cancelTextResId = R.string.txt_deny - ) - } - } - - /** - * 更新首页设备状态数据 - */ - private fun updateMapDeviceStatus( - isNeedCountDown: Boolean = true, useBleLocation: Boolean = false - ) { -// mShowCenterLocationType = ConstantInt.PetLocationType -// ViewUtil.instance.setMapSwitchLocationButtonImage( -// mViewBinding.homeMapRefreshBtn, mShowCenterLocationType -// ) - if (mHomeV2Activity.mPetList.size <= mCurrentShowPetPos) return - mHomeV2Activity.getPet()?.apply { - //蓝牙连接上,就直接用蓝牙上报的位置刷新 - if (useBleLocation && BleManager.getInstance().isConnected(macID)) { - mMapDeviceBean?.let { - mHomeMapCommon.refreshPetCurrentLocation( - it.latitude, it.longitude, isMoveCamera - ) - mHomeMapCommon.startRefreshUserLocation() - } - } else { - mMapViewModel.getMapDeviceStatus(deviceId, isNeedCountDown) - } - } - } - - /** - * 显示地图类型选择弹窗 - */ - private fun showMapTypeDialog() { - if (null == mSelectMapTypeDialog) mSelectMapTypeDialog = ViewUtil.instance.getMapTypeDialog( - mContext!!, object : BaseRecyclerAdapter.OnItemClickListener { - override fun onItemClick(itemView: View?, pos: Int) { - mMapType = Util.getMapTypeSp() - if (pos == mMapType) { - return - } - mHomeMapCommon.switchSatelliteAndNormalMapType() - } - }) { v, isChecked -> - if (v.id == R.id.cb_dialog_map_fences_switch) { - setFencesShow(isChecked) - } - } - else { - mSelectMapTypeDialog!!.mapTypeSpToUpdate() - } - mSelectMapTypeDialog?.show() - } - - /** - * 设置围栏显示 - */ - private fun setFencesShow(isShow: Boolean) { - isShowFence = isShow - MMKVUtil.putBoolean(MMKVKey.ShowFence, isShow) - if (isShow) { - mMapDeviceBean?.fences?.let { fences -> - mFencesMapViewModel.setFencesData(mContext!!, fences, mFragment) - } - } else { - mFencesMapViewModel.setFencesData(mContext!!, null, mFragment) - } - } - - /** - * 设置需要更新的标识 - */ - fun setNeedUpdateTag() { - mCurrentShowPetPos = -1 - } - - /** - * 显示选择宠物 - */ - fun showPetNameAndHead(position: Int) { - //变量初始化 - if (!::mHomeV2Activity.isInitialized) { - return - } - if (mHomeV2Activity.mPetList.size == 0) { - return - } - mCurrentShowPetPos = position - - ViewUtil.instance.selectPetDialogShow( - mContext!!, - mHomeV2Activity.mPetList, - position, - mViewBinding.llHomeMapTopPet.homeDataPetNameSmall, - mViewBinding.llHomeMapTopPet.homeDataPetHeadSmall.appHeadImage - ) - - if (mHomeMapCommon.isMapLoadOk()) { - isMoveCamera=true - mHomeMapCommon.clearMarker() - mViewBinding.miHomeMapAddressView.visibility = View.GONE - mViewBinding.rvHomeMapDeviceMsg.visibility = View.GONE - showLoading(true) - val pet = mHomeV2Activity.mPetList[position] - //重新设置地图宠物头像 - mHomeMapCommon.setPetHeadIcon(pet.imgurl, pet.petType) - - //获取首页设备信息状态 - updateMapDeviceStatus() - } - } - - - /** - * 设置地图相关数据 - */ - private fun setMapData(mapDeviceBean: MapDeviceBean) { - mapDeviceBean.apply { - //分钟后无上报、没有lte信号或在wifi中隐藏直播按钮 - mViewBinding.homeMapLiveBtn.visibility = - if (Util.isTimeoutReport(updateTime) || powerSwitch == ConstantInt.Type0 || powerSwitch == ConstantInt.Type2 || inWifiZone == ConstantInt.Type1) View.GONE - else View.VISIBLE - - mHomeMapCommon.setMapDeviceBean(this) - //设置循环查询时间间隔 30秒 - mMapViewModel.updateMillisInFuture(0.5f) - - if (isShowFence) { - fences?.let { fences -> - mFencesMapViewModel.setFencesData(mContext!!, fences, mFragment) - } - } - -// mShowCenterLocationType = ConstantInt.PetLocationType -// ViewUtil.instance.setMapSwitchLocationButtonImage( -// mViewBinding.homeMapRefreshBtn, mShowCenterLocationType -// ) - mHomeMapCommon.refreshPetCurrentLocation(latitude, longitude, isMoveCamera) - mHomeMapCommon.startRefreshUserLocation() - - isMoveCamera = false - } - } - - /** - * 检查获取定位,蓝牙权限 - */ - private fun checkPermissions(type: Int) { - Util.checkBluetoothPermissionsEnabled(mContext!!, { - if (type == 0) { - if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { - val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS) - startActivity(intent) - } else if (mHomeV2Activity.isRequestPetData && mHomeV2Activity.mPetList.size == 0) { - showToast(R.string.no_bind_pet) - } else { - mHomeV2Activity.getPet()?.apply { - mViewBinding.homeMapLiveBtn.isEnabled = false - val intent = Intent(mContext, LiveActivityV2::class.java) - intent.putExtra(ConstantString.JumpActivity, true) - intent.putExtra(ConstantString.Pet, this) - startActivity(intent) - } - } - } else if (type == 1) { - if (!SRBleUtil.instance.isBleEnable(mContext!!)) { - SRBleUtil.instance.openBluetooth(mContext!!) - } else if (mHomeV2Activity.isRequestPetData && mHomeV2Activity.mPetList.size == 0) { - showToast(R.string.no_bind_pet) - } else { - mHomeV2Activity.getPet()?.apply { - mViewBinding.homeMapBluetoothBtn.isEnabled = false - val intent = Intent(mContext, LiveActivityV2::class.java) - intent.putExtra(ConstantString.JumpActivity, false) - intent.putExtra(ConstantString.Pet, this) - startActivity(intent) - } - } - } - }) - } - - override fun onClick(v: View?) { - mViewBinding.apply { - when (v!!) { - homeMapRefreshBtn -> { - if (mHomeV2Activity.isRequestPetData && mHomeV2Activity.mPetList.size == 0) { - showToast(R.string.no_bind_pet) - return - } - if (mShowCenterLocationType == ConstantInt.PetLocationType) { - mShowCenterLocationType = ConstantInt.UserLocationType - mHomeMapCommon.switchShowLocation(mShowCenterLocationType) - } else { - mShowCenterLocationType = ConstantInt.PetLocationType - isMoveCamera = true - updateMapDeviceStatus(useBleLocation = true) - } - ViewUtil.instance.setMapSwitchLocationButtonImage( - homeMapRefreshBtn, mShowCenterLocationType - ) - } - - homeMapLiveBtn -> { -// locationPermissionsTip() - mHomeV2Activity.getPet()?.apply { - mViewBinding.homeMapLiveBtn.isEnabled = false - val intent = Intent(mContext, LiveActivityV2::class.java) - intent.putExtra(ConstantString.JumpActivity, true) - intent.putExtra(ConstantString.Pet, this) - startActivity(intent) - } - } - - llHomeMapTopPet.ivTopPetBtnSmall -> showMapTypeDialog() - homeMapBluetoothBtn -> checkPermissions(1) - llHomeMapTopPet.homeDataPetNameSmall, llHomeMapTopPet.homeDataPetHeadSmall.root -> mHomeV2Activity.selectPetDialog() - } - - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/abbidot/tracker/ui/fragment/map/MapV3Fragment.kt b/app/src/main/java/com/abbidot/tracker/ui/fragment/map/MapV3Fragment.kt index f865ff5..157757f 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/fragment/map/MapV3Fragment.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/fragment/map/MapV3Fragment.kt @@ -242,6 +242,8 @@ class MapV3Fragment : BaseFragment(FragmentMapV3Binding::i } mCountDownTimerViewModel.mCountDownEndLiveData.observe(this) { + mCountDownTimerViewModel.isStartCountDown = true + LogUtil.e("22222222222") mViewBinding.llHomeMapTopPet.homeDataPetNameSmall.text = getHomeV2Activity()?.getPet()?.petName } @@ -487,6 +489,7 @@ class MapV3Fragment : BaseFragment(FragmentMapV3Binding::i if (mPetList.size == 0) { return } + mCountDownTimerViewModel.isStartCountDown = false mCurrentShowPetPos = position //隐藏蓝牙nearby @@ -530,23 +533,18 @@ class MapV3Fragment : BaseFragment(FragmentMapV3Binding::i mapDeviceBean.apply { setMapDeviceBean(this) //设置循环查询时间间隔 30秒 - mMapViewModel.updateMillisInFuture(0.5f) +// mMapViewModel.updateMillisInFuture(0.5f) if (latitude == 0.0 && longitude == 0.0) { - mHomeMapCommon.clearMarker() - isMoveCamera = true - mHomeMapCommon.getUserGoogleLatLng()?.let { - mHomeMapCommon.refreshPetCurrentLocation( - it.latitude, it.longitude, isMoveCamera - ) + if (!mCountDownTimerViewModel.isStartCountDown) { + mHomeMapCommon.clearMarker() + isMoveCamera = true + mCountDownTimerViewModel.startCountDown(30) + mViewBinding.llHomeMapTopPet.homeDataPetNameSmall.setText(R.string.txt_locating) + mViewBinding.ilHomeMapPetLocation.root.visibility = View.INVISIBLE } - mCountDownTimerViewModel.startCountDown(30) - mViewBinding.llHomeMapTopPet.homeDataPetNameSmall.setText(R.string.txt_locating) - mViewBinding.ilHomeMapPetLocation.root.visibility = View.INVISIBLE + mHomeMapCommon.switchShowLocation(ConstantInt.UserLocationType) } else { -// mViewBinding.llHomeMapTopPet.homeDataPetNameSmall.text = -// getHomeV2Activity()?.getPet()?.petName -// mCountDownTimerViewModel.stopCountDown() mHomeMapCommon.refreshPetCurrentLocation(latitude, longitude, isMoveCamera) isMoveCamera = false } diff --git a/app/src/main/java/com/abbidot/tracker/vm/CountDownTimerViewModel.kt b/app/src/main/java/com/abbidot/tracker/vm/CountDownTimerViewModel.kt index 6bd687d..7b6f1c8 100644 --- a/app/src/main/java/com/abbidot/tracker/vm/CountDownTimerViewModel.kt +++ b/app/src/main/java/com/abbidot/tracker/vm/CountDownTimerViewModel.kt @@ -14,6 +14,9 @@ class CountDownTimerViewModel : ViewModel() { val mCountDownEndLiveData = MutableLiveData() private var mCountDownTimer: CountDownTimer? = null + //是否开始倒计时 + var isStartCountDown = false + /** * @param second 秒 * 倒计时 @@ -23,16 +26,19 @@ class CountDownTimerViewModel : ViewModel() { mCountDownTimer = object : CountDownTimer(second * 1000, countDownInterval * 1000L) { override fun onTick(millisUntilFinished: Long) { val time = millisUntilFinished / 1000 + isStartCountDown = true mCountDowningLiveData.value = time } override fun onFinish() { + isStartCountDown = false mCountDownEndLiveData.value = 0L } }.start() } fun stopCountDown() { + isStartCountDown = false mCountDownTimer?.cancel() } diff --git a/app/src/main/java/com/abbidot/tracker/widget/FencesPolygonView.kt b/app/src/main/java/com/abbidot/tracker/widget/FencesPolygonView.kt index 366aa4e..813e759 100644 --- a/app/src/main/java/com/abbidot/tracker/widget/FencesPolygonView.kt +++ b/app/src/main/java/com/abbidot/tracker/widget/FencesPolygonView.kt @@ -238,7 +238,7 @@ class FencesPolygonView : View { it.drawBitmap(this, mCPoint.x - width / 2, mCPoint.y - height / 2, null) it.drawBitmap(this, mBPoint.x - width / 2, mBPoint.y - height / 2, null) } - + it.drawRect(mPathRectF, mFillPaint) } } diff --git a/app/src/main/res/layout/activity_live_v2.xml b/app/src/main/res/layout/activity_live_v2.xml deleted file mode 100644 index af9ef20..0000000 --- a/app/src/main/res/layout/activity_live_v2.xml +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_live_v3.xml b/app/src/main/res/layout/activity_live_v3.xml index ab64cef..c49140a 100644 --- a/app/src/main/res/layout/activity_live_v3.xml +++ b/app/src/main/res/layout/activity_live_v3.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context=".ui.activity.map.LiveActivityV2"> + tools:context=".ui.activity.map.LiveActivityV3"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_map_v3.xml b/app/src/main/res/layout/fragment_map_v3.xml index 46dec23..eaaddc4 100644 --- a/app/src/main/res/layout/fragment_map_v3.xml +++ b/app/src/main/res/layout/fragment_map_v3.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".ui.fragment.map.MapV2Fragment"> + tools:context=".ui.fragment.map.MapV3Fragment"> Please wait… Version Description Firmware Name - Firmware version + Firmware Version Firmware file size upgrade Upgrade successful @@ -499,7 +499,7 @@ Upgrading Preparing for Upgrade Device successfully connected - Currently the latest version + Already latest version The tracker is paired with another account Activity Route