diff --git a/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt b/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt index 2ad0421..91cfa4d 100644 --- a/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt +++ b/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt @@ -3,6 +3,7 @@ import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import com.casic.common.detector.gd.R import com.casic.common.detector.gd.model.Satellite @@ -59,4 +60,32 @@ .setText(R.id.azimuthView, "${satellite.azimuth}°") .setText(R.id.elevationView, "${satellite.elevation}°") } + + /** + * 刷新列表,局部刷新 + * */ + fun refresh(newRows: MutableList) { + val diffCallback = object : DiffUtil.Callback() { + override fun getOldListSize(): Int = dataRows.size + + override fun getNewListSize(): Int = newRows.size + + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + val oldItem = dataRows[oldItemPosition] + val newItem = newRows[newItemPosition] + return oldItem.type == newItem.type && oldItem.svid == newItem.svid + } + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + return oldItemPosition == newItemPosition + } + } + + val diffResult = DiffUtil.calculateDiff(diffCallback, true) + + dataRows.clear() + dataRows.addAll(newRows) + + diffResult.dispatchUpdatesTo(this) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt b/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt index 2ad0421..91cfa4d 100644 --- a/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt +++ b/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt @@ -3,6 +3,7 @@ import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import com.casic.common.detector.gd.R import com.casic.common.detector.gd.model.Satellite @@ -59,4 +60,32 @@ .setText(R.id.azimuthView, "${satellite.azimuth}°") .setText(R.id.elevationView, "${satellite.elevation}°") } + + /** + * 刷新列表,局部刷新 + * */ + fun refresh(newRows: MutableList) { + val diffCallback = object : DiffUtil.Callback() { + override fun getOldListSize(): Int = dataRows.size + + override fun getNewListSize(): Int = newRows.size + + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + val oldItem = dataRows[oldItemPosition] + val newItem = newRows[newItemPosition] + return oldItem.type == newItem.type && oldItem.svid == newItem.svid + } + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + return oldItemPosition == newItemPosition + } + } + + val diffResult = DiffUtil.calculateDiff(diffCallback, true) + + dataRows.clear() + dataRows.addAll(newRows) + + diffResult.dispatchUpdatesTo(this) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/common/detector/gd/widgets/SatelliteStatusDialog.kt b/app/src/main/java/com/casic/common/detector/gd/widgets/SatelliteStatusDialog.kt index 0081aae..0ced6d1 100644 --- a/app/src/main/java/com/casic/common/detector/gd/widgets/SatelliteStatusDialog.kt +++ b/app/src/main/java/com/casic/common/detector/gd/widgets/SatelliteStatusDialog.kt @@ -1,6 +1,7 @@ package com.casic.common.detector.gd.widgets import android.Manifest +import android.annotation.SuppressLint import android.app.Dialog import android.content.Context import android.content.pm.PackageManager @@ -25,6 +26,7 @@ import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.widget.TitleBarView +@SuppressLint("SetTextI18n") class SatelliteStatusDialog(private val context: Context) : Dialog(context), LocationListener { private val kTag = "SatelliteStatusDialog" @@ -39,7 +41,6 @@ 6 to "GALILEO", 7 to "IRNSS", ) - private val satelliteCollection = ArrayList() private val binding: DialogSatelliteStatusBinding by binding() private lateinit var satelliteAdapter: SatelliteRecyclerAdapter @@ -64,7 +65,7 @@ LocationManager.GPS_PROVIDER, 3000, 0f, this ) locationManager.registerGnssStatusCallback(gnssStatusListener, null) - satelliteAdapter = SatelliteRecyclerAdapter(context, satelliteCollection) + satelliteAdapter = SatelliteRecyclerAdapter(context, ArrayList()) binding.recyclerView.adapter = satelliteAdapter binding.recyclerView.addItemDecoration(RecyclerViewItemDivider(0f, 0f, Color.WHITE)) @@ -74,8 +75,10 @@ val lng = location.longitude.toDegree() val lat = location.latitude.toDegree() - binding.gdGpsView.text = - "经度:${lng} 纬度:${lat}\n精度:${location.accuracy}m\n类型:高德" + binding.gdView.text = "经度:${lng} 纬度:${lat}\n" + + "经度:${location.longitude} 纬度:${location.latitude}\n" + + "精度:${location.accuracy}m\n" + + "类型:高德" } override fun onError() { @@ -103,12 +106,15 @@ val lng = location.longitude.toDegree() val lat = location.latitude.toDegree() - binding.locationView.text = "经度:${lng} 纬度:${lat}\n精度:${location.accuracy}m\n类型:GPS" + binding.rtkView.text = "经度:${lng} 纬度:${lat}\n" + + "经度:${location.longitude} 纬度:${location.latitude}\n" + + "精度:${location.accuracy}m\n" + + "类型:RTK" } private val gnssStatusListener = object : GnssStatus.Callback() { override fun onSatelliteStatusChanged(status: GnssStatus) { - satelliteCollection.clear() + val newSatellites = mutableListOf() for (i in 0 until status.satelliteCount) { //在同一个导航系统内,svid是唯一的,不会重复,但是,不同的导航系统可能会使用相同的svid数值 val constellationType = status.getConstellationType(i) @@ -121,10 +127,10 @@ isUsedInFix = status.usedInFix(i) } if (satellite.signal != 0) { - satelliteCollection.add(satellite) + newSatellites.add(satellite) } } - satelliteAdapter.notifyDataSetChanged() + satelliteAdapter.refresh(newSatellites) } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt b/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt index 2ad0421..91cfa4d 100644 --- a/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt +++ b/app/src/main/java/com/casic/common/detector/gd/adapter/SatelliteRecyclerAdapter.kt @@ -3,6 +3,7 @@ import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import com.casic.common.detector.gd.R import com.casic.common.detector.gd.model.Satellite @@ -59,4 +60,32 @@ .setText(R.id.azimuthView, "${satellite.azimuth}°") .setText(R.id.elevationView, "${satellite.elevation}°") } + + /** + * 刷新列表,局部刷新 + * */ + fun refresh(newRows: MutableList) { + val diffCallback = object : DiffUtil.Callback() { + override fun getOldListSize(): Int = dataRows.size + + override fun getNewListSize(): Int = newRows.size + + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + val oldItem = dataRows[oldItemPosition] + val newItem = newRows[newItemPosition] + return oldItem.type == newItem.type && oldItem.svid == newItem.svid + } + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + return oldItemPosition == newItemPosition + } + } + + val diffResult = DiffUtil.calculateDiff(diffCallback, true) + + dataRows.clear() + dataRows.addAll(newRows) + + diffResult.dispatchUpdatesTo(this) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/common/detector/gd/widgets/SatelliteStatusDialog.kt b/app/src/main/java/com/casic/common/detector/gd/widgets/SatelliteStatusDialog.kt index 0081aae..0ced6d1 100644 --- a/app/src/main/java/com/casic/common/detector/gd/widgets/SatelliteStatusDialog.kt +++ b/app/src/main/java/com/casic/common/detector/gd/widgets/SatelliteStatusDialog.kt @@ -1,6 +1,7 @@ package com.casic.common.detector.gd.widgets import android.Manifest +import android.annotation.SuppressLint import android.app.Dialog import android.content.Context import android.content.pm.PackageManager @@ -25,6 +26,7 @@ import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.widget.TitleBarView +@SuppressLint("SetTextI18n") class SatelliteStatusDialog(private val context: Context) : Dialog(context), LocationListener { private val kTag = "SatelliteStatusDialog" @@ -39,7 +41,6 @@ 6 to "GALILEO", 7 to "IRNSS", ) - private val satelliteCollection = ArrayList() private val binding: DialogSatelliteStatusBinding by binding() private lateinit var satelliteAdapter: SatelliteRecyclerAdapter @@ -64,7 +65,7 @@ LocationManager.GPS_PROVIDER, 3000, 0f, this ) locationManager.registerGnssStatusCallback(gnssStatusListener, null) - satelliteAdapter = SatelliteRecyclerAdapter(context, satelliteCollection) + satelliteAdapter = SatelliteRecyclerAdapter(context, ArrayList()) binding.recyclerView.adapter = satelliteAdapter binding.recyclerView.addItemDecoration(RecyclerViewItemDivider(0f, 0f, Color.WHITE)) @@ -74,8 +75,10 @@ val lng = location.longitude.toDegree() val lat = location.latitude.toDegree() - binding.gdGpsView.text = - "经度:${lng} 纬度:${lat}\n精度:${location.accuracy}m\n类型:高德" + binding.gdView.text = "经度:${lng} 纬度:${lat}\n" + + "经度:${location.longitude} 纬度:${location.latitude}\n" + + "精度:${location.accuracy}m\n" + + "类型:高德" } override fun onError() { @@ -103,12 +106,15 @@ val lng = location.longitude.toDegree() val lat = location.latitude.toDegree() - binding.locationView.text = "经度:${lng} 纬度:${lat}\n精度:${location.accuracy}m\n类型:GPS" + binding.rtkView.text = "经度:${lng} 纬度:${lat}\n" + + "经度:${location.longitude} 纬度:${location.latitude}\n" + + "精度:${location.accuracy}m\n" + + "类型:RTK" } private val gnssStatusListener = object : GnssStatus.Callback() { override fun onSatelliteStatusChanged(status: GnssStatus) { - satelliteCollection.clear() + val newSatellites = mutableListOf() for (i in 0 until status.satelliteCount) { //在同一个导航系统内,svid是唯一的,不会重复,但是,不同的导航系统可能会使用相同的svid数值 val constellationType = status.getConstellationType(i) @@ -121,10 +127,10 @@ isUsedInFix = status.usedInFix(i) } if (satellite.signal != 0) { - satelliteCollection.add(satellite) + newSatellites.add(satellite) } } - satelliteAdapter.notifyDataSetChanged() + satelliteAdapter.refresh(newSatellites) } } } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_satellite_status.xml b/app/src/main/res/layout/dialog_satellite_status.xml index 7d571bd..8d1d899 100644 --- a/app/src/main/res/layout/dialog_satellite_status.xml +++ b/app/src/main/res/layout/dialog_satellite_status.xml @@ -125,7 +125,7 @@ android:background="@color/white" />