1.Account页面消息移动到pet页面

2.map页和直播页的消息显示状态和宠物头像顶部显示状态共存
This commit is contained in:
yezhiqiu
2025-12-12 18:15:22 +08:00
parent d87679408f
commit 3a7cb0251f
16 changed files with 223 additions and 151 deletions

View File

@@ -30,7 +30,7 @@ android {
targetSdkVersion 35 targetSdkVersion 35
versionCode 2101 versionCode 2101
// versionName "2.1.1" // versionName "2.1.1"
versionName "2.1.1-Beta8" versionName "2.1.1-Beta9"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@@ -20,8 +20,8 @@ class NotificationsViewModel : ViewModel() {
val mNotificationsLiveData = MutableLiveData<Result<MutableList<MessageBean>>>() val mNotificationsLiveData = MutableLiveData<Result<MutableList<MessageBean>>>()
val mDeleteMessageLiveData = MutableLiveData<Result<String>>() val mDeleteMessageLiveData = MutableLiveData<Result<String>>()
fun getMessageList(activity: BaseActivity<*>) { fun getMessageList() {
activity.showLoading(true) // activity.showLoading(true)
viewModelScope.launch { viewModelScope.launch {
val userId = MMKVUtil.getString(MMKVKey.UserId) val userId = MMKVUtil.getString(MMKVKey.UserId)
val result = NetworkApi.getMessageList(userId) val result = NetworkApi.getMessageList(userId)

View File

@@ -3,8 +3,6 @@ package com.abbidot.tracker.ui.activity.account
import android.view.View import android.view.View
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.abbidot.baselibrary.constant.EventName
import com.abbidot.baselibrary.eventbus.XEventBus
import com.abbidot.baselibrary.list.BaseRecyclerAdapter import com.abbidot.baselibrary.list.BaseRecyclerAdapter
import com.abbidot.baselibrary.util.LogUtil import com.abbidot.baselibrary.util.LogUtil
import com.abbidot.tracker.R import com.abbidot.tracker.R
@@ -44,7 +42,7 @@ class NotificationV2Activity :
message.isRead = true message.isRead = true
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
MyDatabase.messageDao().insert(message) MyDatabase.messageDao().insert(message)
XEventBus.post(EventName.RefreshMessage) // XEventBus.post(EventName.RefreshMessage)
} }
} }
notifyItemChanged(pos) notifyItemChanged(pos)
@@ -56,7 +54,7 @@ class NotificationV2Activity :
) )
setOnClickListenerViews(mViewBinding.btnNotificationV2ReadAll) setOnClickListenerViews(mViewBinding.btnNotificationV2ReadAll)
mNotificationsViewModel.getMessageList(this) mNotificationsViewModel.getMessageList()
} }
override fun liveDataObserve() { override fun liveDataObserve() {
@@ -87,9 +85,9 @@ class NotificationV2Activity :
runOnUiThread { runOnUiThread {
mMessageAdapter.setData(sortedByList.toMutableList(), true) mMessageAdapter.setData(sortedByList.toMutableList(), true)
} }
for (i in sortedByList){ // for (i in sortedByList){
LogUtil.e(i.messageId+""+i.message) // LogUtil.e(i.messageId+""+i.message)
} // }
} }
} }
} }
@@ -114,7 +112,7 @@ class NotificationV2Activity :
} }
mMessageAdapter.notifyItemRangeChanged(0, list.size) mMessageAdapter.notifyItemRangeChanged(0, list.size)
} }
if (isUpdate) XEventBus.post(EventName.RefreshMessage) // if (isUpdate) XEventBus.post(EventName.RefreshMessage)
} }
} }
} }

View File

@@ -12,6 +12,7 @@ import androidx.lifecycle.lifecycleScope
import com.abbidot.baselibrary.constant.ConState import com.abbidot.baselibrary.constant.ConState
import com.abbidot.baselibrary.constant.EventName import com.abbidot.baselibrary.constant.EventName
import com.abbidot.baselibrary.constant.MMKVKey import com.abbidot.baselibrary.constant.MMKVKey
import com.abbidot.baselibrary.constant.ResultCode
import com.abbidot.baselibrary.eventbus.XEventBus import com.abbidot.baselibrary.eventbus.XEventBus
import com.abbidot.baselibrary.list.BaseRecyclerAdapter import com.abbidot.baselibrary.list.BaseRecyclerAdapter
import com.abbidot.baselibrary.util.AppUtils import com.abbidot.baselibrary.util.AppUtils
@@ -114,6 +115,8 @@ class LiveActivityV3 : BaseActivity<ActivityLiveV3Binding>(ActivityLiveV3Binding
//设备Led灯开关 //设备Led灯开关
private var isLedOpen = false private var isLedOpen = false
private var mRequestModeType = ConstantInt.Type1 private var mRequestModeType = ConstantInt.Type1
private var isCloseBattery = false
private var isCloseMsg = false
override fun getTopBar() = null override fun getTopBar() = null
@@ -123,6 +126,9 @@ class LiveActivityV3 : BaseActivity<ActivityLiveV3Binding>(ActivityLiveV3Binding
mDistanceUnit = Util.getMetricUnits(mContext, ConstantInt.Type3) mDistanceUnit = Util.getMetricUnits(mContext, ConstantInt.Type3)
intent.extras?.apply { intent.extras?.apply {
isLiveJump = getBoolean(ConstantString.JumpActivity, true) isLiveJump = getBoolean(ConstantString.JumpActivity, true)
isCloseBattery = getBoolean(ConstantString.DeviceAuthorized)
isCloseMsg = getBoolean(ConstantString.PetAuthorized)
mMapViewModel.mDeviceMsgType = getInt(ConstantString.Type, ConstantInt.SpecialType)
mPetBean = Util.getParcelableAdaptive(intent, ConstantString.Pet, PetBean::class.java) mPetBean = Util.getParcelableAdaptive(intent, ConstantString.Pet, PetBean::class.java)
} }
@@ -249,13 +255,15 @@ class LiveActivityV3 : BaseActivity<ActivityLiveV3Binding>(ActivityLiveV3Binding
dealRequestResult(it, object : GetResultCallback { dealRequestResult(it, object : GetResultCallback {
override fun onResult(any: Any) { override fun onResult(any: Any) {
val data = it.getOrNull() val data = it.getOrNull()
data?.apply { data?.let { d ->
mMapDeviceBean = data d.isCloseBattery = isCloseBattery
setMapData(data) d.isCloseMsg = isCloseMsg
mMapDeviceBean = d
setMapData(d)
mMapViewModel.setDeviceStateAndWarningData( mMapViewModel.setDeviceStateAndWarningData(
mContext, mContext,
mPetBean, mPetBean,
data, d,
mViewBinding.ilLiveV3MapDeviceMsg.root, mViewBinding.ilLiveV3MapDeviceMsg.root,
mViewBinding.ilLiveV3MapDeviceMsg.tvDeviceMsgContent, mViewBinding.ilLiveV3MapDeviceMsg.tvDeviceMsgContent,
mViewBinding.ilLiveV3MapDeviceMsg.ivDeviceMsgCloseBtn, mViewBinding.ilLiveV3MapDeviceMsg.ivDeviceMsgCloseBtn,
@@ -288,13 +296,13 @@ class LiveActivityV3 : BaseActivity<ActivityLiveV3Binding>(ActivityLiveV3Binding
//直播超时 //直播超时
-1 -> { -1 -> {
XEventBus.post(EventName.LiveOpenTimeOut) XEventBus.post(EventName.LiveOpenTimeOut)
finish() finishActivity()
} }
//直播结束 //直播结束
0 -> { 0 -> {
mViewBinding.llLiveV2StateLayout.visibility = View.GONE mViewBinding.llLiveV2StateLayout.visibility = View.GONE
// showToast(R.string.txt_change_successful, true) // showToast(R.string.txt_change_successful, true)
finish() finishActivity()
} }
//直播开始 //直播开始
else -> { else -> {
@@ -312,7 +320,7 @@ class LiveActivityV3 : BaseActivity<ActivityLiveV3Binding>(ActivityLiveV3Binding
override fun onRequestError(exceptionCode: String?) { override fun onRequestError(exceptionCode: String?) {
LogUtil.e("HomeV2Activity直播开启错误onRequestError再次请求") LogUtil.e("HomeV2Activity直播开启错误onRequestError再次请求")
if (exceptionCode == mNetworkRequestsFailLimit) { if (exceptionCode == mNetworkRequestsFailLimit) {
finish() finishActivity()
} else { } else {
mPetBean?.apply { mPetBean?.apply {
mMapLiveViewModel.setupDeviceLiveStatus( mMapLiveViewModel.setupDeviceLiveStatus(
@@ -398,6 +406,17 @@ class LiveActivityV3 : BaseActivity<ActivityLiveV3Binding>(ActivityLiveV3Binding
} }
} }
private fun finishActivity() {
val intent = Intent()
mMapDeviceBean?.let {
intent.putExtra(ConstantString.DeviceAuthorized, it.isCloseBattery)
intent.putExtra(ConstantString.PetAuthorized, it.isCloseMsg)
intent.putExtra(ConstantString.Type, mMapViewModel.mDeviceMsgType)
}
setResult(ResultCode.ResultCode_1, intent)
finish()
}
/** /**
* 跳转debug调试页面 * 跳转debug调试页面
@@ -517,7 +536,7 @@ class LiveActivityV3 : BaseActivity<ActivityLiveV3Binding>(ActivityLiveV3Binding
//直播自动结束 //直播自动结束
if (isStartLive) { if (isStartLive) {
XEventBus.post(EventName.LiveAutoEnd) XEventBus.post(EventName.LiveAutoEnd)
finish() finishActivity()
} }
} }
@@ -756,7 +775,7 @@ class LiveActivityV3 : BaseActivity<ActivityLiveV3Binding>(ActivityLiveV3Binding
//直播自动结束 //直播自动结束
if (isStartLive) { if (isStartLive) {
XEventBus.post(EventName.LiveAutoEnd) XEventBus.post(EventName.LiveAutoEnd)
finish() finishActivity()
} }
return return
} else if (liveFlag == ConstantInt.Type1) { } else if (liveFlag == ConstantInt.Type1) {
@@ -1028,7 +1047,7 @@ class LiveActivityV3 : BaseActivity<ActivityLiveV3Binding>(ActivityLiveV3Binding
showAndHideFindLayout() showAndHideFindLayout()
} else { } else {
mFindBleDeviceViewModel.stopFindDevice() mFindBleDeviceViewModel.stopFindDevice()
finish() finishActivity()
} }
} }

View File

@@ -5,7 +5,6 @@ import android.content.Intent
import android.view.View import android.view.View
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.abbidot.baselibrary.constant.EventName import com.abbidot.baselibrary.constant.EventName
import com.abbidot.baselibrary.constant.MMKVKey import com.abbidot.baselibrary.constant.MMKVKey
import com.abbidot.baselibrary.eventbus.XEventBus import com.abbidot.baselibrary.eventbus.XEventBus
@@ -17,11 +16,8 @@ import com.abbidot.tracker.base.BaseFragment
import com.abbidot.tracker.bean.MenuTxtBean import com.abbidot.tracker.bean.MenuTxtBean
import com.abbidot.tracker.constant.GetResultCallback import com.abbidot.tracker.constant.GetResultCallback
import com.abbidot.tracker.constant.MultipleEntity import com.abbidot.tracker.constant.MultipleEntity
import com.abbidot.tracker.database.MyDatabase
import com.abbidot.tracker.databinding.FragmentAccountV2Binding import com.abbidot.tracker.databinding.FragmentAccountV2Binding
import com.abbidot.tracker.deprecated.ui.activity.vm.NotificationsViewModel
import com.abbidot.tracker.ui.activity.HomeV2Activity import com.abbidot.tracker.ui.activity.HomeV2Activity
import com.abbidot.tracker.ui.activity.account.NotificationV2Activity
import com.abbidot.tracker.ui.activity.account.UserProfileActivity import com.abbidot.tracker.ui.activity.account.UserProfileActivity
import com.abbidot.tracker.ui.activity.device.MyTrackerV2Activity import com.abbidot.tracker.ui.activity.device.MyTrackerV2Activity
import com.abbidot.tracker.ui.activity.subscribe.MySubscriptionActivity import com.abbidot.tracker.ui.activity.subscribe.MySubscriptionActivity
@@ -29,8 +25,6 @@ import com.abbidot.tracker.util.Util
import com.abbidot.tracker.util.ViewUtil import com.abbidot.tracker.util.ViewUtil
import com.abbidot.tracker.vm.UserProfileViewModel import com.abbidot.tracker.vm.UserProfileViewModel
import com.qmuiteam.qmui.util.QMUIDisplayHelper import com.qmuiteam.qmui.util.QMUIDisplayHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
/** /**
@@ -41,7 +35,6 @@ class AccountV2Fragment :
BaseFragment<FragmentAccountV2Binding>(FragmentAccountV2Binding::inflate) { BaseFragment<FragmentAccountV2Binding>(FragmentAccountV2Binding::inflate) {
private lateinit var mUserViewModel: UserProfileViewModel private lateinit var mUserViewModel: UserProfileViewModel
private lateinit var mNotificationsViewModel: NotificationsViewModel
private lateinit var mMenuAdapter: HomeAccountMenuAdapter private lateinit var mMenuAdapter: HomeAccountMenuAdapter
private lateinit var mMenuList: MutableList<MenuTxtBean> private lateinit var mMenuList: MutableList<MenuTxtBean>
@@ -60,7 +53,7 @@ class AccountV2Fragment :
llHomeAccountLayout, WindowInsetsCompat.Type.statusBars() llHomeAccountLayout, WindowInsetsCompat.Type.statusBars()
) )
llHomeAccountTopUser.let { llHomeAccountTopUser.let {
it.ivTopPetBtnSmall.setImageResource(R.drawable.icon_noti_svg) it.ivTopPetBtnSmall.visibility = View.GONE
it.homeDataPetNameSmall.text = it.homeDataPetNameSmall.text =
MMKVUtil.getString(MMKVKey.UserName, getString(R.string.app_name)) MMKVUtil.getString(MMKVKey.UserName, getString(R.string.app_name))
val imageUrl = MMKVUtil.getString(MMKVKey.HeadUrl) val imageUrl = MMKVUtil.getString(MMKVKey.HeadUrl)
@@ -80,7 +73,6 @@ class AccountV2Fragment :
setOnClickListenerViews( setOnClickListenerViews(
llHomeAccountMyTracker, llHomeAccountMyTracker,
llHomeAccountSubscription, llHomeAccountSubscription,
llHomeAccountTopUser.ivTopPetBtnSmall,
llHomeAccountTopUser.homeDataPetHeadSmall.root, llHomeAccountTopUser.homeDataPetHeadSmall.root,
llHomeAccountTopUser.homeDataPetNameSmall llHomeAccountTopUser.homeDataPetNameSmall
) )
@@ -88,7 +80,6 @@ class AccountV2Fragment :
//切换到账户ActivityV2Fragment 页面会导致ViewModel生命周期销毁需要重新创建 //切换到账户ActivityV2Fragment 页面会导致ViewModel生命周期销毁需要重新创建
mUserViewModel = ViewModelProvider(this)[UserProfileViewModel::class.java] mUserViewModel = ViewModelProvider(this)[UserProfileViewModel::class.java]
mNotificationsViewModel = ViewModelProvider(this)[NotificationsViewModel::class.java]
getHomeV2Activity()?.apply { getHomeV2Activity()?.apply {
mUserViewModel.getUserInfo(this) mUserViewModel.getUserInfo(this)
@@ -104,13 +95,6 @@ class AccountV2Fragment :
} }
} }
override fun onResume() {
super.onResume()
getHomeV2Activity()?.apply {
mNotificationsViewModel.getMessageList(this)
}
}
private fun addListData() { private fun addListData() {
mMenuList = mutableListOf() mMenuList = mutableListOf()
ViewUtil.instance.addMenuBean(mMenuList, getString(R.string.txt_help)) ViewUtil.instance.addMenuBean(mMenuList, getString(R.string.txt_help))
@@ -192,9 +176,6 @@ class AccountV2Fragment :
mUserViewModel.getUserInfo(it) mUserViewModel.getUserInfo(it)
} }
} }
XEventBus.observe(viewLifecycleOwner, EventName.RefreshMessage) {
getMessageCount()
}
mUserViewModel.apply { mUserViewModel.apply {
mUserInfoLiveData.observe(viewLifecycleOwner) { mUserInfoLiveData.observe(viewLifecycleOwner) {
dealRequestResult(it, object : GetResultCallback { dealRequestResult(it, object : GetResultCallback {
@@ -228,43 +209,8 @@ class AccountV2Fragment :
}) })
} }
} }
mNotificationsViewModel.mNotificationsLiveData.observe(viewLifecycleOwner) {
dealRequestResult(it, object : GetResultCallback {
override fun onResult(any: Any) {
it.getOrNull()?.apply {
lifecycleScope.launch(Dispatchers.IO) {
Util.dealMessage(this@apply)
getMessageCount()
}
}
} }
override fun onRequestError(exceptionCode: String?) {
getMessageCount()
}
}, isRequestErrorTip = false, isShowNoDataTip = false)
}
}
private fun getMessageCount() {
requireActivity().lifecycleScope.launch(Dispatchers.IO) {
MyDatabase.messageDao().findAll(MyDatabase.MessageTableName)?.apply {
var noReadNum = size
LogUtil.e("消息列表个数:${size}")
for (message in this) {
if (message.isRead) noReadNum--
}
getHomeV2Activity()?.runOnUiThread {
mViewBinding.homeAccountMessageCountText.let {
if (noReadNum > 0) it.visibility = View.VISIBLE
else it.visibility = View.GONE
it.text = "$noReadNum"
}
}
}
}
}
fun setMeasureUnit(measurementUnit: Int) { fun setMeasureUnit(measurementUnit: Int) {
mMeasurementUnit = measurementUnit mMeasurementUnit = measurementUnit
@@ -291,12 +237,6 @@ class AccountV2Fragment :
mContext, MySubscriptionActivity::class.java mContext, MySubscriptionActivity::class.java
) )
) )
llHomeAccountTopUser.ivTopPetBtnSmall -> startActivity(
Intent(
mContext, NotificationV2Activity::class.java
)
)
} }
} }
} }

View File

@@ -6,6 +6,7 @@ import android.graphics.Typeface
import android.location.LocationManager import android.location.LocationManager
import android.provider.Settings import android.provider.Settings
import android.view.View import android.view.View
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.commit import androidx.fragment.app.commit
@@ -13,6 +14,7 @@ import androidx.fragment.app.viewModels
import com.abbidot.baselibrary.constant.ConState import com.abbidot.baselibrary.constant.ConState
import com.abbidot.baselibrary.constant.EventName import com.abbidot.baselibrary.constant.EventName
import com.abbidot.baselibrary.constant.MMKVKey import com.abbidot.baselibrary.constant.MMKVKey
import com.abbidot.baselibrary.constant.ResultCode
import com.abbidot.baselibrary.eventbus.XEventBus import com.abbidot.baselibrary.eventbus.XEventBus
import com.abbidot.baselibrary.list.BaseRecyclerAdapter import com.abbidot.baselibrary.list.BaseRecyclerAdapter
import com.abbidot.baselibrary.util.AppUtils import com.abbidot.baselibrary.util.AppUtils
@@ -539,6 +541,35 @@ class MapV3Fragment : BaseFragment<FragmentMapV3Binding>(FragmentMapV3Binding::i
} }
} }
/**
* 接收添加信用卡返回结果
*/
private val mActivityResultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
it.data?.apply {
extras?.let { intent ->
if (it.resultCode == ResultCode.ResultCode_1) {
val isCloseBattery = intent.getBoolean(ConstantString.DeviceAuthorized)
val isCloseMsg = intent.getBoolean(ConstantString.PetAuthorized)
mMapViewModel.mDeviceMsgType =
intent.getInt(ConstantString.Type, mMapViewModel.mDeviceMsgType)
mMapDeviceBean?.let { m ->
if (isCloseBattery != m.isCloseBattery) {
m.isCloseBattery = isCloseBattery
mViewBinding.llHomeMapDeviceBatteryLayout.visibility =
if (isCloseBattery) View.INVISIBLE else View.VISIBLE
}
if (isCloseMsg != m.isCloseMsg) {
m.isCloseMsg = isCloseMsg
mViewBinding.ilHomeMapDeviceMsg.root.visibility =
if (isCloseMsg) View.GONE else View.VISIBLE
}
}
}
}
}
}
/** /**
* 检查获取定位,蓝牙权限 * 检查获取定位,蓝牙权限
*/ */
@@ -552,13 +583,7 @@ class MapV3Fragment : BaseFragment<FragmentMapV3Binding>(FragmentMapV3Binding::i
} else if (isRequestPetData && mPetList.size == 0) { } else if (isRequestPetData && mPetList.size == 0) {
showToast(R.string.no_bind_pet) showToast(R.string.no_bind_pet)
} else { } else {
getPet()?.apply { goLive(true)
mViewBinding.homeMapLiveBtn.isEnabled = false
val intent = Intent(mContext, LiveActivityV3::class.java)
intent.putExtra(ConstantString.JumpActivity, true)
intent.putExtra(ConstantString.Pet, this)
startActivity(intent)
}
} }
} else if (type == 1) { } else if (type == 1) {
if (!SRBleUtil.instance.isBleEnable(mContext)) { if (!SRBleUtil.instance.isBleEnable(mContext)) {
@@ -566,19 +591,35 @@ class MapV3Fragment : BaseFragment<FragmentMapV3Binding>(FragmentMapV3Binding::i
} else if (isRequestPetData && mPetList.size == 0) { } else if (isRequestPetData && mPetList.size == 0) {
showToast(R.string.no_bind_pet) showToast(R.string.no_bind_pet)
} else { } else {
getPet()?.apply { goLive(false)
mViewBinding.homeMapBluetoothBtn.isEnabled = false
val intent = Intent(mContext, LiveActivityV3::class.java)
intent.putExtra(ConstantString.JumpActivity, false)
intent.putExtra(ConstantString.Pet, this)
startActivity(intent)
}
} }
} }
}) })
} }
} }
private fun goLive(isLiveJump: Boolean) {
getHomeV2Activity()?.apply {
getPet()?.apply {
if (isLiveJump) {
mViewBinding.homeMapLiveBtn.isEnabled = false
} else {
mViewBinding.homeMapBluetoothBtn.isEnabled = false
}
val intent = Intent(mContext, LiveActivityV3::class.java)
intent.putExtra(ConstantString.JumpActivity, isLiveJump)
intent.putExtra(ConstantString.Pet, this)
mMapDeviceBean?.let {
intent.putExtra(ConstantString.DeviceAuthorized, it.isCloseBattery)
intent.putExtra(ConstantString.PetAuthorized, it.isCloseMsg)
intent.putExtra(ConstantString.Type, mMapViewModel.mDeviceMsgType)
}
// startActivity(intent)
launchActivity(mActivityResultLauncher, intent)
}
}
}
override fun onClick(v: View?) { override fun onClick(v: View?) {
mViewBinding.apply { mViewBinding.apply {
when (v!!) { when (v!!) {
@@ -604,15 +645,7 @@ class MapV3Fragment : BaseFragment<FragmentMapV3Binding>(FragmentMapV3Binding::i
homeMapLiveBtn -> { homeMapLiveBtn -> {
// locationPermissionsTip() // locationPermissionsTip()
getHomeV2Activity()?.let { goLive(true)
it.getPet()?.apply {
mViewBinding.homeMapLiveBtn.isEnabled = false
val intent = Intent(mContext, LiveActivityV3::class.java)
intent.putExtra(ConstantString.JumpActivity, true)
intent.putExtra(ConstantString.Pet, this)
startActivity(intent)
}
}
} }
llHomeMapTopPet.ivTopPetBtnSmall -> showMapTypeDialog() llHomeMapTopPet.ivTopPetBtnSmall -> showMapTypeDialog()

View File

@@ -6,7 +6,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.animation.LinearInterpolator import android.view.animation.LinearInterpolator
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.isGone import androidx.core.view.isVisible
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import com.abbidot.baselibrary.util.AppUtils import com.abbidot.baselibrary.util.AppUtils
import com.abbidot.baselibrary.util.Utils import com.abbidot.baselibrary.util.Utils
@@ -134,12 +134,13 @@ class HomeMapGoogleMapFragmentV3 : BaseGoogleMapFragment() {
if (marker == mMarker) { if (marker == mMarker) {
mMapDeviceBean?.let { mMapDeviceBean?.let {
if (it.canShowBattery) { if (it.canShowBattery) {
mDeviceBatteryLayout.visibility = if (mDeviceBatteryLayout.isGone) { mDeviceBatteryLayout.visibility =
it.isCloseBattery = false if (mDeviceBatteryLayout.isVisible) {
View.VISIBLE
} else {
it.isCloseBattery = true it.isCloseBattery = true
View.GONE View.GONE
} else {
it.isCloseBattery = false
View.VISIBLE
} }
} }
} }

View File

@@ -1,18 +1,29 @@
package com.abbidot.tracker.ui.fragment.pet package com.abbidot.tracker.ui.fragment.pet
import android.content.Context import android.content.Context
import android.content.Intent
import android.view.View import android.view.View
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.viewpager2.widget.ViewPager2 import androidx.viewpager2.widget.ViewPager2
import com.abbidot.baselibrary.util.AppUtils import com.abbidot.baselibrary.util.AppUtils
import com.abbidot.baselibrary.util.LogUtil import com.abbidot.baselibrary.util.LogUtil
import com.abbidot.tracker.R
import com.abbidot.tracker.adapter.ViewPagerAdapter import com.abbidot.tracker.adapter.ViewPagerAdapter
import com.abbidot.tracker.base.BaseFragment import com.abbidot.tracker.base.BaseFragment
import com.abbidot.tracker.constant.GetResultCallback
import com.abbidot.tracker.database.MyDatabase
import com.abbidot.tracker.databinding.FragmentPetV2Binding import com.abbidot.tracker.databinding.FragmentPetV2Binding
import com.abbidot.tracker.deprecated.ui.activity.vm.NotificationsViewModel
import com.abbidot.tracker.ui.activity.HomeV2Activity import com.abbidot.tracker.ui.activity.HomeV2Activity
import com.abbidot.tracker.ui.activity.account.NotificationV2Activity
import com.abbidot.tracker.ui.fragment.device.HomeTrackFragment import com.abbidot.tracker.ui.fragment.device.HomeTrackFragment
import com.abbidot.tracker.util.Util
import com.abbidot.tracker.util.ViewUtil import com.abbidot.tracker.util.ViewUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
/** /**
@@ -21,6 +32,8 @@ import com.abbidot.tracker.util.ViewUtil
*/ */
class PetV2Fragment : BaseFragment<FragmentPetV2Binding>(FragmentPetV2Binding::inflate) { class PetV2Fragment : BaseFragment<FragmentPetV2Binding>(FragmentPetV2Binding::inflate) {
private lateinit var mNotificationsViewModel: NotificationsViewModel
private lateinit var mFragments: MutableList<Fragment> private lateinit var mFragments: MutableList<Fragment>
//当前这个页面显示的宠物下标 //当前这个页面显示的宠物下标
@@ -42,7 +55,7 @@ class PetV2Fragment : BaseFragment<FragmentPetV2Binding>(FragmentPetV2Binding::i
getHomeV2Activity()?.edgeToEdgeAdapterBars( getHomeV2Activity()?.edgeToEdgeAdapterBars(
root, WindowInsetsCompat.Type.statusBars() root, WindowInsetsCompat.Type.statusBars()
) )
ilHomePetTopBar.ivTopPetBtnSmall.visibility = View.GONE ilHomePetTopBar.ivTopPetBtnSmall.setImageResource(R.drawable.icon_noti_svg)
rgSwitchPetTrack.setOnCheckedChangeListener { _, checkedId -> rgSwitchPetTrack.setOnCheckedChangeListener { _, checkedId ->
when (checkedId) { when (checkedId) {
@@ -69,7 +82,9 @@ class PetV2Fragment : BaseFragment<FragmentPetV2Binding>(FragmentPetV2Binding::i
} }
}) })
setOnClickListenerViews( setOnClickListenerViews(
ilHomePetTopBar.homeDataPetNameSmall, ilHomePetTopBar.homeDataPetHeadSmall.root ilHomePetTopBar.homeDataPetNameSmall,
ilHomePetTopBar.homeDataPetHeadSmall.root,
ilHomePetTopBar.ivTopPetBtnSmall
) )
} }
if (AppUtils.isDebug()) { if (AppUtils.isDebug()) {
@@ -79,6 +94,30 @@ class PetV2Fragment : BaseFragment<FragmentPetV2Binding>(FragmentPetV2Binding::i
} }
} }
} }
mNotificationsViewModel = ViewModelProvider(this)[NotificationsViewModel::class.java]
}
override fun liveDataObserve() {
// XEventBus.observe(viewLifecycleOwner, EventName.RefreshMessage) {
// getMessageCount()
// }
mNotificationsViewModel.mNotificationsLiveData.observe(viewLifecycleOwner) {
dealRequestResult(it, object : GetResultCallback {
override fun onResult(any: Any) {
it.getOrNull()?.apply {
lifecycleScope.launch(Dispatchers.IO) {
Util.dealMessage(this@apply)
getMessageCount()
}
}
}
override fun onRequestError(exceptionCode: String?) {
getMessageCount()
}
}, isRequestErrorTip = false, isShowNoDataTip = false)
}
} }
private fun getHomeV2Activity(): HomeV2Activity? { private fun getHomeV2Activity(): HomeV2Activity? {
@@ -92,6 +131,7 @@ class PetV2Fragment : BaseFragment<FragmentPetV2Binding>(FragmentPetV2Binding::i
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
mNotificationsViewModel.getMessageList()
(mFragments[1] as HomeTrackFragment).onResume() (mFragments[1] as HomeTrackFragment).onResume()
getHomeV2Activity()?.apply { getHomeV2Activity()?.apply {
//其他页面是否选择了宠物 //其他页面是否选择了宠物
@@ -108,6 +148,26 @@ class PetV2Fragment : BaseFragment<FragmentPetV2Binding>(FragmentPetV2Binding::i
(mFragments[1] as HomeTrackFragment).onPause() (mFragments[1] as HomeTrackFragment).onPause()
} }
private fun getMessageCount() {
requireActivity().lifecycleScope.launch(Dispatchers.IO) {
MyDatabase.messageDao().findAll(MyDatabase.MessageTableName)?.apply {
var noReadNum = size
LogUtil.e("消息数量:${size}")
for (message in this) {
if (message.isRead) noReadNum--
}
getHomeV2Activity()?.runOnUiThread {
mViewBinding.homePetMessageCountText.let {
if (noReadNum > 0) it.visibility = View.VISIBLE
else it.visibility = View.GONE
it.text = "$noReadNum"
}
}
}
}
}
/** /**
* 设置需要更新的标识 * 设置需要更新的标识
*/ */
@@ -144,6 +204,9 @@ class PetV2Fragment : BaseFragment<FragmentPetV2Binding>(FragmentPetV2Binding::i
mViewBinding.apply { mViewBinding.apply {
when (v!!) { when (v!!) {
ilHomePetTopBar.homeDataPetNameSmall, ilHomePetTopBar.homeDataPetHeadSmall.root -> getHomeV2Activity()?.selectPetDialog() ilHomePetTopBar.homeDataPetNameSmall, ilHomePetTopBar.homeDataPetHeadSmall.root -> getHomeV2Activity()?.selectPetDialog()
ilHomePetTopBar.ivTopPetBtnSmall -> startActivity(
Intent(mContext, NotificationV2Activity::class.java)
)
} }
} }
} }

View File

@@ -35,7 +35,7 @@ class MapViewModel : ViewModel() {
private var mRefreshDataMin = 0.5f private var mRefreshDataMin = 0.5f
private var mDeviceId = "" private var mDeviceId = ""
private var mDeviceMsgType = ConstantInt.SpecialType var mDeviceMsgType = ConstantInt.SpecialType
fun getMapDeviceStatus(deviceId: String, isNeedCountDown: Boolean = true) { fun getMapDeviceStatus(deviceId: String, isNeedCountDown: Boolean = true) {
viewModelScope.launch { viewModelScope.launch {

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 705 B

View File

@@ -11,32 +11,33 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/dp_8">
<include <include
android:id="@+id/ll_home_account_top_user" android:id="@+id/ll_home_account_top_user"
layout="@layout/layout_top_pet_data_small" layout="@layout/layout_top_pet_data_small"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_8"
android:layout_marginTop="@dimen/dp_8" /> android:layout_marginTop="@dimen/dp_8" />
<!-- <RelativeLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:paddingHorizontal="@dimen/dp_8">-->
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/home_account_message_count_text" <!-- <androidx.appcompat.widget.AppCompatTextView-->
android:layout_width="@dimen/dp_18" <!-- android:id="@+id/home_account_message_count_text"-->
android:layout_height="@dimen/dp_18" <!-- android:layout_width="@dimen/dp_18"-->
android:layout_alignParentEnd="true" <!-- android:layout_height="@dimen/dp_18"-->
android:layout_marginTop="@dimen/dp_8" <!-- android:layout_alignParentEnd="true"-->
android:layout_marginEnd="@dimen/dp_8" <!-- android:layout_marginTop="@dimen/dp_8"-->
android:background="@drawable/message_shape_bg" <!-- android:layout_marginEnd="@dimen/dp_8"-->
android:gravity="center" <!-- android:background="@drawable/message_shape_bg"-->
android:text="99" <!-- android:gravity="center"-->
android:textColor="@color/white" <!-- android:text="99"-->
android:textSize="@dimen/textSize10" <!-- android:textColor="@color/white"-->
android:visibility="gone" /> <!-- android:textSize="@dimen/textSize10"-->
</RelativeLayout> <!-- android:visibility="gone" />-->
<!-- </RelativeLayout>-->
<androidx.appcompat.widget.LinearLayoutCompat <androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -6,14 +6,33 @@
android:orientation="vertical" android:orientation="vertical"
tools:context=".ui.fragment.pet.PetV2Fragment"> tools:context=".ui.fragment.pet.PetV2Fragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/dp_8">
<include <include
android:id="@+id/il_home_pet_top_bar" android:id="@+id/il_home_pet_top_bar"
layout="@layout/layout_top_pet_data_small" layout="@layout/layout_top_pet_data_small"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_8"
android:layout_marginTop="@dimen/dp_8" /> android:layout_marginTop="@dimen/dp_8" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/home_pet_message_count_text"
android:layout_width="@dimen/dp_18"
android:layout_height="@dimen/dp_18"
android:layout_alignParentEnd="true"
android:layout_marginTop="@dimen/dp_8"
android:layout_marginEnd="@dimen/dp_8"
android:background="@drawable/message_shape_bg"
android:gravity="center"
android:text="99"
android:textColor="@color/white"
android:textSize="@dimen/textSize10"
android:visibility="gone" />
</RelativeLayout>
<RadioGroup <RadioGroup
android:id="@+id/rg_switch_pet_track" android:id="@+id/rg_switch_pet_track"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -21,10 +21,9 @@
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_device_msg_close_btn" android:id="@+id/iv_device_msg_close_btn"
android:layout_width="@dimen/dp_16" android:layout_width="wrap_content"
android:layout_height="@dimen/dp_16" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:src="@drawable/ic_delete_easyy_photos" android:src="@drawable/icon_white_bg_gray_delete" />
android:tint="@color/gray_color3" />
</FrameLayout> </FrameLayout>

View File

@@ -33,10 +33,9 @@
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_device_close_btn" android:id="@+id/iv_device_close_btn"
android:layout_width="@dimen/dp_16" android:layout_width="wrap_content"
android:layout_height="@dimen/dp_16" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:src="@drawable/ic_delete_easyy_photos" android:src="@drawable/icon_white_bg_gray_delete" />
android:tint="@color/gray_color3" />
</FrameLayout> </FrameLayout>