[8.3.0][临时不停车] 乘客屏功能完成
This commit is contained in:
@@ -14,21 +14,58 @@ class StationAdapter : ListAdapter<BusStationBean, StationViewHolder>(MessageDif
|
||||
var distanceAndTime = ""
|
||||
|
||||
override fun submitList(list: MutableList<BusStationBean>?) {
|
||||
val newDataList = mutableListOf<BusStationBean>()
|
||||
var isLeaving = false
|
||||
list?.let {
|
||||
var showPassOmit = false
|
||||
var showFuluterOmit = false
|
||||
it.forEachIndexed { index, busStationBean ->
|
||||
if (busStationBean.drivingStatus == 2) {
|
||||
currentIndex = index
|
||||
isLeaving = busStationBean.isLeaving
|
||||
return@forEachIndexed
|
||||
var currentStationIndex = -1
|
||||
var isLeavingStatus = false
|
||||
|
||||
// --- 新逻辑开始 ---
|
||||
|
||||
// 1. 首选查找: 查找第一个 drivingStatus == 2 且 tag != 2 的站点
|
||||
val currentStation = it.firstOrNull { bean ->
|
||||
bean.drivingStatus == 2 && bean.tag != 2
|
||||
}
|
||||
|
||||
if (currentStation != null) {
|
||||
currentStationIndex = it.indexOf(currentStation)
|
||||
isLeavingStatus = currentStation.isLeaving
|
||||
} else {
|
||||
// 2. 备用查找: 如果找不到,则查找第一个 tag != 2 的站点
|
||||
val firstValidStation = it.firstOrNull { bean ->
|
||||
bean.tag != 2
|
||||
}
|
||||
if (firstValidStation != null) {
|
||||
currentStationIndex = it.indexOf(firstValidStation)
|
||||
isLeavingStatus = firstValidStation.isLeaving
|
||||
} else {
|
||||
// 如果整个列表都没有 tag != 2 的站点,则保持默认值 -1 (或 0)
|
||||
currentStationIndex = 0 // 默认为第一个
|
||||
isLeavingStatus = false
|
||||
}
|
||||
}
|
||||
if (isLeaving) {
|
||||
currentIndex += 1
|
||||
|
||||
// 3. 处理 isLeaving 状态,更新 currentIndex 到下一个有效站点
|
||||
if (currentStationIndex != -1 && isLeavingStatus) {
|
||||
// 从当前站点的下一个位置开始查找第一个 tag != 2 的站点
|
||||
val nextValidStation = it.subList(currentStationIndex + 1, it.size)
|
||||
.firstOrNull { bean -> bean.tag != 2 }
|
||||
|
||||
if (nextValidStation != null) {
|
||||
// 更新 currentIndex 为下一个有效站点的实际索引
|
||||
currentStationIndex = it.indexOf(nextValidStation)
|
||||
} else {
|
||||
// 如果后面没有 tag != 2 的站点,则 currentIndex 保持在列表末尾或上一个有效站点的索引
|
||||
currentStationIndex = currentStationIndex // 保持在当前站点的索引
|
||||
}
|
||||
}
|
||||
|
||||
// 更新 Adapter 的 currentIndex 和 isLeaving(虽然 isLeaving 没有直接存储在 Adapter 中,但逻辑上已处理)
|
||||
currentIndex = if (currentStationIndex != -1) currentStationIndex else 0
|
||||
// --- 新逻辑结束 ---
|
||||
|
||||
val newDataList = mutableListOf<BusStationBean>()
|
||||
var showPassOmit = false
|
||||
var showFuluterOmit = false
|
||||
|
||||
if ((it.size) <= 7) {
|
||||
showPassOmit = false
|
||||
showFuluterOmit = false
|
||||
@@ -64,7 +101,7 @@ class StationAdapter : ListAdapter<BusStationBean, StationViewHolder>(MessageDif
|
||||
newDataList.add(StationBeanOmit(list.size-5-1))
|
||||
newDataList.addAll(list.slice(list.size-5 until list.size))
|
||||
} else {
|
||||
|
||||
// 保持原来的逻辑,如果不满足省略条件,则全展示
|
||||
}
|
||||
}else{
|
||||
newDataList.addAll(it.toList())
|
||||
@@ -72,19 +109,27 @@ class StationAdapter : ListAdapter<BusStationBean, StationViewHolder>(MessageDif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// 在将列表提交给 ListAdapter 之前,再次确定 currentIndex。
|
||||
// 这里的逻辑需要根据newDataList重新计算currentIndex,因为列表可能已经被裁剪和插入了省略号
|
||||
// 但是因为省略号逻辑是根据原始 currentIndex 计算的,所以我们只需确保在最终列表中正确标记 'CurrentStation' 即可。
|
||||
// 考虑到 getItemViewType 依赖 position 和 currentIndex 来判断 ViewType,我们保留在提交前更新 currentIndex 的步骤。
|
||||
|
||||
newDataList.forEachIndexed { index, busStationBean ->
|
||||
if (busStationBean.drivingStatus == 2) {
|
||||
currentIndex = index
|
||||
isLeaving = busStationBean.isLeaving
|
||||
if(isLeaving){
|
||||
currentIndex+=1
|
||||
// 再次更新 currentIndex,以匹配 newDataList 中的索引位置
|
||||
if (currentStationIndex != -1) {
|
||||
// 找到原列表中 currentIndex 对应的站点对象
|
||||
val originalCurrentBean = it[currentStationIndex]
|
||||
// 查找该对象在 newDataList 中的新索引
|
||||
val newIndex = newDataList.indexOfFirst { item ->
|
||||
// 确保 item 是 BusStationBean 且与原始对象匹配
|
||||
item is BusStationBean && item.siteId == originalCurrentBean.siteId
|
||||
}
|
||||
currentIndex = if (newIndex != -1) newIndex else 0 // 如果找不到,则默认为第一个
|
||||
} else {
|
||||
currentIndex = 0
|
||||
}
|
||||
distanceAndTime = ""
|
||||
super.submitList(newDataList)
|
||||
}
|
||||
distanceAndTime = ""
|
||||
super.submitList(newDataList)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: StationViewHolder, position: Int) {
|
||||
|
||||
@@ -34,26 +34,50 @@ abstract class StationViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
class NormalStationStartViewHolder(binding: View) : StationViewHolder(binding) {
|
||||
private var startStaionName: AppCompatTextView = binding.findViewById(R.id.actv_normal_station_start)
|
||||
private val stationStatus: AppCompatTextView = itemView.findViewById(R.id.station_status)//站点状态
|
||||
override fun bind(item: BusStationBean,distanceAndView:String) {
|
||||
startStaionName.text = item.name
|
||||
stationStatus.visibility = if (item.tag == 2) {
|
||||
View.VISIBLE
|
||||
}else{
|
||||
View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
class NormalStationEndViewHolder(binding: View) : StationViewHolder(binding) {
|
||||
private var endStaionName: AppCompatTextView = binding.findViewById(R.id.actv_normal_station_end)
|
||||
private val stationStatus: AppCompatTextView = itemView.findViewById(R.id.station_status)//站点状态
|
||||
override fun bind(item: BusStationBean,distanceAndView:String) {
|
||||
endStaionName.text = item.name
|
||||
stationStatus.visibility = if (item.tag == 2) {
|
||||
View.VISIBLE
|
||||
}else{
|
||||
View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
class NormalStationPassViewHolder(binding: View) : StationViewHolder(binding) {
|
||||
private var passStaionName: AppCompatTextView = binding.findViewById(R.id.actv_normal_station_pass)
|
||||
private val stationStatus: AppCompatTextView = itemView.findViewById(R.id.station_status)//站点状态
|
||||
override fun bind(item: BusStationBean,distanceAndView:String) {
|
||||
passStaionName.text = item.name
|
||||
stationStatus.visibility = if (item.tag == 2) {
|
||||
View.VISIBLE
|
||||
}else{
|
||||
View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
class NormalStationFutureViewHolder(binding: View) : StationViewHolder(binding) {
|
||||
private var futureStaionName: AppCompatTextView = binding.findViewById(R.id.actv_normal_station_future)
|
||||
private val stationStatus: AppCompatTextView = itemView.findViewById(R.id.station_status)//站点状态
|
||||
override fun bind(item: BusStationBean,distanceAndView:String) {
|
||||
futureStaionName.text = item.name
|
||||
stationStatus.visibility = if (item.tag == 2) {
|
||||
View.VISIBLE
|
||||
}else{
|
||||
View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="16dp" />
|
||||
<gradient
|
||||
android:angle="0"
|
||||
android:endColor="#D5DDED"
|
||||
android:startColor="#D5DDED"
|
||||
android:type="linear" />
|
||||
</shape>
|
||||
@@ -47,4 +47,21 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/station_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/dp_20"
|
||||
android:background="@drawable/shuttle_p_b2_station_status_bg"
|
||||
android:paddingStart="@dimen/dp_12"
|
||||
android:paddingTop="@dimen/dp_4"
|
||||
android:paddingEnd="@dimen/dp_12"
|
||||
android:paddingBottom="@dimen/dp_4"
|
||||
android:text="临时不停"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/dp_34"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -57,4 +57,21 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/station_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/dp_20"
|
||||
android:background="@drawable/shuttle_p_b2_station_status_bg"
|
||||
android:paddingStart="@dimen/dp_12"
|
||||
android:paddingTop="@dimen/dp_4"
|
||||
android:paddingEnd="@dimen/dp_12"
|
||||
android:paddingBottom="@dimen/dp_4"
|
||||
android:text="临时不停"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/dp_34"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -56,4 +56,21 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/station_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/dp_20"
|
||||
android:background="@drawable/shuttle_p_b2_station_status_bg"
|
||||
android:paddingStart="@dimen/dp_12"
|
||||
android:paddingTop="@dimen/dp_4"
|
||||
android:paddingEnd="@dimen/dp_12"
|
||||
android:paddingBottom="@dimen/dp_4"
|
||||
android:text="临时不停"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/dp_34"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -46,4 +46,21 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/station_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/dp_20"
|
||||
android:background="@drawable/shuttle_p_b2_station_status_bg"
|
||||
android:paddingStart="@dimen/dp_12"
|
||||
android:paddingTop="@dimen/dp_4"
|
||||
android:paddingEnd="@dimen/dp_12"
|
||||
android:paddingBottom="@dimen/dp_4"
|
||||
android:text="临时不停"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/dp_34"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user