diff --git a/app/build.gradle b/app/build.gradle index a215198..92b76e2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,9 +28,9 @@ android { applicationId "com.abbidot.tracker" minSdkVersion 23 targetSdkVersion 35 - versionCode 2110 -// versionName "2.1.10" - versionName "2.1.10-Beta10" + versionCode 2111 +// versionName "2.1.11" + versionName "2.1.11-Beta1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/abbidot/tracker/adapter/HomePetTrackStateAdapter.kt b/app/src/main/java/com/abbidot/tracker/adapter/HomePetTrackStateAdapter.kt index d99e469..44a1fad 100644 --- a/app/src/main/java/com/abbidot/tracker/adapter/HomePetTrackStateAdapter.kt +++ b/app/src/main/java/com/abbidot/tracker/adapter/HomePetTrackStateAdapter.kt @@ -9,6 +9,7 @@ import com.abbidot.tracker.R import com.abbidot.tracker.bean.MenuTxtBean import com.abbidot.tracker.constant.ConstantInt import com.abbidot.tracker.constant.MultipleEntity +import com.abbidot.tracker.util.ViewUtil import com.abbidot.tracker.widget.BatteryView import com.abbidot.tracker.widget.MyBluetoothAnimView import com.abbidot.tracker.widget.TypefaceTextView @@ -27,12 +28,13 @@ class HomePetTrackStateAdapter( val stateTextView = holder!!.getView(R.id.tv_home_pet_device_state_item) as TypefaceTextView stateTextView.text = item.menuName - holder.getTextView(R.id.tv_home_pet_device_state_name_item).apply { + val stateName = holder.getTextView(R.id.tv_home_pet_device_state_name_item).apply { text = item.menuValue val color = if (item.type == ConstantInt.SpecialType) R.color.grey_color else item.colorRedId setTextColor(ContextCompat.getColor(mContext, color)) } + val btnState = holder.getImageView(R.id.iv_home_pet_btn_state) val color = if (item.type == ConstantInt.SpecialType) R.color.grey_color else R.color.data_black_color @@ -43,7 +45,9 @@ class HomePetTrackStateAdapter( holder.getView(R.id.mba_home_pet_device_search_anim_item) as MyBluetoothAnimView when (item.menuType) { MultipleEntity.IMG_TEXT_IMG -> { + stateName.visibility = View.VISIBLE bluetoothAnimView.visibility = View.GONE + btnState.visibility = View.GONE bv.visibility = View.VISIBLE bv.setValue(item.imageId) bluetoothAnimView.setBluetoothAnimStartAndStop(item.isSwitch) @@ -51,8 +55,10 @@ class HomePetTrackStateAdapter( } MultipleEntity.TEXT_TEXT_IMG -> { + stateName.visibility = View.VISIBLE bluetoothAnimView.visibility = View.VISIBLE bv.visibility = View.GONE + btnState.visibility = View.GONE bluetoothAnimView.setBluetoothAnimStartAndStop(item.isSwitch) stateTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) } @@ -73,6 +79,16 @@ class HomePetTrackStateAdapter( null, drawable, null, null ) } + btnState.apply { + ViewUtil.instance.viewRotationAnimator(this, true) + visibility = if (item.state == ConstantInt.Type1) { + stateName.visibility = View.GONE + View.VISIBLE + } else { + stateName.visibility = View.VISIBLE + View.GONE + } + } } } } diff --git a/app/src/main/java/com/abbidot/tracker/base/BaseActivity.kt b/app/src/main/java/com/abbidot/tracker/base/BaseActivity.kt index 5ea34b1..e631005 100644 --- a/app/src/main/java/com/abbidot/tracker/base/BaseActivity.kt +++ b/app/src/main/java/com/abbidot/tracker/base/BaseActivity.kt @@ -551,6 +551,7 @@ abstract class BaseActivity(val inflater: (inflater: LayoutInfl showLoading: Boolean = false, isShowNoDataTip: Boolean = true, isShowRequestErrorTip: Boolean = true, + isShowCodeError: Boolean = true, errorTip: String = getString(R.string.txt_net_error) ) { try { @@ -566,7 +567,7 @@ abstract class BaseActivity(val inflater: (inflater: LayoutInfl getResultCallback.onRequestError(exceptionCode) } //拦截请求异常code - if (netErrorCodeTips(exceptionCode)) { + if (netErrorCodeTips(exceptionCode, isShowCodeError)) { //已经处理相关错误码就直接返回 getResultCallback.onErrorCode() return @@ -606,108 +607,120 @@ abstract class BaseActivity(val inflater: (inflater: LayoutInfl /** * 网络请求错误code提示 */ - private fun netErrorCodeTips(exceptionCode: String): Boolean { + private fun netErrorCodeTips(exceptionCode: String, isShowCodeError: Boolean = true): Boolean { //设备已过期,请续费 when (exceptionCode) { ErrorCode.DEVICE_RENEWAL.toString() -> { - showToast(R.string.txt_device_renewal) + if (isShowCodeError) showToast(R.string.txt_device_renewal) return true } //TOKEN失效或者过期 ErrorCode.TOKEN_OVERDUE.toString() -> { - showToast(R.string.txt_token_overdue) + if (isShowCodeError) showToast(R.string.txt_token_overdue) return true } //用户名或密码错误 ErrorCode.USER_PASSWORD_ERROR.toString() -> { - showToast(R.string.txt_user_password_error, gravity = Gravity.CENTER) + if (isShowCodeError) showToast( + R.string.txt_user_password_error, gravity = Gravity.CENTER + ) return true } //验证码错误 ErrorCode.VERIFY_CODE_ERROR.toString() -> { - showToast(R.string.txt_verify_code_error, gravity = Gravity.CENTER) + if (isShowCodeError) showToast( + R.string.txt_verify_code_error, gravity = Gravity.CENTER + ) return true } //验证码已过期 ErrorCode.VERIFY_CODE_EXPIRE.toString() -> { - showToast(R.string.txt_verify_code_expire, gravity = Gravity.CENTER) + if (isShowCodeError) showToast( + R.string.txt_verify_code_expire, gravity = Gravity.CENTER + ) return true } //注册失败 ErrorCode.REGISTER_FAIL.toString() -> { - showToast(R.string.txt_register_fail, gravity = Gravity.CENTER) + if (isShowCodeError) showToast(R.string.txt_register_fail, gravity = Gravity.CENTER) return true } //用户不存在 ErrorCode.USER_NO_EXIST.toString() -> { - showToast(R.string.txt_user_no_exist, gravity = Gravity.CENTER) + if (isShowCodeError) showToast(R.string.txt_user_no_exist, gravity = Gravity.CENTER) return true } //用户已存在 ErrorCode.USER_HAS_EXIST.toString() -> { - if (!isInterceptNetErrorCodeTip) { + if (!isInterceptNetErrorCodeTip && isShowCodeError) { showToast(R.string.txt_user_has_exist, gravity = Gravity.BOTTOM) } return true } //邮箱格式不对 ErrorCode.EMAIL_FORMAT_ERROR.toString() -> { - showToast(R.string.txt_email_format_error, gravity = Gravity.CENTER) + if (isShowCodeError) showToast( + R.string.txt_email_format_error, gravity = Gravity.CENTER + ) return true } //不能分享给自己 ErrorCode.NO_SHARE_MYSELF.toString() -> { - showToast(R.string.txt_no_share_myself) + if (isShowCodeError) showToast(R.string.txt_no_share_myself) return true } //当前用户已经绑定该设备 ErrorCode.DEVICE_HAS_BOUND.toString() -> { - showToast(R.string.txt_device_has_bound) + if (isShowCodeError) showToast(R.string.txt_device_has_bound) return true } //该设备已被绑定 ErrorCode.DEVICE_HAS_BIND.toString() -> { - showToast(R.string.txt_device_has_bind) + if (isShowCodeError) showToast(R.string.txt_device_has_bind) return true } //设备不存在 ErrorCode.DEVICE_NOT_EXIST.toString() -> { - showToast(R.string.txt_no_dfu) + if (isShowCodeError) showToast(R.string.txt_no_dfu) return true } //系统异常 "1001" -> { - showToast(R.string.txt_system_error, gravity = Gravity.CENTER) + if (isShowCodeError) showToast(R.string.txt_system_error, gravity = Gravity.CENTER) return true } "1002" -> { - showToast(R.string.txt_missing_param, gravity = Gravity.CENTER) + if (isShowCodeError) showToast(R.string.txt_missing_param, gravity = Gravity.CENTER) return true } "1003" -> { - showToast(R.string.txt_tracker_busy, gravity = Gravity.CENTER) + if (isShowCodeError) showToast(R.string.txt_tracker_busy, gravity = Gravity.CENTER) return true } "1004" -> { - showToast(R.string.txt_tracker_offline, gravity = Gravity.CENTER) + if (isShowCodeError) showToast( + R.string.txt_tracker_offline, gravity = Gravity.CENTER + ) return true } "1005" -> { - showToast(R.string.txt_tracker_live, gravity = Gravity.CENTER) + if (isShowCodeError) showToast(R.string.txt_tracker_live, gravity = Gravity.CENTER) return true } "1006" -> { - showToast(R.string.txt_time_out_try_again, gravity = Gravity.CENTER) + if (isShowCodeError) showToast( + R.string.txt_time_out_try_again, gravity = Gravity.CENTER + ) return true } "1007" -> { - showToast(R.string.txt_abnormity, gravity = Gravity.CENTER) + if (isShowCodeError) showToast(R.string.txt_abnormity, gravity = Gravity.CENTER) return true } diff --git a/app/src/main/java/com/abbidot/tracker/base/BaseFragment.kt b/app/src/main/java/com/abbidot/tracker/base/BaseFragment.kt index f02c09b..f7763a5 100644 --- a/app/src/main/java/com/abbidot/tracker/base/BaseFragment.kt +++ b/app/src/main/java/com/abbidot/tracker/base/BaseFragment.kt @@ -36,7 +36,7 @@ abstract class BaseFragment( var mLoadingDialog: QMUITipDialog? = null //防止某个时间执行多次 - private var mLimitExecutionTime = 0L + private var mLimitExecutionTime = 0L /** * Fragment中嵌套子Fragment时,如果父Fragment被销毁而子Fragment未被销毁,会导致子Fragment的视图不再显示‌ @@ -173,10 +173,17 @@ abstract class BaseFragment( showLoading: Boolean = false, isShowNoDataTip: Boolean = true, isRequestErrorTip: Boolean = true, + isShowCodeError: Boolean = true, errorTip: String = getString(R.string.txt_net_error) ) { (activity as BaseActivity<*>).dealRequestResult( - it, getResultCallback, showLoading, isShowNoDataTip, isRequestErrorTip, errorTip + it, + getResultCallback, + showLoading, + isShowNoDataTip, + isRequestErrorTip, + isShowCodeError, + errorTip ) } } \ No newline at end of file diff --git a/app/src/main/java/com/abbidot/tracker/bean/MenuTxtBean.kt b/app/src/main/java/com/abbidot/tracker/bean/MenuTxtBean.kt index 2556b9f..6fdccdc 100644 --- a/app/src/main/java/com/abbidot/tracker/bean/MenuTxtBean.kt +++ b/app/src/main/java/com/abbidot/tracker/bean/MenuTxtBean.kt @@ -16,23 +16,24 @@ data class MenuTxtBean( var imageUrl: String, var isSwitch: Boolean, var type: Int, + var state: Int, @MultipleEntity val menuType: Int ) : MultiItemEntity { //设置空的构造方法 - constructor(@MultipleEntity menuType: Int) : this("", "", 0, 0, "", false, 0, menuType) + constructor(@MultipleEntity menuType: Int) : this("", "", 0, 0, "", false, 0, 0, menuType) //设置多个构造方法 constructor(menuName: String, menuValue: String, @MultipleEntity menuType: Int) : this( - menuName, menuValue, 0, 0, "", false, 0, menuType + menuName, menuValue, 0, 0, "", false, 0, 0, menuType ) constructor(menuName: String, menuValue: String) : this( - menuName, menuValue, 0, 0, "", false, 0, MultipleEntity.TEXT + menuName, menuValue, 0, 0, "", false, 0, 0, MultipleEntity.TEXT ) constructor(menuName: String, imageId: Int, menuValue: String) : this( - menuName, menuValue, imageId, 0, "", false, 0, MultipleEntity.TEXT + menuName, menuValue, imageId, 0, "", false, 0, 0, MultipleEntity.TEXT ) @MultipleEntity 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 244500a..62882b7 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 @@ -108,8 +108,7 @@ class AddNewTracker3Activity : } else if (ble.conState == ConState.CONNECTION_FAIL) { setNoConnectState() mViewBinding.ivAddNewTracker3RefreshBtn.isEnabled = true - } - else{ + } else { mViewBinding.ivAddNewTracker3RefreshBtn.isEnabled = true } } @@ -216,6 +215,17 @@ class AddNewTracker3Activity : mScanDeviceAdapter.notifyItemRangeInserted(list.size - 1, 1) } } + } else if (null != name && name.contains("Pet_")) { + DeviceBean().let { + it.type = getDeviceType("typeName") + it.deviceOutId = scanRecord.sliceArray(45..45 + 6).decodeToString() + it.macId = mac + it.deviceName = name + mScanDeviceAdapter.getData().let { list -> + list.add(it) + mScanDeviceAdapter.notifyItemRangeInserted(list.size - 1, 1) + } + } } } } 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 35d79ab..c8e8d0b 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 @@ -19,6 +19,7 @@ import com.abbidot.tracker.base.BaseDialog import com.abbidot.tracker.bean.BleTrackDeviceBean 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 @@ -33,6 +34,7 @@ import com.abbidot.tracker.vm.TrackerInfoViewModel import com.clj.fastble.BleManager import com.daimajia.androidanimations.library.Techniques import com.daimajia.androidanimations.library.YoYo +import com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView /** @@ -135,6 +137,7 @@ class LedLightActivity : BaseActivity(ActivityLedLightB mViewBinding.apply { + ViewUtil.instance.viewRotationAnimator(ilLedLightBtnState.ivLedBtnState, true) ilLedLightIssueLayout.let { it.tvIssueOneBigTitle.setText(R.string.txt_led_light_set) it.tvIssueTwoSmallOneTitle.setText(R.string.txt_bluetooth_setup) @@ -221,6 +224,47 @@ class LedLightActivity : BaseActivity(ActivityLedLightB } } } + //接收发送指令后设备返回的数据 + XEventBus.observe(this, EventName.DeviceReceiveData) { receiveData: ReceiveDeviceData -> + mPetBean?.apply { + if (macID == receiveData.mac) { + parseData(receiveData.data) + } + } + } + } + + 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 == 3 && data1 == 1) { + val data3 = SRBleCmdUtil.instance.byteToInt(data[3]) + val ledSwitch = if (data3 > 0) { + mViewBinding.ledLightOpenAndClose.switch.isChecked = true + ConstantInt.Open + } else { + mViewBinding.ledLightOpenAndClose.switch.isChecked = false + ConstantInt.Close + } + mMapDeviceBean?.ledSwitch = ledSwitch + val modeType = if (data2 == 0) { + ConstantInt.Type1 + } else { + ConstantInt.Type3 + } + mMapDeviceBean?.let { + mViewBinding.ledLightOpenAndClose.accessoryType = + QMUICommonListItemView.ACCESSORY_TYPE_SWITCH + mViewBinding.ilLedLightBtnState.root.visibility = View.GONE + //远程控制 + mLedLightViewModel.setLedSwitch( + null, it.deviceServerId, ledSwitch, modeType + ) + } + } + } } private fun setDeviceData(mapDeviceBean: MapDeviceBean) { @@ -241,17 +285,7 @@ class LedLightActivity : BaseActivity(ActivityLedLightB private fun updateDisabledState(mapDeviceBean: MapDeviceBean) { mapDeviceBean.apply { - if (SRBleUtil.instance.isMacConnect(deviceMacId)) { - setDisabledState(false) - } else { - //是否超时上报 - val isTimeoutReport = Util.isTimeoutReport(updateTime) - if (powerSwitch == ConstantInt.Type0 || powerSwitch == ConstantInt.Type2 || powerSwitch == ConstantInt.Type3 || inWifiZone == ConstantInt.Type1 || isTimeoutReport) { - setDisabledState(true) - } else { - setDisabledState(false) - } - } + setDisabledState(!Util.getLedControlState(deviceMacId,mapDeviceBean)) } } @@ -423,12 +457,24 @@ class LedLightActivity : BaseActivity(ActivityLedLightB private fun setLedSwitch() { mViewBinding.ledLightOpenAndClose.switch.apply { mMapDeviceBean?.let { - if (isChecked) { - it.ledSwitch = ConstantInt.Open - setBleLedMode(it.ledMode) + mViewBinding.ledLightOpenAndClose.accessoryType = + QMUICommonListItemView.ACCESSORY_TYPE_NONE + mViewBinding.ilLedLightBtnState.root.visibility = View.VISIBLE + val ledSwitch = if (it.ledSwitch == ConstantInt.Open) { + ConstantInt.Close } else { - it.ledSwitch = ConstantInt.Close - setBleLedMode(0) + ConstantInt.Open + } + if (BleManager.getInstance().isConnected(it.deviceMacId)) { + //蓝牙控制 + mBleTrackDeviceBean?.apply { + SRBleUtil.instance.setBleLedSwitch(mContext, bleDevice, ledSwitch) + } + } else { + //远程控制 + mLedLightViewModel.setLedSwitch( + null, it.deviceServerId, ledSwitch, ConstantInt.Type2 + ) } } } diff --git a/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/LedLightActivityV0.kt b/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/LedLightActivityV0.kt new file mode 100644 index 0000000..677e2b8 --- /dev/null +++ b/app/src/main/java/com/abbidot/tracker/ui/activity/device/set/LedLightActivityV0.kt @@ -0,0 +1,467 @@ +package com.abbidot.tracker.ui.activity.device.set + +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.view.Gravity +import android.view.View +import androidx.activity.viewModels +import androidx.core.content.ContextCompat +import androidx.core.view.isGone +import com.abbidot.baselibrary.constant.ConState +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 +import com.abbidot.tracker.adapter.LedLightColorAdapter +import com.abbidot.tracker.base.BaseActivity +import com.abbidot.tracker.base.BaseDialog +import com.abbidot.tracker.bean.BleTrackDeviceBean +import com.abbidot.tracker.bean.MapDeviceBean +import com.abbidot.tracker.bean.PetBean +import com.abbidot.tracker.constant.ConstantInt +import com.abbidot.tracker.constant.ConstantString +import com.abbidot.tracker.constant.GetResultCallback +import com.abbidot.tracker.databinding.ActivityLedLightBinding +import com.abbidot.tracker.deprecated.ui.activity.vm.LedLightViewModel +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.TrackerInfoViewModel +import com.clj.fastble.BleManager +import com.daimajia.androidanimations.library.Techniques +import com.daimajia.androidanimations.library.YoYo + + +/** + * LedLight颜色光源设置 + */ +class LedLightActivityV0 : BaseActivity(ActivityLedLightBinding::inflate) { + + private val mLedLightViewModel: LedLightViewModel by viewModels() + private val mTrackerManageSetViewModel: TrackerInfoViewModel by viewModels() + private val mConnectionDeviceViewModel: ConnectionDeviceViewModel by viewModels() + + private var mPetBean: PetBean? = null + private var mMapDeviceBean: MapDeviceBean? = null + private var mOldMapDeviceBean: MapDeviceBean? = null + private var mBleTrackDeviceBean: BleTrackDeviceBean? = null + private lateinit var mLedLightColorAdapter: LedLightColorAdapter + private lateinit var mLedModeList: MutableList + + //防止多次按返回键执行 + private var isFinishSave = false + + //禁用模式 + private var isDisabledMode = true + + override fun getTopBar() = mViewBinding.ilLedLightBar.titleTopBar + + override fun initData() { + super.initData() + setTopBarTitle(R.string.tracker_manage_set_led) + setLeftBackImage(R.drawable.icon_white_back_svg) +// initStatus() + + mPetBean = Util.getParcelableAdaptive(intent, ConstantString.Pet, PetBean::class.java) + + mLedModeList = mutableListOf( + getString(R.string.tracker_light_mode_sustained), + getString(R.string.tracker_light_mode_breathing), +// getString(R.string.tracker_light_mode_slow_flash), + getString(R.string.tracker_light_mode_flash) + ) + + ViewUtil.instance.showQMUICommonListItemView( + mContext, + mViewBinding.ledLightOpenAndClose, + null, + getString(R.string.tracker_manage_set_led) + ) + + val builder = ViewUtil.instance.showBottomSheetList(mContext, { dialog, _, position, _ -> + mMapDeviceBean?.apply { + dialog.dismiss() + ledMode = position + 1 + mViewBinding.ledLightMode.detailText = mLedModeList[position] + mViewBinding.ledLightOpenAndClose.switch.let { + if (!it.isChecked) { + it.isChecked = true + } + setBleLedMode(ledMode) + } + } + }) + for (i in 0 until mLedModeList.size) builder.addItem(mLedModeList[i]) + + mViewBinding.ledLightMode.apply { + ViewUtil.instance.showQMUICommonListItemView(mContext, this, { + if (!isDisabledMode) builder.build().show() + }, getString(R.string.txt_light_mode)) +// mMapDeviceBean?.apply { +// detailText = when { +// ledMode - 1 >= mLedModeList.size -> { +// mLedModeList[mLedModeList.size - 1] +// } +// +// ledMode == 0 -> { +// mLedModeList[0] +// } +// +// else -> mLedModeList[ledMode - 1] +// } +// } + } + + val colorListResId = mutableListOf( + R.color.white, + R.color.colormenu, + R.color.corner_color, + R.color.blue_light, + R.color.deep_blue, + R.color.red_blue, + R.color.yellow_color, + R.color.yellow_red_color + ) + mLedLightColorAdapter = LedLightColorAdapter(mContext, colorListResId) + mLedLightColorAdapter.setOnItemClickListener(object : + BaseRecyclerAdapter.OnItemClickListener { + override fun onItemClick(itemView: View?, pos: Int) { + setLedLightColor(ContextCompat.getColor(mContext, colorListResId[pos])) + } + }) + + + mViewBinding.apply { + ilLedLightIssueLayout.let { + it.tvIssueOneBigTitle.setText(R.string.txt_led_light_set) + it.tvIssueTwoSmallOneTitle.setText(R.string.txt_bluetooth_setup) + it.tvIssueTwoSmallOneTitle.setText(R.string.txt_bluetooth_setup) + it.tvIssueTwoSmallTitleOneContent.setText(R.string.txt_bluetooth_setup_dec) + it.tvIssueTwoSmallTwoTitle.setText(R.string.txt_network_setup) + it.tvIssueTwoSmallTitleTwoContent.setText(R.string.txt_network_setup_dec) + } + ViewUtil.instance.setRecyclerViewGridLayout( + mContext, + colorSelectRecyclerView, + mLedLightColorAdapter, + spanCount = 2, + bottom = AppUtils.dpToPx(9), + itemWidth = AppUtils.dpToPx(30), + offset = AppUtils.dpToPx(290) + ) + + selectColorPaintView.setOnColorSelectListener { + setLedLightColor(it) + } + + setOnClickListenerViews( + ledLightBluetoothTips.trbBleConnectState, + btnLedLightSetSave, + btnLedLightIssue, + ilLedLightIssueLayout.tvCloseIssueBtn, + mViewBinding.ledLightOpenAndClose.switch + ) + } + + setDisabledState(true) + mPetBean?.apply { + //查找是否连接了蓝牙 + SRBleUtil.instance.getConnectMacDevice(macID)?.let { + updateConState(it, false) + } + mTrackerManageSetViewModel.getPetTrackerInfo(this@LedLightActivityV0, deviceId) + } + } + + override fun liveDataObserve() { + mTrackerManageSetViewModel.mTrackerInfoLiveData.observe(this) { + dealRequestResult(it, object : GetResultCallback { + override fun onResult(any: Any) { + val data = it.getOrNull() + data?.apply { + mMapDeviceBean = data + mOldMapDeviceBean = data.copy() + setDeviceData(data) + } + } + }) + } + mLedLightViewModel.mSetLedLightLiveData.observe(this) { + dealRequestResult(it, object : GetResultCallback { + override fun onResult(any: Any) { + showToast(R.string.txt_change_successful, isFinish = true) + } + + override fun onRequestError(exceptionCode: String?) { + isFinishSave = false + mViewBinding.btnLedLightSetSave.isEnabled = true + } + }) + } + + //接收开蓝牙操作,然后搜索连接设备 + XEventBus.observe(this, EventName.ActionConDeviceState) { conState: Int -> + mViewBinding.ledLightBluetoothTips.trbBleConnectState.let { view -> + if (!isDisabledMode) { + ViewUtil.instance.bleConActionState(this, view, conState) + } + } + } + //接收蓝牙连接状态 + XEventBus.observe(this, EventName.ConnectDeviceState) { ble: BleTrackDeviceBean -> + mPetBean?.apply { + if (ble.mac == macID) { + mMapDeviceBean?.let { + updateDisabledState(it) + } + updateConState(ble) + } + } + } + } + + private fun setDeviceData(mapDeviceBean: MapDeviceBean) { + mapDeviceBean.apply { + mViewBinding.let { + it.ledLightOpenAndClose.switch.isChecked = ledSwitch == ConstantInt.Open + + setLedLightColor( + Color.rgb(ledRedValue, ledGreenValue, ledBlueValue), true + ) + if (ledMode == 0 || ledMode > mLedModeList.size) ledMode = 1 + it.ledLightMode.detailText = mLedModeList[ledMode - 1] + + updateDisabledState(this) + } + } + } + + private fun updateDisabledState(mapDeviceBean: MapDeviceBean) { + mapDeviceBean.apply { + if (SRBleUtil.instance.isMacConnect(deviceMacId)) { + setDisabledState(false) + } else { + //是否超时上报 + val isTimeoutReport = Util.isTimeoutReport(updateTime) + if (powerSwitch == ConstantInt.Type0 || powerSwitch == ConstantInt.Type2 || powerSwitch == ConstantInt.Type3 || inWifiZone == ConstantInt.Type1 || isTimeoutReport) { + setDisabledState(true) + } else { + setDisabledState(false) + } + } + } + } + + private fun setDisabledState(isDisabled: Boolean) { + isDisabledMode = isDisabled + mViewBinding.apply { + val tColor = if (isDisabled) { + btnLedLightSetSave.visibility = View.GONE + ledLightBluetoothTips.root.visibility = View.GONE + R.color.grey_color + } else { + btnLedLightSetSave.visibility = View.VISIBLE + ledLightBluetoothTips.root.visibility = View.VISIBLE + R.color.qmui_config_color_gray_1 + } + ledLightOpenAndClose.textView.setTextColor(ContextCompat.getColor(mContext, tColor)) + ledLightMode.textView.setTextColor(ContextCompat.getColor(mContext, tColor)) + } + } + + /** + * 更新设备连接状态 + */ + private fun updateConState(trackBleDevice: BleTrackDeviceBean, isShowToast: Boolean = true) { + mBleTrackDeviceBean = trackBleDevice + mViewBinding.ledLightBluetoothTips.trbBleConnectState.let { view -> + val bgColor = if (trackBleDevice.conState == ConState.CONNECTED) { + view.text = getString(R.string.tracker_manage_set_ble_connect) + ContextCompat.getColor(mContext, R.color.cyan_color1) + } else { + view.text = getString(R.string.tracker_manage_set_ble_unconnect) + ContextCompat.getColor(mContext, R.color.red_color4) + } + view.setBackgroundColor(bgColor) + } + if (!isDisabledMode && isShowToast) { + ViewUtil.instance.bleConStateToast(this, trackBleDevice.conState, Gravity.CENTER) + } + } + + private fun setBleLedMode(mode: Int) { + mBleTrackDeviceBean?.apply { + SRBleUtil.instance.setBleLedSwitch(mContext, bleDevice, mode) + } + } + + override fun leftBackOnClick() { + if (null == mMapDeviceBean || null == mOldMapDeviceBean) { + super.leftBackOnClick() + return + } + if (isFinishSave) return + //是否是蓝牙连接了,修改设备数据返回,同步服务器 + if (null != mBleTrackDeviceBean) { + mMapDeviceBean?.apply { + mOldMapDeviceBean?.let { + if (it == mMapDeviceBean) { + super.leftBackOnClick() + } else { + //判断是否有蓝牙连接 + if (BleManager.getInstance().isConnected(mBleTrackDeviceBean!!.bleDevice)) { + finishAndSave(ConstantInt.Type1) + } else { + super.leftBackOnClick() + } + } + } + } + } else { + super.leftBackOnClick() + } + } + + /** + * 保存设置数据 + */ + private fun finishAndSave(modeType: Int) { + if (null == mMapDeviceBean) { + finish() + return + } + mMapDeviceBean?.apply { + isFinishSave = true + mLedLightViewModel.setLedLight(this@LedLightActivityV0, this, modeType) + } + } + + /** + * @param show 只显示,不作为命令处理 + */ + private fun setLedLightColor(color: Int, show: Boolean = false) { + val drawableColor = ColorDrawable(color) + mViewBinding.currentSelectColor.appHeadImage.setImageDrawable(drawableColor) +// mViewBinding.ledLightBarColorImage.setBackgroundColor(color) + + val red = color and 0xff0000 shr 16 + val green = color and 0x00ff00 shr 8 + val blue = color and 0x0000ff + + mMapDeviceBean?.apply { + ledRedValue = red + ledGreenValue = green + ledBlueValue = blue + } + +// mViewBinding.tvLedLightCurrentRgb.text = String.format("#%06X", -0x1 and color) + mViewBinding.tvLedLightCurrentRgb.text = String.format("#%06X", 0xffffff and color) + + if (!show) { + mBleTrackDeviceBean?.let { + //判断是否有蓝牙连接 + if (BleManager.getInstance().isConnected(it.bleDevice)) { + SRBleUtil.instance.writeData( + it.bleDevice, SRBleCmdUtil.instance.ledColor( + SRBleCmdUtil.CMD_WRITE, red, green, blue + ) + ) + } + } + } + } + + /** + * 断开连接设备 + */ + private fun operateDeviceTips(messageID: Int, type: Int = 0) { + ViewUtil.instance.showDialog(mContext, messageID, object : BaseDialog.OnDialogOkListener { + override fun onOkClick(dialog: BaseDialog<*>) { + dialog.dismiss() + when (type) { + 0 -> { + mBleTrackDeviceBean?.let { + mConnectionDeviceViewModel.disconnect(it.bleDevice) + } + } + } + } + }, okTextResId = R.string.start_txt_yes) + } + + /** + * 手动连接/断开设备 + */ + private fun connectionBtn(btnString: String) { + mPetBean?.apply { + ViewUtil.instance.connectionBtn(mContext, btnString, macID) { + mConnectionDeviceViewModel.connectDeviceToMac(this@LedLightActivityV0, macID) + } + } + } + + /** + * 显示led问题 + */ + private fun showLedIssue() { + mViewBinding.apply { + if (ilLedLightIssueLayout.root.isGone) { + YoYo.with(Techniques.BounceInUp).duration(700).onStart { + ilLedLightIssueLayout.root.visibility = View.VISIBLE + }.playOn(ilLedLightIssueLayout.root) + } else { + YoYo.with(Techniques.SlideOutDown).duration(600).onEnd { + ilLedLightIssueLayout.root.visibility = View.GONE + }.playOn(ilLedLightIssueLayout.root) + } + } + } + + private fun setLedSwitch() { + mViewBinding.ledLightOpenAndClose.switch.apply { + mMapDeviceBean?.let { + if (isChecked) { + it.ledSwitch = ConstantInt.Open + setBleLedMode(it.ledMode) + } else { + it.ledSwitch = ConstantInt.Close + setBleLedMode(0) + } + } + } + } + + override fun onClick(v: View?) { + mViewBinding.apply { + when (v) { + //手动连接设备 + ledLightBluetoothTips.trbBleConnectState -> connectionBtn(ledLightBluetoothTips.trbBleConnectState.text.toString()) + btnLedLightSetSave -> { + val modeType = if (null != mBleTrackDeviceBean && BleManager.getInstance() + .isConnected(mBleTrackDeviceBean!!.bleDevice) + ) ConstantInt.Type1 + else ConstantInt.Type2 + btnLedLightSetSave.isEnabled = false + finishAndSave(modeType) + } + + btnLedLightIssue -> showLedIssue() + ilLedLightIssueLayout.tvCloseIssueBtn -> showLedIssue() + ledLightOpenAndClose.switch -> { + if (isDisabledMode) { + ledLightOpenAndClose.switch.isChecked = + !ledLightOpenAndClose.switch.isChecked + } else setLedSwitch() + } + } + } + } + + override fun onDestroy() { + super.onDestroy() + mViewBinding.selectColorPaintView.recycle() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV3.kt b/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV3.kt index 416369f..65c0654 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV3.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV3.kt @@ -137,6 +137,14 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding isShowFence = Util.getShowFenceSp() mViewBinding.apply { + ViewUtil.instance.viewRotationAnimator( + ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.ilDeviceLightBtnState.ivLedBtnState, + true + ) + ViewUtil.instance.viewRotationAnimator( + ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.ilDeviceLightBtnState.ivLedBtnState, + true + ) ilLiveV2BluetoothFindDevice.ivMapLiveV2BleConState.setValue(0) mFragment = mHomeMapCommon.getMapFragment( mContext, @@ -148,6 +156,32 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding ViewUtil.instance.setMapSwitchLocationButtonImage( ivMapLiveV2RefreshBtn, mShowCenterLocation ) + setLedBtnEnabled(false) + mPetBean?.let { p -> + if (p.deviceType == ConstantInt.Type2) { + ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.tvDeviceLightSwitchTitle.text = + getString(R.string.txt_tone) + ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.tvDeviceLightSwitchTitle.setCompoundDrawablesWithIntrinsicBounds( + R.drawable.icon_sound_image, 0, 0, 0 + ) + ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.tvDeviceLightSwitchTitle.text = + getString(R.string.txt_tone) + ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.tvDeviceLightSwitchTitle.setCompoundDrawablesWithIntrinsicBounds( + R.drawable.icon_sound_image, 0, 0, 0 + ) + } else { + ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.tvDeviceLightSwitchTitle.text = + getString(R.string.txt_light) + ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.tvDeviceLightSwitchTitle.setCompoundDrawablesWithIntrinsicBounds( + R.drawable.icon_light_svg, 0, 0, 0 + ) + ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.tvDeviceLightSwitchTitle.text = + getString(R.string.txt_light) + ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.tvDeviceLightSwitchTitle.setCompoundDrawablesWithIntrinsicBounds( + R.drawable.icon_light_svg, 0, 0, 0 + ) + } + } ilLiveV2OperateLayout.tvLiveV2Speed.text = "--$mSpeedUnit" ilLiveV2OperateLayout.tvLiveV2Distance.text = "--$mDistanceUnit" llLiveV2MapTopPet.ivTopPetBtnSmall.setImageResource(R.drawable.icon_map_type) @@ -258,6 +292,7 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding override fun onResult(any: Any) { val data = it.getOrNull() data?.let { d -> + LogUtil.e("xxxxxxxxxxxxxxxxxxxxx,${d.latitude},${d.longitude}") d.isCloseBattery = isCloseBattery d.isCloseMsg = isCloseMsg mMapDeviceBean = d @@ -282,7 +317,7 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding } else { mPetBean?.apply { //获取首页设备信息状态 - mMapViewModel.getMapDeviceStatus(deviceId, false) + mMapViewModel.getMapDeviceStatus(deviceId, !isLiveJump) } } } @@ -358,15 +393,19 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding //接收蓝牙连接状态 XEventBus.observe(this, EventName.ConnectDeviceState) { trackBle: BleTrackDeviceBean -> - mPetBean?.apply { - if (trackBle.mac == macID && trackBle.conState != ConState.CONNECTED) { + mPetBean?.let { p -> + if (trackBle.mac == p.macID && trackBle.conState != ConState.CONNECTED) { //隐藏蓝牙nearby mViewBinding.ilLiveV3MapDeviceMsg.root.visibility = View.GONE } - } - mMapDeviceBean?.apply { - if (trackBle.mac == deviceMacId) { - updateConState(trackBle) + mMapDeviceBean?.apply { + if (trackBle.mac == deviceMacId) { + updateConState(trackBle) + //分享设备不可以控制灯 + if (p.shared == ConstantInt.NoShare) { + setLedBtnEnabled(Util.getLedControlState(p.macID, this)) + } + } } } } @@ -393,9 +432,30 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding 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) + mPetBean?.apply { + if (!SRBleUtil.instance.isMacConnect(macID)) { + mViewBinding.let { m -> + m.ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.let { i -> + i.cbDeviceLightSwitch.isChecked = isLedOpen + i.cbDeviceLightSwitch.visibility = View.VISIBLE + i.ilDeviceLightBtnState.root.visibility = View.GONE + } + m.ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.let { i -> + i.cbDeviceLightSwitch.isChecked = isLedOpen + i.cbDeviceLightSwitch.visibility = View.VISIBLE + i.ilDeviceLightBtnState.root.visibility = View.GONE + } + } + } + } + } + + override fun onErrorCode() { + setErrorLedState() + } + + override fun onRequestError(exceptionCode: String?) { + setErrorLedState() } }) } @@ -418,6 +478,26 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding } } + private fun setErrorLedState() { + mPetBean?.apply { + if (!SRBleUtil.instance.isMacConnect(macID)) { + isLedOpen = !isLedOpen + mViewBinding.let { m -> + m.ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.let { i -> + i.cbDeviceLightSwitch.isChecked = isLedOpen + i.cbDeviceLightSwitch.visibility = View.VISIBLE + i.ilDeviceLightBtnState.root.visibility = View.GONE + } + m.ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.let { i -> + i.cbDeviceLightSwitch.isChecked = isLedOpen + i.cbDeviceLightSwitch.visibility = View.VISIBLE + i.ilDeviceLightBtnState.root.visibility = View.GONE + } + } + } + } + } + private fun finishActivity() { val intent = Intent() mMapDeviceBean?.let { @@ -483,6 +563,18 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding } } } else if (data0 == 3 && data1 == 1) { + mViewBinding.let { m -> + m.ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.let { i -> + i.cbDeviceLightSwitch.isChecked = isLedOpen + i.cbDeviceLightSwitch.visibility = View.VISIBLE + i.ilDeviceLightBtnState.root.visibility = View.GONE + } + m.ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.let { i -> + i.cbDeviceLightSwitch.isChecked = isLedOpen + i.cbDeviceLightSwitch.visibility = View.VISIBLE + i.ilDeviceLightBtnState.root.visibility = View.GONE + } + } val modeType = if (data2 == 0) { ConstantInt.Type1 } else { @@ -572,24 +664,37 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding * 远程设置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 + mPetBean?.let { p -> + //分享设备不可以点击控制灯 + if (p.shared != ConstantInt.NoShare) { + return + } + isLedOpen = !isLedOpen + mViewBinding.apply { + //屏蔽点击就变状态 + ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.let { + it.cbDeviceLightSwitch.isChecked = !isLedOpen + it.cbDeviceLightSwitch.visibility = View.GONE + it.ilDeviceLightBtnState.root.visibility = View.VISIBLE + } + ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.let { + it.cbDeviceLightSwitch.isChecked = !isLedOpen + it.cbDeviceLightSwitch.visibility = View.GONE + it.ilDeviceLightBtnState.root.visibility = View.VISIBLE + } - mMapDeviceBean?.apply { - this.ledSwitch = ledSwitch - if (BleManager.getInstance().isConnected(deviceMacId)) { - setLedSwitch(ledSwitch) - } else { - mLedLightViewModel.setLedSwitch( - null, deviceServerId, ledSwitch, ConstantInt.Type2 - ) + 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 + ) + } } } } @@ -705,41 +810,21 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding } else { updateConState(bleConDevice) } - } - - mViewBinding.let { - if (deviceType == ConstantInt.Type2) { - it.ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.tvDeviceLightSwitchTitle.text = - getString(R.string.txt_tone) - it.ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.tvDeviceLightSwitchTitle.setCompoundDrawablesWithIntrinsicBounds( - R.drawable.icon_sound_image, 0, 0, 0 - ) - it.ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.tvDeviceLightSwitchTitle.text = - getString(R.string.txt_tone) - it.ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.tvDeviceLightSwitchTitle.setCompoundDrawablesWithIntrinsicBounds( - R.drawable.icon_sound_image, 0, 0, 0 - ) - } else { - it.ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.tvDeviceLightSwitchTitle.text = - getString(R.string.txt_light) - it.ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.tvDeviceLightSwitchTitle.setCompoundDrawablesWithIntrinsicBounds( - R.drawable.icon_light_svg, 0, 0, 0 - ) - it.ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.tvDeviceLightSwitchTitle.text = - getString(R.string.txt_light) - it.ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.tvDeviceLightSwitchTitle.setCompoundDrawablesWithIntrinsicBounds( - R.drawable.icon_light_svg, 0, 0, 0 - ) - } - isLedOpen = ledSwitch == ConstantInt.Open - it.ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.cbDeviceLightSwitch.isChecked = - isLedOpen - it.ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.cbDeviceLightSwitch.isChecked = - isLedOpen + mViewBinding.let { + //分享设备不可以控制灯 + if (shared == ConstantInt.NoShare) { + setLedBtnEnabled(Util.getLedControlState(deviceMacId, mapDeviceBean)) + } + 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) { @@ -761,6 +846,16 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding } } + private fun setLedBtnEnabled(btnEnabled: Boolean) { + mViewBinding.apply { + ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.cbDeviceLightSwitch.isEnabled = btnEnabled + ilLiveV2OperateLayout.ilLiveV2DataLightSwitch.root.isEnabled = btnEnabled + ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.root.isEnabled = btnEnabled + ilLiveV2BluetoothFindDevice.ilLiveV2RadarLightSwitch.cbDeviceLightSwitch.isEnabled = + btnEnabled + } + } + private fun setMapDeviceBean(mapDeviceBean: MapDeviceBean) { mapDeviceBean.apply { mViewBinding.ilLiveV3MapDeviceBatteryLayout.let { @@ -796,7 +891,7 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding mHomeMapCommon.setPetHeadIcon(imgurl, petType) //获取首页设备信息状态 - mMapViewModel.getMapDeviceStatus(deviceId, false) + mMapViewModel.getMapDeviceStatus(deviceId, !isLiveJump) } } 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 b7a53d8..5837810 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 @@ -29,6 +29,7 @@ import com.abbidot.tracker.bean.FencesBean import com.abbidot.tracker.bean.FirmwareBean import com.abbidot.tracker.bean.MapDeviceBean import com.abbidot.tracker.bean.MenuTxtBean +import com.abbidot.tracker.bean.PetBean import com.abbidot.tracker.bean.ReceiveDeviceData import com.abbidot.tracker.bean.WiFiZoneBean import com.abbidot.tracker.constant.ConstantInt @@ -92,6 +93,7 @@ class HomeTrackFragment : private var isDFUCallback = false private var mFirmwareBean: FirmwareBean? = null private var isSwitchPet = true + private var mLedMac = "" companion object { @JvmStatic @@ -288,7 +290,6 @@ class HomeTrackFragment : // LogUtil.e("蓝牙连接,不使用接口数据更新状态") // } else { // } - addMenuListData() setStateData(data) setZoneData(data) } @@ -384,11 +385,54 @@ class HomeTrackFragment : } mLedLightViewModel.mLedSwitchLiveData.observe(viewLifecycleOwner) { - dealRequestResult(it, object : GetResultCallback { - override fun onResult(any: Any) { + dealRequestResult( + it, + object : GetResultCallback { + override fun onResult(any: Any) { + getHomeV2Activity()?.let { h -> + h.getPet(false)?.let { p -> + if (mLedMac == p.macID && !BleManager.getInstance() + .isConnected(p.macID) + ) { + mTrackStateList[5].apply { + val ledSwitch = + if (menuValue == getString(R.string.tracker_manage_set_led_on)) { + ConstantInt.Close + } else { + ConstantInt.Open + } + setLedState(ledSwitch) + } + } + } + } + } + override fun onErrorCode() { + setLedErrorState() + } + + override fun onRequestError(exceptionCode: String?) { + setLedErrorState() + } + }, + isRequestErrorTip = mLedMac == getHomeV2Activity()!!.getPet(false)!!.macID, + isShowCodeError = mLedMac == getHomeV2Activity()!!.getPet(false)!!.macID + ) + } + } + + private fun setLedErrorState() { + getHomeV2Activity()?.apply { + getPet(false)?.let { + if (mLedMac == it.macID && !BleManager.getInstance().isConnected(it.macID)) { + mTrackStateList[5].apply { + state = ConstantInt.Type0 + type = ConstantInt.Type0 + mHomePetTrackStateAdapter.notifyItemChanged(5) + } } - }) + } } } @@ -396,13 +440,20 @@ class HomeTrackFragment : isSwitchPet = switchPet getHomeV2Activity()?.let { it.getPet()?.apply { - if (isSwitchPet) { + isSwitchPet = false + mTrackStateList[5].apply { + state = ConstantInt.Type0 + type = ConstantInt.SpecialType + menuValue = getString(R.string.tracker_manage_set_led_off) + mHomePetTrackStateAdapter.notifyItemChanged(5) + } mTrackMenuAdapter.notifyItemRangeRemoved(0, mTrackMenuList.size) mTrackMenuList.clear() } + addMenuListData(this) mTrackerInfoViewModel.getPetTrackerInfo(it, deviceId) } } @@ -470,8 +521,8 @@ class HomeTrackFragment : ) } - private fun addMenuListData() { - mMapDeviceBean?.apply { + private fun addMenuListData(petBean: PetBean) { + petBean.apply { if (mTrackMenuList.size == 0) { if (deviceType == ConstantInt.Type1) { ViewUtil.instance.addMenuBean( @@ -710,11 +761,9 @@ class HomeTrackFragment : it.menuName = getString(R.string.txt_tone) } it.colorRedId = R.color.orange_color3 - it.type = if (SRBleUtil.instance.isMacConnect(deviceMacId)) { - ConstantInt.Type0 - } else if (powerSwitch == ConstantInt.Type0 || powerSwitch == ConstantInt.Type2 || powerSwitch == ConstantInt.Type3 || inWifiZone == ConstantInt.Type1 || isTimeoutReport) { - ConstantInt.SpecialType - } else ConstantInt.Type0 + it.type = if (Util.getLedControlState(deviceMacId, this)) ConstantInt.Type0 + else ConstantInt.SpecialType + it.menuValue = if (ledSwitch == ConstantInt.Open) { it.colorRedId = R.color.blue_color1 getString(R.string.tracker_manage_set_led_on) @@ -887,7 +936,7 @@ class HomeTrackFragment : ) } } - } else if (data0 == 3 && data1 == 1) { + } else if (getHomeV2Activity()!!.isFrontRunning && data0 == 3 && data1 == 1) { val ledSwitch = if (mTrackStateList[5].menuValue == getString(R.string.tracker_manage_set_led_on)) { ConstantInt.Close @@ -1082,13 +1131,17 @@ class HomeTrackFragment : } mMapDeviceBean?.let { + state = ConstantInt.Type1 + type = ConstantInt.SpecialType + mHomePetTrackStateAdapter.notifyItemChanged(5) + mLedMac = it.deviceMacId if (BleManager.getInstance().isConnected(it.deviceMacId)) { //蓝牙控制 getBleTrackDeviceBean(false)?.let { ble -> SRBleUtil.instance.setBleLedSwitch(mContext!!, ble.bleDevice, ledSwitch) } } else { - setLedState(ledSwitch) +// setLedState(ledSwitch) //远程控制 mLedLightViewModel.setLedSwitch( null, it.deviceServerId, ledSwitch, ConstantInt.Type2 @@ -1103,6 +1156,8 @@ class HomeTrackFragment : */ private fun setLedState(ledSwitch: Int) { mTrackStateList[5].apply { + state = ConstantInt.Type0 + type = ConstantInt.Type0 colorRedId = R.color.orange_color3 menuValue = if (ledSwitch == ConstantInt.Open) { colorRedId = R.color.blue_color1 diff --git a/app/src/main/java/com/abbidot/tracker/util/Util.kt b/app/src/main/java/com/abbidot/tracker/util/Util.kt index 58ea836..2d838de 100644 --- a/app/src/main/java/com/abbidot/tracker/util/Util.kt +++ b/app/src/main/java/com/abbidot/tracker/util/Util.kt @@ -826,6 +826,22 @@ class Util { else -> R.drawable.icon_tracker_device_small } } + + /** + * 获取LED是否可以控制 + */ + fun getLedControlState(mac: String, mapDeviceBean: MapDeviceBean): Boolean { + var isControl: Boolean + mapDeviceBean.apply { + //是否超时上报 + val isTimeoutReport = isTimeoutReport(updateTime) + isControl = if (powerSwitch == ConstantInt.Type3) false + else if (SRBleUtil.instance.isMacConnect(mac)) true + else if (powerSwitch == ConstantInt.Type0 || powerSwitch == ConstantInt.Type2 || inWifiZone == ConstantInt.Type1 || isTimeoutReport) false + else true + } + return isControl + } } /** diff --git a/app/src/main/java/com/abbidot/tracker/vm/GeoCoderViewModel.kt b/app/src/main/java/com/abbidot/tracker/vm/GeoCoderViewModel.kt index e8dfa89..13f7a68 100644 --- a/app/src/main/java/com/abbidot/tracker/vm/GeoCoderViewModel.kt +++ b/app/src/main/java/com/abbidot/tracker/vm/GeoCoderViewModel.kt @@ -113,16 +113,19 @@ class GeoCoderViewModel : ViewModel() { } } searchResult.address?.let { + if (!TextUtils.isEmpty(it.houseNumber)) { + address += "${it.houseNumber} " + } if (!TextUtils.isEmpty(it.street)) { address += "${it.street} " } -// if (!TextUtils.isEmpty(it.houseNumber)) { -// address += "${it.houseNumber} " -// } - if (!TextUtils.isEmpty(it.locality)) { + if (TextUtils.isEmpty(address) && !TextUtils.isEmpty(it.neighborhood)) { + address += "${it.neighborhood} " + } + if (isShowDetailAddress && !TextUtils.isEmpty(it.locality)) { address += "${it.locality} " } - if (!TextUtils.isEmpty(it.place)) { + if (isShowDetailAddress && !TextUtils.isEmpty(it.place)) { address += "${it.place} " } if (isShowDetailAddress && !TextUtils.isEmpty(it.region)) { @@ -131,6 +134,17 @@ class GeoCoderViewModel : ViewModel() { if (isShowDetailAddress && !TextUtils.isEmpty(it.country)) { address += "${it.country}" } + + //防止显示空的地址 + if (TextUtils.isEmpty(address) && !TextUtils.isEmpty(it.locality)) { + address += "${it.locality} " + } + if (TextUtils.isEmpty(address) && !TextUtils.isEmpty(it.place)) { + address += "${it.place} " + } + if (TextUtils.isEmpty(address) && !TextUtils.isEmpty(it.region)) { + address += "${it.region} " + } mRegion = it.region.toString() } // address = address?.replace("null", "") @@ -169,7 +183,7 @@ class GeoCoderViewModel : ViewModel() { if (isShowDetailAddress && !TextUtils.isEmpty(province)) { address += province } - if (!TextUtils.isEmpty(city)) { + if (isShowDetailAddress && !TextUtils.isEmpty(city)) { address += city } if (!TextUtils.isEmpty(district)) { diff --git a/app/src/main/java/com/abbidot/tracker/vm/MapViewModel.kt b/app/src/main/java/com/abbidot/tracker/vm/MapViewModel.kt index 2036ecb..c89d982 100644 --- a/app/src/main/java/com/abbidot/tracker/vm/MapViewModel.kt +++ b/app/src/main/java/com/abbidot/tracker/vm/MapViewModel.kt @@ -458,15 +458,18 @@ class MapViewModel : ViewModel() { ViewUtil.instance.viewShow(closeBtn) } } else if (powerSwitch == ConstantInt.Type3) { - it.setCompoundDrawablesWithIntrinsicBounds( - R.drawable.icon_charge_image, 0, 0, 0 - ) - it.text = context.getString(R.string.txt_charging) + val image = if (batteryLevel == 100) { + it.text = context.getString(R.string.txt_fully_charged) + R.drawable.icon_fully_charged_image + } else { + it.text = context.getString(R.string.txt_charging) + R.drawable.icon_charge_image + } + it.setCompoundDrawablesWithIntrinsicBounds(image, 0, 0, 0) ViewUtil.instance.viewShow(closeBtn) } else if (batteryLevel <= ConstantInt.LowBattery20) { val lowBattery = if (batteryLevel <= ConstantInt.LowBattery10) ConstantInt.LowBattery10 -// else if (batteryLevel <= ConstantInt.LowBattery20) ConstantInt.LowBattery20 else ConstantInt.LowBattery20 it.setCompoundDrawablesWithIntrinsicBounds( R.drawable.icon_low_battery_image, 0, 0, 0 diff --git a/app/src/main/res/drawable-xhdpi/icon_fully_charged_image.png b/app/src/main/res/drawable-xhdpi/icon_fully_charged_image.png new file mode 100644 index 0000000..1cf39d2 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/icon_fully_charged_image.png differ diff --git a/app/src/main/res/drawable-xxhdpi/icon_fully_charged_image.png b/app/src/main/res/drawable-xxhdpi/icon_fully_charged_image.png new file mode 100644 index 0000000..56ed7eb Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/icon_fully_charged_image.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/icon_fully_charged_image.png b/app/src/main/res/drawable-xxxhdpi/icon_fully_charged_image.png new file mode 100644 index 0000000..7aa2c29 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/icon_fully_charged_image.png differ diff --git a/app/src/main/res/drawable/shape32_grey_color_bg.xml b/app/src/main/res/drawable/shape32_grey_color_bg.xml new file mode 100644 index 0000000..cc2ff38 --- /dev/null +++ b/app/src/main/res/drawable/shape32_grey_color_bg.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/app/src/main/res/drawable/shape44_gray_border_white_bg.xml b/app/src/main/res/drawable/shape44_gray_border_white_bg.xml index 76c3735..0a89905 100644 --- a/app/src/main/res/drawable/shape44_gray_border_white_bg.xml +++ b/app/src/main/res/drawable/shape44_gray_border_white_bg.xml @@ -1,11 +1,18 @@ - - - - - - + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_led_light.xml b/app/src/main/res/layout/activity_led_light.xml index 456085a..7020853 100644 --- a/app/src/main/res/layout/activity_led_light.xml +++ b/app/src/main/res/layout/activity_led_light.xml @@ -74,17 +74,46 @@ - + - + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_device_light_image_button.xml b/app/src/main/res/layout/layout_device_light_image_button.xml index 709982e..424905c 100644 --- a/app/src/main/res/layout/layout_device_light_image_button.xml +++ b/app/src/main/res/layout/layout_device_light_image_button.xml @@ -10,9 +10,9 @@ android:paddingVertical="@dimen/dp_8"> + + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_led_btn_state.xml b/app/src/main/res/layout/layout_led_btn_state.xml new file mode 100644 index 0000000..402d0e1 --- /dev/null +++ b/app/src/main/res/layout/layout_led_btn_state.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file 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 ca553d7..b0745ff 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 @@ -3,8 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingTop="@dimen/dp_10" - android:background="@color/white"> + android:background="@color/white" + android:paddingTop="@dimen/dp_10"> - Pull to load more Release to load + Fully charged + \ No newline at end of file