8000 fix: [ANDROAPP-6349] Prevents crash on map layer dialog and an orientation change by ferdyrod · Pull Request #4097 · dhis2/dhis2-android-capture-app · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

fix: [ANDROAPP-6349] Prevents crash on map layer dialog and an orientation change #4097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
8000 Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ class EventMapFragment :
eventMapManager?.takeIf { it.isMapReady() }?.update(
data.featureCollectionMap,
data.boundingBox,
)
).also {
presenter.mapManager = eventMapManager
}
}
}

Expand Down Expand Up @@ -132,12 +134,11 @@ class EventMapFragment :
)
},
) {
MapLayerDialog(eventMapManager!!, presenter.programUid()) { layersVisibility ->
val mapLayerDialog = MapLayerDialog.newInstance(presenter.programUid())
mapLayerDialog.mapManager = presenter.mapManager
mapLayerDialog.setOnLayersVisibilityListener { layersVisibility ->
presenter.filterVisibleMapItems(layersVisibility)
}.show(
childFragmentManager,
MapLayerDialog::class.java.name,
)
}.show(childFragmentManager, MapLayerDialog::class.java.name)
}
locationState?.let {
LocationIcon(
Expand Down Expand Up @@ -218,6 +219,9 @@ class EventMapFragment :
programEventsViewModel.setProgress(true)
presenter.getEventInfo(eventUid)
}
val exists = childFragmentManager
.findFragmentByTag(MapLayerDialog::class.java.name) as MapLayerDialog?
exists?.dismiss()
}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.dhis2.commons.schedulers.SchedulerProvider
import org.dhis2.commons.schedulers.defaultSubscribe
import org.dhis2.maps.extensions.toStringProperty
import org.dhis2.maps.layer.MapLayer
import org.dhis2.maps.managers.MapManager
import org.dhis2.usescases.programEventDetail.ProgramEventDetailRepository
import org.dhis2.usescases.programEventDetail.ProgramEventMapData
import org.hisp.dhis.android.core.common.FeatureType
Expand All @@ -27,6 +28,7 @@ class EventMapPresenter(
) {

private var layersVisibility: Map<String, MapLayer> = emptyMap()
var mapManager: MapManager? = null

private val _eventMapData = MutableLiveData<ProgramEventMapData>()
val eventMapData: LiveData<ProgramEventMapData> = _eventMapData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import org.dhis2.form.ui.provider.DisplayNameProvider
import org.dhis2.maps.extensions.toStringProperty
import org.dhis2.maps.layer.MapLayer
import org.dhis2.maps.layer.basemaps.BaseMapStyle
import org.dhis2.maps.managers.MapManager
import org.dhis2.maps.usecases.MapStyleConfiguration
import org.dhis2.mobile.commons.coroutine.CoroutineTracker
import org.dhis2.tracker.NavigationBarUIState
Expand Down Expand Up @@ -134,6 +135,8 @@ class SearchTEIViewModel(

var uiState by mutableStateOf(SearchParametersUiState())

var mapManager: MapManager? = null

private var fetchJob: Job? = null

private val = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ class SearchTEMap : FragmentGlobalAbstract() {
data.eventFeatures,
data.dataElementFeaturess,
data.teiBoundingBox,
)
).also {
viewModel.mapManager = teiMapManager
}
}
}

Expand Down Expand Up @@ -190,10 +192,15 @@ class SearchTEMap : FragmentGlobalAbstract() {
)
},
) {
MapLayerDialog(teiMapManager!!, viewModel.initialProgramUid) { layersVisibility ->
val mapLayerDialog = MapLayerDialog.newInstance(viewModel.initialProgramUid)
mapLayerDialog.mapManager = viewModel.mapManager
mapLayerDialog.setOnLayersVisibilityListener { layersVisibility ->
viewModel.filterVisibleMapItems(layersVisibility)
}
.show(childFragmentManager, MapLayerDialog::class.java.name)
mapLayerDialog.show(
childFragmentManager,
MapLayerDialog::class.java.name,
)
}
locationState?.let {
LocationIcon(
Expand Down Expand Up @@ -326,6 +333,13 @@ class SearchTEMap : FragmentGlobalAbstract() {
teiMapManager?.onSaveInstanceState(outState)
}

override fun onResume() {
super.onResume()
val exists = childFragmentManager
.findFragmentByTag(MapLayerDialog::class.java.name) as MapLayerDialog?
exists?.dismiss()
}

@Deprecated("Deprecated in Java")
override fun onRequestPermissionsResult(
requestCode: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ class RelationshipFragment : FragmentGlobalAbstract(), RelationshipView {
},
) {
relationshipMapManager?.let {
MapLayerDialog(it, programUid()) { layersVisibility ->
val dialog = MapLayerDialog.newInstance(programUid())
dialog.mapManager = it
dialog.setOnLayersVisibilityListener { layersVisibility ->
presenter.filterVisibleMapItems(layersVisibility)
}.show(
childFragmentManager,
MapLayerDialog::class.java.name,
)
}
.show(childFragmentManager, MapLayerDialog::class.java.name)
}
}
locationState?.let {
Expand Down Expand Up @@ -386,6 +386,9 @@ class RelationshipFragment : FragmentGlobalAbstract(), RelationshipView {
super.onResume()
presenter.init()
relationShipsViewModel.refreshRelationships()
val exists = childFragmentManager
.findFragmentByTag(MapLayerDialog::class.java.name) as MapLayerDialog?
exists?.dismiss()
}

override fun onPause() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import org.dhis2.maps.managers.EventMapManager
import org.dhis2.maps.managers.MapManager
import org.dhis2.maps.managers.RelationshipMapManager.Companion.RELATIONSHIP_ICON

class MapLayerDialog(
private val mapManager: MapManager,
private val programUid: String?,
private val onLayersVisibility: (layersVisibility: HashMap<String, MapLayer>) -> Unit = {},
) : BottomSheetDialogFragment() {
class MapLayerDialog : BottomSheetDialogFragment() {

var mapManager: MapManager? = null
private var programUid: String? = null
private var onLayersVisibility: (layersVisibility: HashMap<String, MapLayer>) -> Unit = {}

private val layerVisibility: HashMap<String, Boolean> = hashMapOf()
lateinit var binding: DialogMapLayerBinding
Expand All @@ -51,6 +51,7 @@ class MapLayerDialog(
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme)
programUid = arguments?.getString(ARG_PROGRAM_UID)
}

override fun onCreateView(
Expand All @@ -59,7 +60,9 @@ class MapLayerDialog(
savedInstanceState: Bundle?,
): View {
binding = DataBindingUtil.inflate(inflater, R.layout.dialog_map_layer, container, false)
binding.baseMapCarousel.adapter = BasemapAdapter(mapManager.mapLayerManager)
mapManager?.let {
binding.baseMapCarousel.adapter = BasemapAdapter(it.mapLayerManager)
}
binding.acceptButton.setTextColor(
ColorStateList.valueOf(
requireContext().getPrimaryColor(ColorType.PRIMARY),
Expand Down Expand Up @@ -111,6 +114,23 @@ class MapLayerDialog(
return dialog
}

fun setOnLayersVisibilityListener(listener: (HashMap<String, MapLayer>) -> Unit): MapLayerDialog {
this.>
return this
}

companion object {
private const val ARG_PROGRAM_UID = "programUid"

fun newInstance(programUid: String?): MapLayerDialog {
return MapLayerDialog().apply {
arguments = Bundle().apply {
putString(ARG_PROGRAM_UID, programUid)
}
}
}
}

private fun initProgramData() {
val layerMap: LinkedHashMap<String, MutableList<View>> = linkedMapOf(
Pair("TEI", mutableListOf()),
Expand All @@ -121,7 +141,7 @@ class MapLayerDialog(
Pair("DE", mutableListOf()),
Pair("HEATMAP", mutableListOf()),
)
mapManager.mapLayerManager.mapLayers.toSortedMap().forEach { (source, layer) ->
mapManager?.mapLayerManager?.mapLayers?.toSortedMap()?.forEach { (source, layer) ->
layerVisibility[source] ?: run { layerVisibility[source] = layer.visible }
when (layer) {
is TeiMapLayer -> layerMap["TEI"]?.add(
Expand Down Expand Up @@ -178,7 +198,7 @@ class MapLayerDialog(
is FieldMapLayer -> layerMap["DE"]?.add(
addCheckBox(
source,
mapManager.getLayerName(source),
mapManager?.getLayerName(source),
"${EventMapManager.DE_ICON_ID}_$source",
),
)
Expand All @@ -196,11 +216,11 @@ class MapLayerDialog(
private fun initListeners() {
binding.acceptButton.setOnClickListener {
layerVisibility.forEach { (sourceId, visible) ->
mapManager.mapLayerManager.handleLayer(sourceId, visible)
mapManager?.mapLayerManager?.handleLayer(sourceId, visible)
}
mapManager?.let {
onLayersVisibility(it.updateLayersVisibility(layerVisibility))
}
onLayersVisibility(
mapManager.updateLayersVisibility(layerVisibility),
)
dismiss()
}
}
Expand Down Expand Up @@ -229,11 +249,11 @@ class MapLayerDialog(
if (it == HEATMAP_ICON) {
layerIcon.setImageResource(R.drawable.ic_heatmap_icon)
} else {
layerIcon.setImageBitmap(
mapManager.mapLayerManager.mapBoxMap.style?.getImage(
image,
),
)
mapManager?.let { manager ->
layerIcon.setImageBitmap(
manager.mapLayerManager.mapBoxMap.style?.getImage(image),
)
}
}
}
}.root
Expand Down
0