From d4d8fa9861f04a68421fa368c4faba9754ae5ca9 Mon Sep 17 00:00:00 2001 From: yezhiqiu <983577727@qq.com> Date: Thu, 13 Nov 2025 15:30:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9ELED=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=EF=BC=8Cgps=E6=97=B6=E9=97=B4=E8=AE=BE=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E6=9C=BA=EF=BC=8C=E7=9B=B4=E6=92=AD=E8=93=9D?= =?UTF-8?q?=E7=89=99=E4=B8=8B=E5=8F=91;=E4=BF=AE=E6=94=B9=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=AE=BE=E5=A4=87=E6=B2=A1=E6=9C=89=E6=94=AF=E4=BB=98?= =?UTF-8?q?=EF=BC=8C=E8=BF=94=E5=9B=9E=E5=86=8D=E6=AC=A1=E6=89=AB=E6=8F=8F?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E8=AE=BE=E5=A4=87bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compile-file-map.properties | 2 +- app/build.gradle | 6 +- .../tracker/bean/ActionConStateBean.kt | 10 ++ .../ui/activity/map/MapLiveActivity.kt | 21 +-- .../ui/activity/vm/LedLightViewModel.kt | 25 +++- .../tracker/retrofit2/INetworkService.kt | 18 ++- .../abbidot/tracker/retrofit2/NetworkApi.kt | 28 ++-- .../activity/device/AddNewTracker3Activity.kt | 22 ++- .../activity/device/set/LedLightActivity.kt | 22 +-- .../activity/device/set/PowerOffActivity.kt | 2 +- .../device/set/TrackingDurationSetActivity.kt | 66 +++++++-- .../tracker/ui/activity/map/LiveActivityV2.kt | 116 +++++++++++----- .../ui/fragment/device/HomeTrackFragment.kt | 129 +++++++++++------- .../tracker/ui/fragment/pet/PetV2Fragment.kt | 2 +- .../tracker/util/bluetooth/SRBleCmdUtil.kt | 19 ++- .../tracker/util/bluetooth/SRBleUtil.kt | 3 + .../tracker/vm/ConnectionDeviceViewModel.kt | 24 ++-- .../abbidot/tracker/vm/MapLiveViewModel.kt | 8 +- .../abbidot/tracker/vm/TrackerSetViewModel.kt | 18 +-- .../res/layout/layout_live_v2_data_info.xml | 4 +- 20 files changed, 375 insertions(+), 170 deletions(-) create mode 100644 app/src/main/java/com/abbidot/tracker/bean/ActionConStateBean.kt 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 901cfcb..161703c 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 Oct 31 15:54:13 CST 2025 +#Thu Nov 13 11:09:24 CST 2025 diff --git a/app/build.gradle b/app/build.gradle index d20c674..857d45c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,9 +28,9 @@ android { applicationId "com.abbidot.tracker" minSdkVersion 23 targetSdkVersion 35 - versionCode 2022 -// versionName "2.0.22" - versionName "2.0.22-Beta4" + versionCode 2100 +// versionName "2.1.0" + versionName "2.1.0-Beta1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/abbidot/tracker/bean/ActionConStateBean.kt b/app/src/main/java/com/abbidot/tracker/bean/ActionConStateBean.kt new file mode 100644 index 0000000..a221b37 --- /dev/null +++ b/app/src/main/java/com/abbidot/tracker/bean/ActionConStateBean.kt @@ -0,0 +1,10 @@ +package com.abbidot.tracker.bean + +/** + *Created by .yzq on 2025/11/13/周四. + * @link + * @description: + */ +data class ActionConStateBean(var conState: Int, var mac: String) { + constructor() : this(0, "") +} diff --git a/app/src/main/java/com/abbidot/tracker/deprecated/ui/activity/map/MapLiveActivity.kt b/app/src/main/java/com/abbidot/tracker/deprecated/ui/activity/map/MapLiveActivity.kt index b674827..b807f0f 100644 --- a/app/src/main/java/com/abbidot/tracker/deprecated/ui/activity/map/MapLiveActivity.kt +++ b/app/src/main/java/com/abbidot/tracker/deprecated/ui/activity/map/MapLiveActivity.kt @@ -16,16 +16,16 @@ import com.abbidot.tracker.constant.ConstantInt import com.abbidot.tracker.constant.ConstantString import com.abbidot.tracker.constant.GetResultCallback import com.abbidot.tracker.databinding.ActivityMapLiveBinding -import com.abbidot.tracker.vm.MapLiveViewModel -import com.abbidot.tracker.vm.FencesManageViewModel -import com.abbidot.tracker.vm.FencesMapViewModel -import com.abbidot.tracker.vm.FindBleDeviceViewModel -import com.abbidot.tracker.vm.TrackerSetViewModel +import com.abbidot.tracker.deprecated.ui.activity.vm.LedLightViewModel import com.abbidot.tracker.ui.common.map.MapLiveCommon 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.FencesManageViewModel +import com.abbidot.tracker.vm.FencesMapViewModel +import com.abbidot.tracker.vm.FindBleDeviceViewModel +import com.abbidot.tracker.vm.MapLiveViewModel import com.clj.fastble.BleManager import com.clj.fastble.data.BleDevice import com.daimajia.androidanimations.library.Techniques @@ -40,7 +40,7 @@ class MapLiveActivity : BaseActivity(ActivityMapLiveBind private val mMapLiveViewModel: MapLiveViewModel by viewModels() val mFencesMapViewModel: FencesMapViewModel by viewModels() val mFencesManageViewModel: FencesManageViewModel by viewModels() - private val mTrackerManageViewModel: TrackerSetViewModel by viewModels() + private val mLedLightViewModel: LedLightViewModel by viewModels() private val mFindBleDeviceViewModel: FindBleDeviceViewModel by viewModels() lateinit var mPet: PetBean @@ -79,7 +79,7 @@ class MapLiveActivity : BaseActivity(ActivityMapLiveBind ) } - mMapLiveViewModel.setupDeviceLiveStatus(this, mPet.deviceId, mLiveStatus) + mMapLiveViewModel.setupDeviceLiveStatus(this, mPet.deviceId, mLiveStatus,0) } override fun liveDataObserve() { @@ -113,7 +113,7 @@ class MapLiveActivity : BaseActivity(ActivityMapLiveBind } - mTrackerManageViewModel.mLedSwitchLiveData.observe(this) { + mLedLightViewModel.mLedSwitchLiveData.observe(this) { dealRequestResult(it, object : GetResultCallback { override fun onResult(any: Any) { mViewBinding.mapLiveDeviceLedSwitch.isChecked = @@ -193,6 +193,7 @@ class MapLiveActivity : BaseActivity(ActivityMapLiveBind } override fun onBackPressed() { + super.onBackPressed() stopMapLive() } @@ -203,7 +204,7 @@ class MapLiveActivity : BaseActivity(ActivityMapLiveBind dialog.dismiss() mLiveStatus = 0 mMapLiveViewModel.setupDeviceLiveStatus( - this@MapLiveActivity, mPet.deviceId, mLiveStatus + this@MapLiveActivity, mPet.deviceId, mLiveStatus,0 ) } }, okTextResId = R.string.txt_sure @@ -224,7 +225,7 @@ class MapLiveActivity : BaseActivity(ActivityMapLiveBind setBleLedMode(mPet.macID, mHistoryDataBean!!.lightMode) ConstantInt.Open } - mTrackerManageViewModel.setLedSwitch(this, mHistoryDataBean!!.deviceInfoId, ledSwitch) + mLedLightViewModel.setLedSwitch(this, mHistoryDataBean!!.deviceInfoId, ledSwitch,0) } /** diff --git a/app/src/main/java/com/abbidot/tracker/deprecated/ui/activity/vm/LedLightViewModel.kt b/app/src/main/java/com/abbidot/tracker/deprecated/ui/activity/vm/LedLightViewModel.kt index 3ae47ac..3c24bef 100644 --- a/app/src/main/java/com/abbidot/tracker/deprecated/ui/activity/vm/LedLightViewModel.kt +++ b/app/src/main/java/com/abbidot/tracker/deprecated/ui/activity/vm/LedLightViewModel.kt @@ -14,20 +14,41 @@ import kotlinx.coroutines.launch * @description: */ class LedLightViewModel : ViewModel() { + val mSetLedLightLiveData = MutableLiveData>() + val mLedSwitchLiveData = MutableLiveData>() /** * 设置light灯光 */ - fun setLedLight(activity: BaseActivity<*>, mapDeviceBean: MapDeviceBean) { + fun setLedLight(activity: BaseActivity<*>, mapDeviceBean: MapDeviceBean, modeType: Int) { activity.showLoading(true) mapDeviceBean.apply { viewModelScope.launch { val result = NetworkApi.setLedLight( - deviceServerId, ledRedValue, ledGreenValue, ledBlueValue, ledMode, ledSwitch + deviceServerId, + ledRedValue, + ledGreenValue, + ledBlueValue, + ledMode, + ledSwitch, + modeType ) mSetLedLightLiveData.value = result } } } + + /** + * 设置ledSwitch开关 + */ + fun setLedSwitch( + activity: BaseActivity<*>?, deviceInfoId: String, ledSwitch: Int, modeType: Int + ) { + activity?.showLoading(true) + viewModelScope.launch { + val result = NetworkApi.setLedSwitch(deviceInfoId, ledSwitch, modeType) + mLedSwitchLiveData.value = result + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/abbidot/tracker/retrofit2/INetworkService.kt b/app/src/main/java/com/abbidot/tracker/retrofit2/INetworkService.kt index 361934d..25f5233 100644 --- a/app/src/main/java/com/abbidot/tracker/retrofit2/INetworkService.kt +++ b/app/src/main/java/com/abbidot/tracker/retrofit2/INetworkService.kt @@ -827,7 +827,8 @@ interface INetworkService { suspend fun setupDeviceLiveStatus( @Query("deviceId") deviceId: String, @Query("liveState") liveState: Int, - @Query("sendState") sendState: Int + @Query("sendState") sendState: Int, + @Query("modeType") modeType: Int, ): BaseResponse /** @@ -957,7 +958,9 @@ interface INetworkService { @FormUrlEncoded @POST("device/turnoff") suspend fun turnoff( - @Field("deviceInfoId") deviceInfoId: String, @Field("turnOff") turnOff: Int + @Field("deviceInfoId") deviceInfoId: String, + @Field("turnOff") turnOff: Int, + @Field("modeType") modeType: Int ): BaseResponse /** @@ -966,7 +969,9 @@ interface INetworkService { @FormUrlEncoded @POST("device/gnssInterval") suspend fun reportInterval( - @Field("deviceInfoId") deviceInfoId: String, @Field("gnssInterval") gnssInterval: Int + @Field("deviceInfoId") deviceInfoId: String, + @Field("gnssInterval") gnssInterval: Int, + @Field("modeType") modeType: Int ): BaseResponse /** @@ -984,7 +989,9 @@ interface INetworkService { @FormUrlEncoded @POST("device/ledSwitch") suspend fun setLedSwitch( - @Field("deviceInfoId") deviceInfoId: String, @Field("ledSwitch") ledSwitch: Int + @Field("deviceInfoId") deviceInfoId: String, + @Field("ledSwitch") ledSwitch: Int, + @Field("modeType") modeType: Int ): BaseResponse /** @@ -998,7 +1005,8 @@ interface INetworkService { @Field("green") green: Int, @Field("blue") blue: Int, @Field("lightMode") lightMode: Int, - @Field("ledSwitch") ledSwitch: Int + @Field("ledSwitch") ledSwitch: Int, + @Field("modeType") modeType: Int ): BaseResponse /** diff --git a/app/src/main/java/com/abbidot/tracker/retrofit2/NetworkApi.kt b/app/src/main/java/com/abbidot/tracker/retrofit2/NetworkApi.kt index 724944e..99ec582 100644 --- a/app/src/main/java/com/abbidot/tracker/retrofit2/NetworkApi.kt +++ b/app/src/main/java/com/abbidot/tracker/retrofit2/NetworkApi.kt @@ -453,8 +453,8 @@ object NetworkApi : BaseNetworkApi(INetworkService.BASE_URL) { /** * 移除围栏 */ - suspend fun removeFence(fenceId: String, deviceServiceId: String,modeType:Int) = getResult { - service.removeFence(fenceId, deviceServiceId,modeType) + suspend fun removeFence(fenceId: String, deviceServiceId: String, modeType: Int) = getResult { + service.removeFence(fenceId, deviceServiceId, modeType) } /** @@ -731,8 +731,8 @@ object NetworkApi : BaseNetworkApi(INetworkService.BASE_URL) { /** * 打开关闭直播 */ - suspend fun setupDeviceLiveStatus(deviceId: String, liveState: Int) = getResult { - service.setupDeviceLiveStatus(deviceId, liveState, 0) + suspend fun setupDeviceLiveStatus(deviceId: String, liveState: Int, modeType: Int) = getResult { + service.setupDeviceLiveStatus(deviceId, liveState, 0, modeType) } /** @@ -857,14 +857,14 @@ object NetworkApi : BaseNetworkApi(INetworkService.BASE_URL) { * 关闭设备 */ suspend fun turnoff(deviceInfoId: String, turnOff: Int) = getResult { - service.turnoff(deviceInfoId, turnOff) + service.turnoff(deviceInfoId, turnOff, 1) } /** * 设置设备上报下发时间 */ - suspend fun reportInterval(deviceInfoId: String, gnssInterval: Int) = getResult { - service.reportInterval(deviceInfoId, gnssInterval) + suspend fun reportInterval(deviceInfoId: String, gnssInterval: Int, modeType: Int) = getResult { + service.reportInterval(deviceInfoId, gnssInterval, modeType) } /** @@ -877,17 +877,23 @@ object NetworkApi : BaseNetworkApi(INetworkService.BASE_URL) { /** * 设置ledSwitch开关 */ - suspend fun setLedSwitch(deviceInfoId: String, ledSwitch: Int) = getResult { - service.setLedSwitch(deviceInfoId, ledSwitch) + suspend fun setLedSwitch(deviceInfoId: String, ledSwitch: Int, modeType: Int) = getResult { + service.setLedSwitch(deviceInfoId, ledSwitch, modeType) } /** * 设置light灯光 */ suspend fun setLedLight( - deviceServerId: String, red: Int, green: Int, blue: Int, lightMode: Int, ledSwitch: Int + deviceServerId: String, + red: Int, + green: Int, + blue: Int, + lightMode: Int, + ledSwitch: Int, + modeType: Int ) = getResult { - service.setLedLight(deviceServerId, red, green, blue, lightMode, ledSwitch) + service.setLedLight(deviceServerId, red, green, blue, lightMode, ledSwitch, modeType) } /** diff --git a/app/src/main/java/com/abbidot/tracker/ui/activity/device/AddNewTracker3Activity.kt b/app/src/main/java/com/abbidot/tracker/ui/activity/device/AddNewTracker3Activity.kt index f3e72de..d7b45c6 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/activity/device/AddNewTracker3Activity.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/activity/device/AddNewTracker3Activity.kt @@ -1,6 +1,7 @@ package com.abbidot.tracker.ui.activity.device import android.content.Intent +import android.text.TextUtils import android.view.View import android.widget.NumberPicker import androidx.activity.viewModels @@ -17,9 +18,9 @@ import com.abbidot.tracker.constant.GetResultCallback import com.abbidot.tracker.databinding.ActivityAddNewTracker3Binding import com.abbidot.tracker.util.Util import com.abbidot.tracker.util.ViewUtil +import com.abbidot.tracker.util.bluetooth.SRBleUtil import com.abbidot.tracker.vm.ConnectionDeviceViewModel import com.abbidot.tracker.vm.TrackerSetViewModel -import com.clj.fastble.BleManager class AddNewTracker3Activity : BaseActivity(ActivityAddNewTracker3Binding::inflate), @@ -32,6 +33,7 @@ class AddNewTracker3Activity : private var mDeviceOutId = "" private var mDeviceId = "" private var mScanDeviceList: ArrayList? = null + private var mConBleMac = "" override fun getTopBar() = mViewBinding.ilAddNewTracker3TopBar.titleTopBar @@ -93,6 +95,7 @@ class AddNewTracker3Activity : XEventBus.observe(this, EventName.ConnectDeviceState) { ble: BleTrackDeviceBean -> setButtonEnabled(mViewBinding.btnPairTrackerYes, ConstantInt.Type1) if (ble.conState == ConState.CONNECTED) { + mConBleMac = ble.mac val intent = Intent(mContext, AddPairedSuccessActivity::class.java) intent.putExtra(ConstantString.DeviceOutId, mDeviceOutId) intent.putExtra(ConstantString.isFirstBind, isFirstBind) @@ -136,6 +139,20 @@ class AddNewTracker3Activity : } } + override fun leftBackOnClick() { + disconnectBle() + super.leftBackOnClick() + } + + /** + * 防止没支付后退页面。扫描不到设备情况 + */ + private fun disconnectBle() { + if (!TextUtils.isEmpty(mConBleMac)) { + SRBleUtil.instance.disconnectToMac(mConBleMac) + } + } + override fun onClick(v: View?) { mViewBinding.apply { when (v!!) { @@ -146,7 +163,7 @@ class AddNewTracker3Activity : } btnPairTrackerYes -> { - BleManager.getInstance().disconnectAllDevice() + disconnectBle() setButtonEnabled(mViewBinding.btnPairTrackerYes, ConstantInt.Type0) mTrackerSetViewModel.bindDevice( this@AddNewTracker3Activity, mDeviceOutId @@ -154,6 +171,7 @@ class AddNewTracker3Activity : } mRightImageButton -> { + disconnectBle() val intent = Intent(mContext, AddNewTracker2Activity::class.java) intent.putExtra(ConstantString.isFirstBind, isFirstBind) startActivityFinish(intent) diff --git a/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/LedLightActivity.kt b/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/LedLightActivity.kt index 43e2c74..3354eec 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/LedLightActivity.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/LedLightActivity.kt @@ -199,13 +199,6 @@ class LedLightActivity : BaseActivity(ActivityLedLightB mLedLightViewModel.mSetLedLightLiveData.observe(this) { dealRequestResult(it, object : GetResultCallback { override fun onResult(any: Any) { -// XEventBus.post(EventName.UpdateData + "TrackerManageSetActivity") -// XEventBus.post(EventName.UpdateData + "TrackerManageFragment") - mPetBean?.apply { - SRBleUtil.instance.isConnectBleSendCmdData( - macID, SRBleCmdUtil.instance.setNotifySyncData() - ) - } showToast(R.string.txt_change_successful, isFinish = true) } }) @@ -270,7 +263,7 @@ class LedLightActivity : BaseActivity(ActivityLedLightB if (null != mBleTrackDeviceBean) { //判断是否有蓝牙连接 if (BleManager.getInstance().isConnected(mBleTrackDeviceBean!!.bleDevice)) { - finishAndSave() + finishAndSave(ConstantInt.Type1) } else { super.leftBackOnClick() } @@ -282,10 +275,10 @@ class LedLightActivity : BaseActivity(ActivityLedLightB /** * 保存设置数据 */ - private fun finishAndSave() { + private fun finishAndSave(modeType: Int) { mMapDeviceBean?.apply { isFinishSave = true - mLedLightViewModel.setLedLight(this@LedLightActivity, this) + mLedLightViewModel.setLedLight(this@LedLightActivity, this, modeType) } } @@ -375,7 +368,14 @@ class LedLightActivity : BaseActivity(ActivityLedLightB when (v) { //手动连接设备 ledLightBluetoothTips.trbBleConnectState -> connectionBtn(ledLightBluetoothTips.trbBleConnectState.text.toString()) - btnLedLightSetSave -> finishAndSave() + btnLedLightSetSave -> { + val modeType = if (null != mBleTrackDeviceBean && BleManager.getInstance() + .isConnected(mBleTrackDeviceBean!!.bleDevice) + ) ConstantInt.Type1 + else ConstantInt.Type2 + finishAndSave(modeType) + } + btnLedLightIssue -> showLedIssue() ilLedLightIssueLayout.tvCloseIssueBtn -> showLedIssue() } diff --git a/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/PowerOffActivity.kt b/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/PowerOffActivity.kt index a7be887..2c46563 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/PowerOffActivity.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/PowerOffActivity.kt @@ -38,7 +38,7 @@ class PowerOffActivity : BaseActivity(ActivityPowerOffB } mViewBinding.apply { - setOnClickListenerViews(btnPowerOffYes,ilPowerOffBluetoothTips.trbBleConnectState) + setOnClickListenerViews(btnPowerOffYes, ilPowerOffBluetoothTips.trbBleConnectState) } connectBle() diff --git a/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/TrackingDurationSetActivity.kt b/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/TrackingDurationSetActivity.kt index 2a0deae..8c85927 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/TrackingDurationSetActivity.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/TrackingDurationSetActivity.kt @@ -2,6 +2,8 @@ package com.abbidot.tracker.ui.activity.device.set import android.view.View import androidx.activity.viewModels +import com.abbidot.baselibrary.constant.EventName +import com.abbidot.baselibrary.eventbus.XEventBus import com.abbidot.baselibrary.list.BaseRecyclerAdapter import com.abbidot.baselibrary.util.AppUtils import com.abbidot.tracker.R @@ -9,6 +11,7 @@ import com.abbidot.tracker.adapter.DurationSetAdapter import com.abbidot.tracker.base.BaseActivity import com.abbidot.tracker.bean.DataBean import com.abbidot.tracker.bean.MapDeviceBean +import com.abbidot.tracker.bean.ReceiveDeviceData import com.abbidot.tracker.constant.ConstantInt import com.abbidot.tracker.constant.ConstantString import com.abbidot.tracker.constant.GetResultCallback @@ -18,6 +21,7 @@ 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.TrackerSetViewModel +import com.clj.fastble.BleManager class TrackingDurationSetActivity : BaseActivity(ActivityTrackingDurationSetBinding::inflate) { @@ -61,13 +65,49 @@ class TrackingDurationSetActivity : ViewUtil.instance.updateDataBeanOnlySelectedItem( mDurationSetAdapter, mDurationSetAdapter.getData(), mSelectIndex ) - mMapDeviceBean?.apply { - SRBleUtil.instance.isConnectBleSendCmdData( - deviceMacId, SRBleCmdUtil.instance.setNotifySyncData() + } + }) + } + + //接收发送指令后设备返回的数据 + XEventBus.observe(this, EventName.DeviceReceiveData) { receiveData: ReceiveDeviceData -> + mMapDeviceBean?.let { + if (it.deviceMacId == receiveData.mac) { + val data = receiveData.data + parseData(data) + } + } + } + } + + /** + * 解析数据 + */ + private fun parseData(data: ByteArray?) { + data?.apply { + val data0 = SRBleCmdUtil.instance.byteToInt(data[0]) + val data1 = SRBleCmdUtil.instance.byteToInt(data[1]) + val data2 = SRBleCmdUtil.instance.byteToInt(data[2]) + if (data0 == 0x12 && data1 == 1) { + mMapDeviceBean?.apply { + val dataBean = mDurationSetAdapter.getData()[mSelectIndex] + if (data2 == 0) { + mTrackerSetViewModel.reportInterval( + this@TrackingDurationSetActivity, + deviceServerId, + dataBean.imageId, + ConstantInt.Type1 + ) + } else { + mTrackerSetViewModel.reportInterval( + this@TrackingDurationSetActivity, + deviceServerId, + dataBean.imageId, + ConstantInt.Type3 ) } } - }) + } } } @@ -77,7 +117,7 @@ class TrackingDurationSetActivity : for (time in timeList) { DataBean().apply { imageId = time - name = String.format(getString(R.string.txt_duration_min_unit), time) + name = String.format(getString(R.string.txt_duration_min_unit), "$time") durationList.add(this) } } @@ -105,9 +145,19 @@ class TrackingDurationSetActivity : mMapDeviceBean?.apply { mSelectIndex = pos val dataBean = mDurationSetAdapter.getData()[pos] - mTrackerSetViewModel.reportInterval( - this@TrackingDurationSetActivity, deviceServerId, dataBean.imageId - ) + if (BleManager.getInstance().isConnected(deviceMacId)) { + SRBleUtil.instance.isConnectBleSendCmdData( + deviceMacId, + SRBleCmdUtil.instance.setAndRedGpsDuration(duration = dataBean.imageId * 60L) + ) + } else { + mTrackerSetViewModel.reportInterval( + this@TrackingDurationSetActivity, + deviceServerId, + dataBean.imageId, + ConstantInt.Type2 + ) + } } } } \ No newline at end of file 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 index 0502c38..719a419 100644 --- 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 @@ -33,6 +33,7 @@ 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 @@ -47,7 +48,6 @@ 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.vm.TrackerSetViewModel import com.abbidot.tracker.widget.MapDeviceNetView import com.clj.fastble.BleManager import com.daimajia.androidanimations.library.Techniques @@ -64,7 +64,7 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding private val mMapViewModel: MapViewModel by viewModels() private val mFindBleDeviceViewModel: FindBleDeviceViewModel by viewModels() private val mMapLiveViewModel: MapLiveViewModel by viewModels() - private val mTrackerManageViewModel: TrackerSetViewModel by viewModels() + private val mLedLightViewModel: LedLightViewModel by viewModels() private val mCountDownViewModel: CountDownTimerViewModel by viewModels() private val mConDeviceViewModel: ConnectionDeviceViewModel by viewModels() @@ -115,6 +115,7 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding //设备Led灯开关 private var isLedOpen = false + private var mRequestModeType = ConstantInt.Type1 override fun getTopBar() = null @@ -197,6 +198,13 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding } } + /** + * 地图加载好了 + */ + private fun mapLoadOk() { + showPetNameAndHead() + } + override fun liveDataObserve() { mCountDownViewModel.mCountDownEndLiveData.observe(this) { when (mStartLiveIndex) { @@ -311,7 +319,7 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding } else { mPetBean?.apply { mMapLiveViewModel.setupDeviceLiveStatus( - this@LiveActivityV2, deviceId, mLiveStatus + this@LiveActivityV2, deviceId, mLiveStatus, mRequestModeType ) } } @@ -344,11 +352,11 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding //搜索蓝牙的设备状态 XEventBus.observe(this, EventName.ActionConDeviceState) { conState: Int -> if (conState == ConState.DEVICE_NOT_FOUND) { - openNetLive() + openNetLive(ConstantInt.Type2) } } - mTrackerManageViewModel.mLedSwitchLiveData.observe(this) { + mLedLightViewModel.mLedSwitchLiveData.observe(this) { dealRequestResult(it, object : GetResultCallback { override fun onResult(any: Any) { // mViewBinding.cbLiveV2DeviceLightSwitch.isChecked = @@ -401,11 +409,44 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding if (data0 == 0x06 && data1 == 1) { val data3 = SRBleCmdUtil.instance.byteToInt(data[3]) //开启直播 - if (data2 == 1 && data3 == 0) { - LogUtil.e("开启直播") - } else if (data2 == 0 && data3 == 0) { - //停止轨迹Live直播 - LogUtil.e("//停止轨迹Live直播") + 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 + ) } } } @@ -414,16 +455,15 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding /** * 开启网络上报直播 */ - private fun openNetLive() { + private fun openNetLive(modeType: Int) { if (isLiveJump) { mPetBean?.apply { - if (!BleManager.getInstance().isConnected(macID)) { - //刚开始显示Starting Live. - mCountDownViewModel.startCountDown(2) - mMapLiveViewModel.setupDeviceLiveStatus( - this@LiveActivityV2, deviceId, mLiveStatus - ) - } + //刚开始显示Starting Live. + mCountDownViewModel.startCountDown(2) + mRequestModeType = modeType + mMapLiveViewModel.setupDeviceLiveStatus( + this@LiveActivityV2, deviceId, mLiveStatus, modeType + ) } } } @@ -493,9 +533,15 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding val ledSwitch = if (isLedOpen) ConstantInt.Open else ConstantInt.Close - setLedSwitch(ledSwitch) mMapDeviceBean?.apply { - mTrackerManageViewModel.setLedSwitch(null, deviceServerId, ledSwitch) + this.ledSwitch = ledSwitch + if (BleManager.getInstance().isConnected(deviceMacId)) { + setLedSwitch(ledSwitch) + } else { + mLedLightViewModel.setLedSwitch( + null, deviceServerId, ledSwitch, ConstantInt.Type2 + ) + } } } } @@ -515,6 +561,7 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding private fun updateConState(trackBleDevice: BleTrackDeviceBean) { mTrackBleDevice = trackBleDevice if (trackBleDevice.conState == ConState.CONNECTED) { + LogUtil.e("更新设备连接状态") if (isLiveJump) { if (isStartLive) { mMapLiveViewModel.stopGetData() @@ -535,7 +582,7 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding // mViewBinding.ilLiveV2BluetoothFindDevice.ivMapLiveV2BleConState.setValue(2) } else if (trackBleDevice.conState == ConState.CONNECTION_FAIL) { if (isLiveJump) { - openNetLive() + openNetLive(ConstantInt.Type2) } } else if (trackBleDevice.conState == ConState.DISCONNECTED) { if (isLiveJump && isStartLive) { @@ -597,7 +644,6 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding val bleConDevice = SRBleUtil.instance.getConnectMacDevice(macID) if (null == bleConDevice) { if (isLiveJump) { - openNetLive() //没有连接,一进入页面就尝试连接 mConDeviceViewModel.connectDeviceToMac(this@LiveActivityV2, macID) } @@ -841,13 +887,6 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding } } - /** - * 地图加载好了 - */ - private fun mapLoadOk() { - showPetNameAndHead() - } - /** * 找蓝牙设备 */ @@ -898,14 +937,19 @@ class LiveActivityV2 : BaseActivity(ActivityLiveV2Binding * 停止直播 */ private fun stopLive() { - mTrackBleDevice?.apply { - SRBleUtil.instance.writeData( - bleDevice, SRBleCmdUtil.instance.setLiveSwitch(0, 0) - ) + mPetBean?.apply { + 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 + ) + } } - mMapLiveViewModel.setupDeviceLiveStatus( - this@LiveActivityV2, mPetBean!!.deviceId, 0 - ) + } /** 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 8c9634d..ac68c09 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 @@ -35,6 +35,7 @@ import com.abbidot.tracker.constant.ConstantString import com.abbidot.tracker.constant.GetResultCallback import com.abbidot.tracker.constant.MultipleEntity import com.abbidot.tracker.databinding.FragmentHomeTrackBinding +import com.abbidot.tracker.deprecated.ui.activity.vm.LedLightViewModel import com.abbidot.tracker.dialog.DFUNewDialog import com.abbidot.tracker.ui.activity.HomeV2Activity import com.abbidot.tracker.ui.activity.device.fences.VirtualFencesActivity @@ -62,6 +63,7 @@ class HomeTrackFragment : private val mTrackerInfoViewModel: TrackerInfoViewModel by viewModels() private val mTrackerSetViewModel: TrackerSetViewModel by viewModels() + private val mLedLightViewModel: LedLightViewModel by viewModels() private val mConnectionDeviceViewModel: ConnectionDeviceViewModel by viewModels() private val mDeviceDFUViewModel: DeviceDFUViewModel by viewModels() private val mDownLoadFileViewModel: DownLoadFileViewModel by viewModels() @@ -211,20 +213,22 @@ class HomeTrackFragment : } //接收开蓝牙操作,然后搜索连接设备 XEventBus.observe(this, EventName.ActionConDeviceState) { conState: Int -> - if (conState == ConState.CONNECTING || conState == ConState.CONNECTING_MAC) { -// mConnectionDeviceViewModel.connectingFailCountDown() - mTrackStateList[4].apply { - menuValue = getString(R.string.txt_connecting) - colorRedId = R.color.gray - isSwitch = true - mHomePetTrackStateAdapter.notifyItemChanged(4) - } - } else { - mTrackStateList[4].apply { - menuValue = getString(R.string.txt_unconnect_no) - isSwitch = false - colorRedId = R.color.orange_color3 - mHomePetTrackStateAdapter.notifyItemChanged(4) + mHomeV2Activity.getPet()?.apply { + if (BleManager.getInstance().isConnected(macID)) return@apply + if (conState == ConState.CONNECTING || conState == ConState.CONNECTING_MAC) { + mTrackStateList[4].apply { + menuValue = getString(R.string.txt_connecting) + colorRedId = R.color.gray + isSwitch = true + mHomePetTrackStateAdapter.notifyItemChanged(4) + } + } else { + mTrackStateList[4].apply { + menuValue = getString(R.string.txt_unconnect_no) + isSwitch = false + colorRedId = R.color.orange_color3 + mHomePetTrackStateAdapter.notifyItemChanged(4) + } } } } @@ -324,19 +328,25 @@ class HomeTrackFragment : mTurnoffLiveData.observe(viewLifecycleOwner) { dealRequestResult(it, object : GetResultCallback { override fun onResult(any: Any) { - mTrackMenuList[4].menuValue = ConstantInt.Close.toString() - mTrackMenuAdapter.notifyItemChanged(4) - bleTurnOff() +// mTrackMenuList[4].menuValue = ConstantInt.Close.toString() +// mTrackMenuAdapter.notifyItemChanged(4) +// bleTurnOff() + mBleTrackDeviceBean?.apply { + SRBleUtil.instance.writeData( + bleDevice, SRBleCmdUtil.instance.forcedShutdown() + ) + } } }) } - mLedSwitchLiveData.observe(viewLifecycleOwner) { - dealRequestResult(it, object : GetResultCallback { - override fun onResult(any: Any) { - } - }) - } + } + mLedLightViewModel.mLedSwitchLiveData.observe(viewLifecycleOwner) { + dealRequestResult(it, object : GetResultCallback { + override fun onResult(any: Any) { + + } + }) } } @@ -721,22 +731,42 @@ class HomeTrackFragment : ) } } - } else if (data0 == 3 && data1 == 0 && data2 == 0) { - val data3 = SRBleCmdUtil.instance.byteToInt(data[3]) - if (data3 in 1..3) setLedState(ConstantInt.Open) - else setLedState(ConstantInt.Close) - } else if (data0 == 4) { - if (data1 == 1 && data2 == 0) { - mTrackMenuList[1].menuValue = "" - mTrackMenuList[2].menuValue = "" - mTrackMenuList[3].menuValue = "" - //取消红点显示 - mTrackMenuList[3].isSwitch = false - mTrackMenuList[4].menuValue = ConstantInt.Close.toString() - mTrackMenuAdapter.notifyItemRangeChanged(1, 4) - mBleTrackDeviceBean?.apply { - SRBleUtil.instance.disconnectToMac(mac) + } else if (data0 == 3 && data1 == 1) { + val ledSwitch = + if (mTrackStateList[5].menuValue == getString(R.string.tracker_manage_set_led_on)) { + ConstantInt.Close + } else { + ConstantInt.Open } + val modeType = if (data2 == 0) { + val data3 = SRBleCmdUtil.instance.byteToInt(data[3]) + if (data3 in 1..3) setLedState(ConstantInt.Open) + else setLedState(ConstantInt.Close) + ConstantInt.Type1 + } else { + ConstantInt.Type3 + } + mMapDeviceBean?.let { + setLedState(ledSwitch) + //远程控制 + mLedLightViewModel.setLedSwitch( + null, it.deviceServerId, ledSwitch, modeType + ) + } + } else if (data0 == 4 && data1 == 1 && data2 == 0) { + mMapDeviceBean?.let { + mTrackerSetViewModel.turnOff(mHomeV2Activity, it.deviceServerId) + } + mTrackMenuList[1].menuValue = "" + mTrackMenuList[2].menuValue = "" + mTrackMenuList[3].menuValue = "" + //取消红点显示 + mTrackMenuList[3].isSwitch = false + mTrackMenuList[4].menuValue = ConstantInt.Close.toString() + mTrackMenuAdapter.notifyItemRangeChanged(1, 4) + } else if (data0 == 0x18 && data1 == 1 && data2 == 0) { + mBleTrackDeviceBean?.apply { + SRBleUtil.instance.disconnectToMac(mac) } } } @@ -850,16 +880,21 @@ class HomeTrackFragment : } else { ConstantInt.Open } - //蓝牙控制 - getBleTrackDeviceBean(false)?.let { - SRBleUtil.instance.setBleLedSwitch(mContext!!, it.bleDevice, ledSwitch) - } - //远程控制 - mMapDeviceBean?.let { - mTrackerSetViewModel.setLedSwitch(null, it.deviceServerId, ledSwitch) - } - setLedState(ledSwitch) + mMapDeviceBean?.let { + if (BleManager.getInstance().isConnected(it.deviceMacId)) { + //蓝牙控制 + getBleTrackDeviceBean(false)?.let { ble -> + SRBleUtil.instance.setBleLedSwitch(mContext!!, ble.bleDevice, ledSwitch) + } + } else { + setLedState(ledSwitch) + //远程控制 + mLedLightViewModel.setLedSwitch( + null, it.deviceServerId, ledSwitch, ConstantInt.Type2 + ) + } + } } } diff --git a/app/src/main/java/com/abbidot/tracker/ui/fragment/pet/PetV2Fragment.kt b/app/src/main/java/com/abbidot/tracker/ui/fragment/pet/PetV2Fragment.kt index f9deca3..b6e0cff 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/fragment/pet/PetV2Fragment.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/fragment/pet/PetV2Fragment.kt @@ -87,13 +87,13 @@ class PetV2Fragment : BaseFragment(FragmentPetV2Binding::i activity?.apply { mHomeV2Activity = this as HomeV2Activity } + (mFragments[1] as HomeTrackFragment).onResume() //其他页面是否选择了宠物 if (mCurrentShowPetPos != mHomeV2Activity.mSelectPetPosition) { showPetNameAndHead(mHomeV2Activity.mSelectPetPosition) } else { (mFragments[1] as HomeTrackFragment).getPetTrackerInfoData() } - (mFragments[1] as HomeTrackFragment).onResume() } override fun onPause() { diff --git a/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleCmdUtil.kt b/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleCmdUtil.kt index d5fe277..e3ee45d 100644 --- a/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleCmdUtil.kt +++ b/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleCmdUtil.kt @@ -175,13 +175,21 @@ class SRBleCmdUtil private constructor() { } /** - * 关机 + * 关机,设备会上报关机状态后关机 */ fun shutdownDevice(): ByteArray { val byteArray = byteArrayOf(0x04, CMD_WRITE.toByte()) return getCrc8Cmd(byteArray) } + /** + * 强制关机消息,设备不会上报,立马关机 + */ + fun forcedShutdown(): ByteArray { + val byteArray = byteArrayOf(0x18, CMD_WRITE.toByte()) + return getCrc8Cmd(byteArray) + } + /** * 获取固件版本号 */ @@ -350,5 +358,14 @@ class SRBleCmdUtil private constructor() { val byteArray = byteArrayOf(0x13, CMD_READ.toByte(), 0) return getCrc8Cmd(byteArray) } + + /** + * 设置/查询定位时间间隔 + */ + fun setAndRedGpsDuration(writeAndRed: Int = CMD_WRITE, duration: Long = 0): ByteArray { + var byteArray = byteArrayOf(0x12, writeAndRed.toByte()) + byteArray = byteArray.plus(longTo2ByteArray(duration)) + return getCrc8Cmd(byteArray) + } } diff --git a/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleUtil.kt b/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleUtil.kt index 3a41301..1f2ca2d 100644 --- a/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleUtil.kt +++ b/app/src/main/java/com/abbidot/tracker/util/bluetooth/SRBleUtil.kt @@ -439,6 +439,9 @@ class SRBleUtil private constructor() { fun cancelBleScan(log: String = "") { if (BleManager.getInstance().scanSate == BleScanState.STATE_SCANNING) { isScanInterrupt = true + XEventBus.post( + EventName.ActionConDeviceState, ConState.DEVICE_NOT_FOUND + ) if (TextUtils.isEmpty(log)) LogUtil.e("正在扫描设备,取消蓝牙扫描") else LogUtil.e(log) BleManager.getInstance().cancelScan() diff --git a/app/src/main/java/com/abbidot/tracker/vm/ConnectionDeviceViewModel.kt b/app/src/main/java/com/abbidot/tracker/vm/ConnectionDeviceViewModel.kt index 1125adf..b22ae16 100644 --- a/app/src/main/java/com/abbidot/tracker/vm/ConnectionDeviceViewModel.kt +++ b/app/src/main/java/com/abbidot/tracker/vm/ConnectionDeviceViewModel.kt @@ -118,17 +118,17 @@ class ConnectionDeviceViewModel : ViewModel() { /** * 连接中倒计时20s变为未连接状态 */ - fun connectingFailCountDown() { - mCountDownTimer = object : CountDownTimer(20 * 1000, 1000) { - override fun onTick(time: Long) { - } - - override fun onFinish() { - LogUtil.e("连接中倒计时20s变为未连接状态") - XEventBus.post(EventName.ActionConDeviceState, ConState.CONNECTION_FAIL) - } - }.start() - } +// fun connectingFailCountDown() { +// mCountDownTimer = object : CountDownTimer(20 * 1000, 1000) { +// override fun onTick(time: Long) { +// } +// +// override fun onFinish() { +// LogUtil.e("连接中倒计时20s变为未连接状态") +// XEventBus.post(EventName.ActionConDeviceState, ConState.CONNECTION_FAIL) +// } +// }.start() +// } /** * 连接成功后取消倒计时 @@ -276,7 +276,7 @@ class ConnectionDeviceViewModel : ViewModel() { super.onCleared() LogUtil.e("ConnectionDeviceViewModel,onCleared") SRBleUtil.instance.isBleConnecting = false - SRBleUtil.instance.cancelBleScan("退出APP,取消扫描蓝") + SRBleUtil.instance.cancelBleScan("onCleared,退出当前页面,取消扫描蓝牙") cancelFailCountDown() } } \ No newline at end of file diff --git a/app/src/main/java/com/abbidot/tracker/vm/MapLiveViewModel.kt b/app/src/main/java/com/abbidot/tracker/vm/MapLiveViewModel.kt index 37a212a..e6785d5 100644 --- a/app/src/main/java/com/abbidot/tracker/vm/MapLiveViewModel.kt +++ b/app/src/main/java/com/abbidot/tracker/vm/MapLiveViewModel.kt @@ -23,10 +23,12 @@ class MapLiveViewModel : ViewModel() { /** * 打开关闭直播 */ - fun setupDeviceLiveStatus(activity: BaseActivity<*>, deviceId: String, liveState: Int) { + fun setupDeviceLiveStatus( + activity: BaseActivity<*>, deviceId: String, liveState: Int, modeType: Int + ) { activity.showLoading(true) viewModelScope.launch { - val result = NetworkApi.setupDeviceLiveStatus(deviceId, liveState) + val result = NetworkApi.setupDeviceLiveStatus(deviceId, liveState, modeType) mMapLiveStatusLiveData.value = result } } @@ -60,7 +62,7 @@ class MapLiveViewModel : ViewModel() { /** * 停止获取数据 */ - fun stopGetData() { + fun stopGetData() { if (null != mCountDownTimer) { mCountDownTimer!!.cancel() mCountDownTimer = null diff --git a/app/src/main/java/com/abbidot/tracker/vm/TrackerSetViewModel.kt b/app/src/main/java/com/abbidot/tracker/vm/TrackerSetViewModel.kt index 47041a7..a80353b 100644 --- a/app/src/main/java/com/abbidot/tracker/vm/TrackerSetViewModel.kt +++ b/app/src/main/java/com/abbidot/tracker/vm/TrackerSetViewModel.kt @@ -17,24 +17,12 @@ import kotlinx.coroutines.launch */ class TrackerSetViewModel : ViewModel() { val mAddBindDeviceLiveData = MutableLiveData>() - val mLedSwitchLiveData = MutableLiveData>() val mTurnoffLiveData = MutableLiveData>() val mReportIntervalLiveData = MutableLiveData>() val mSetLiveTimeLiveData = MutableLiveData>() val mUnbindDeviceLiveData = MutableLiveData>() val mAssignOtherTrackerLiveData = MutableLiveData>() - /** - * 设置ledSwitch开关 - */ - fun setLedSwitch(activity: BaseActivity<*>?, deviceInfoId: String, ledSwitch: Int) { - activity?.showLoading(true) - viewModelScope.launch { - val result = NetworkApi.setLedSwitch(deviceInfoId, ledSwitch) - mLedSwitchLiveData.value = result - } - } - /** * 关闭设备 */ @@ -49,10 +37,12 @@ class TrackerSetViewModel : ViewModel() { /** * 设置设备上报下发时间 */ - fun reportInterval(activity: BaseActivity<*>, deviceInfoId: String, gnssInterval: Int) { + fun reportInterval( + activity: BaseActivity<*>, deviceInfoId: String, gnssInterval: Int, modeType: Int + ) { activity.showLoading(true) viewModelScope.launch { - val result = NetworkApi.reportInterval(deviceInfoId, gnssInterval) + val result = NetworkApi.reportInterval(deviceInfoId, gnssInterval, modeType) mReportIntervalLiveData.value = result } } diff --git a/app/src/main/res/layout/layout_live_v2_data_info.xml b/app/src/main/res/layout/layout_live_v2_data_info.xml index 26364ea..ca553d7 100644 --- a/app/src/main/res/layout/layout_live_v2_data_info.xml +++ b/app/src/main/res/layout/layout_live_v2_data_info.xml @@ -23,7 +23,7 @@ + android:paddingHorizontal="@dimen/dp_30">