Skip to content

Commit ceec614

Browse files
authored
fixes for displaying FloorFilter facilitySelector when Sites are not present in the map (#153)
1 parent bcfe16d commit ceec614

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

toolkit/indoors/src/main/java/com/arcgismaps/toolkit/indoors/FloorFilter.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public fun FloorFilter(
139139
var isFacilitiesSelectorVisible by rememberSaveable { mutableStateOf(false) }
140140

141141
// get the current selected facility
142-
var selectedFacility = floorFilterState.onFacilityChanged.collectAsStateWithLifecycle().value
142+
val selectedFacility = floorFilterState.onFacilityChanged.collectAsStateWithLifecycle().value
143143

144144
// get the selected level ID
145145
val selectedLevelID = floorFilterState.onLevelChanged.collectAsStateWithLifecycle().value?.id
@@ -207,11 +207,14 @@ public fun FloorFilter(
207207
)
208208

209209
} else {
210+
val selectedLevelName = selectedFacility.levels.find { it.id == selectedLevelID }?.let {
211+
it.shortName.ifBlank { it.levelNumber }
212+
}
210213
// display only the selected floor level
211214
FloorLevelSelectButton(
212215
index = 0,
213216
selected = true,
214-
floorText = selectedFacility.levels.find { it.id == selectedLevelID }?.shortName.toString(),
217+
floorText = selectedLevelName.toString(),
215218
uiProperties = uiProperties,
216219
onFloorLevelSelected = {
217220
// display all floor levels when clicked
@@ -286,7 +289,7 @@ internal fun FloorListColumn(
286289
index = index,
287290
selected = currentFacility.levels[index].id == selectedLevelID,
288291
onFloorLevelSelected = onFloorLevelSelected,
289-
floorText = currentFacility.levels[index].shortName,
292+
floorText = currentFacility.levels[index].shortName.ifBlank { currentFacility.levels[index].levelNumber.toString() },
290293
uiProperties = uiProperties,
291294
)
292295
}

toolkit/indoors/src/main/java/com/arcgismaps/toolkit/indoors/SiteAndFacilitySelector.kt

+23-12
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ internal fun SiteAndFacilitySelector(
112112
)
113113
{
114114
Column {
115-
if (!isFacilitiesSelectorVisible) {
115+
// display the siteSelector
116+
if (!isFacilitiesSelectorVisible && floorFilterState.sites.isNotEmpty()) {
116117
// display the sites top bar
117118
SiteSelectorTopBar(
118119
uiProperties = uiProperties,
@@ -130,6 +131,8 @@ internal fun SiteAndFacilitySelector(
130131
onFacilitiesSelectorVisible(true)
131132
}
132133
} else {
134+
// display the facilitiesSelector
135+
133136
// display the facilities top bar
134137
FacilitySelectorTopBar(
135138
floorFilterState = floorFilterState,
@@ -211,15 +214,18 @@ internal fun FacilitySelectorTopBar(
211214
modifier = Modifier.height(65.dp).fillMaxWidth(),
212215
horizontalArrangement = Arrangement.SpaceBetween
213216
) {
214-
// a box is helpful to use a consistent clickable animation
215-
Box(
216-
modifier = Modifier.clickable { backToSiteButtonClicked() }
217-
) {
218-
Icon(
219-
modifier = Modifier.fillMaxHeight().padding(horizontal = 6.dp).size(24.dp),
220-
painter = painterResource(id = R.drawable.ic_chevron_left_32),
221-
contentDescription = "Go Back to Site Selector"
222-
)
217+
// if there are no sites, do not allow going back to the siteSelector from facilitySelector
218+
if (floorFilterState.sites.isNotEmpty()) {
219+
// a box is helpful to use a consistent clickable animation
220+
Box(
221+
modifier = Modifier.clickable { backToSiteButtonClicked() }
222+
) {
223+
Icon(
224+
modifier = Modifier.fillMaxHeight().padding(horizontal = 6.dp).size(24.dp),
225+
painter = painterResource(id = R.drawable.ic_chevron_left_32),
226+
contentDescription = "Go Back to Site Selector"
227+
)
228+
}
223229
}
224230
Divider(
225231
color = Color.LightGray,
@@ -245,7 +251,7 @@ internal fun FacilitySelectorTopBar(
245251

246252
Text(
247253
text = stringResource(R.string.floor_filter_site_selector_top_bar) +
248-
floorFilterState.getSelectedSite()?.name.toString(),
254+
(floorFilterState.getSelectedSite()?.name ?: "not available"),
249255
fontSize = 15.sp,
250256
color = Color.Gray
251257
)
@@ -284,6 +290,11 @@ internal fun SitesAndFacilitiesFilter(
284290
// focus manager is used to clear focus from OutlinedTextField on search
285291
val focusManager = LocalFocusManager.current
286292

293+
val facilitiesAtSelectedSite = if (floorFilterState.sites.isNotEmpty())
294+
floorFilterState.getSelectedSite()?.facilities
295+
else
296+
floorFilterState.facilities
297+
287298
// list of all the site/facility names to display when no search prompt is used
288299
val allSitesOrFacilities: MutableList<SiteFacilityWrapper> =
289300
if (!isFacilitiesSelectorVisible)
@@ -294,7 +305,7 @@ internal fun SitesAndFacilitiesFilter(
294305
)
295306
}.toMutableList()
296307
else
297-
floorFilterState.getSelectedSite()?.facilities?.map { floorFacility ->
308+
facilitiesAtSelectedSite?.map { floorFacility ->
298309
SiteFacilityWrapper(
299310
facility = floorFacility,
300311
isSelected = floorFacility.id == floorFilterState.selectedFacilityId

0 commit comments

Comments
 (0)