fix the bug of map reset

This commit is contained in:
Chengxu Yang 2025-10-12 20:59:05 +11:00
parent 14d6c80241
commit 0523416e78
2 changed files with 27 additions and 1 deletions

View file

@ -91,6 +91,7 @@ public class NearbyFilterSearchRecyclerViewAdapter
label.setSelected(!label.isSelected()); label.setSelected(!label.isSelected());
holder.placeTypeLayout.setSelected(label.isSelected()); holder.placeTypeLayout.setSelected(label.isSelected());
NearbyFilterState.setSelectedLabels(new ArrayList<>(selectedLabels));
callback.filterByMarkerType(selectedLabels, 0, false, false); callback.filterByMarkerType(selectedLabels, 0, false, false);
}); });
} }
@ -152,6 +153,7 @@ public class NearbyFilterSearchRecyclerViewAdapter
label.setSelected(false); label.setSelected(false);
selectedLabels.remove(label); selectedLabels.remove(label);
} }
NearbyFilterState.setSelectedLabels(new ArrayList<>(selectedLabels));
notifyDataSetChanged(); notifyDataSetChanged();
} }
@ -163,6 +165,7 @@ public class NearbyFilterSearchRecyclerViewAdapter
selectedLabels.add(label); selectedLabels.add(label);
} }
} }
NearbyFilterState.setSelectedLabels(new ArrayList<>(selectedLabels));
notifyDataSetChanged(); notifyDataSetChanged();
} }

View file

@ -881,6 +881,12 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
fun initNearbyFilter() { fun initNearbyFilter() {
binding!!.nearbyFilterList.root.visibility = View.GONE binding!!.nearbyFilterList.root.visibility = View.GONE
hideBottomSheet() hideBottomSheet()
binding!!.nearbyFilter.searchViewLayout.searchView.apply {
setIconifiedByDefault(false)
isIconified = false
setQuery("", false)
clearFocus()
}
binding!!.nearbyFilter.searchViewLayout.searchView.setOnQueryTextFocusChangeListener { v, hasFocus -> binding!!.nearbyFilter.searchViewLayout.searchView.setOnQueryTextFocusChangeListener { v, hasFocus ->
setLayoutHeightAlignedToWidth( setLayoutHeightAlignedToWidth(
1.25, 1.25,
@ -924,6 +930,7 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
return _isDarkTheme return _isDarkTheme
} }
}) })
restoreStoredFilterSelection()
binding!!.nearbyFilterList.root binding!!.nearbyFilterList.root
.layoutParams.width = getScreenWidth( .layoutParams.width = getScreenWidth(
requireActivity(), requireActivity(),
@ -942,6 +949,22 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
}) })
} }
private fun restoreStoredFilterSelection() {
val adapter = nearbyFilterSearchRecyclerViewAdapter ?: return
val savedLabels = ArrayList(NearbyFilterState.getInstance().selectedLabels)
adapter.selectedLabels.clear()
val savedSet = savedLabels.toSet()
Label.valuesAsList().forEach { label ->
val isSelected = savedSet.contains(label)
label.setSelected(isSelected)
if (isSelected) {
adapter.selectedLabels.add(label)
}
}
NearbyFilterState.setSelectedLabels(ArrayList(adapter.selectedLabels))
adapter.notifyDataSetChanged()
}
override fun setCheckBoxAction() { override fun setCheckBoxAction() {
binding!!.nearbyFilterList.checkboxTriStates.addAction() binding!!.nearbyFilterList.checkboxTriStates.addAction()
binding!!.nearbyFilterList.checkboxTriStates.state = CheckBoxTriStates.UNKNOWN binding!!.nearbyFilterList.checkboxTriStates.state = CheckBoxTriStates.UNKNOWN
@ -2987,4 +3010,4 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(),
return input.contains("(") || input.contains(")") return input.contains("(") || input.contains(")")
} }
} }
} }