From a77620f6a632e3a19d0676c89ee69f07a59c7c0e Mon Sep 17 00:00:00 2001 From: Bruno Lazarini Sigg Date: Thu, 19 Dec 2024 16:39:39 +0100 Subject: [PATCH] feat: modify filter to reflect changes in map filter --- .../android/periodpals/ui/alert/AlertLists.kt | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/android/periodpals/ui/alert/AlertLists.kt b/app/src/main/java/com/android/periodpals/ui/alert/AlertLists.kt index 79f44f536..d80d8296d 100644 --- a/app/src/main/java/com/android/periodpals/ui/alert/AlertLists.kt +++ b/app/src/main/java/com/android/periodpals/ui/alert/AlertLists.kt @@ -70,6 +70,7 @@ import com.android.periodpals.resources.ComponentColor.getFilledPrimaryButtonCol import com.android.periodpals.resources.ComponentColor.getPrimaryCardColors import com.android.periodpals.resources.ComponentColor.getTertiaryCardColors import com.android.periodpals.services.GPSServiceImpl +import com.android.periodpals.ui.components.FILTERS_NO_PREFERENCE_TEXT import com.android.periodpals.ui.components.FilterDialog import com.android.periodpals.ui.components.FilterFab import com.android.periodpals.ui.components.formatAlertTime @@ -208,27 +209,32 @@ fun AlertListsScreen( context = context, currentRadius = radiusInMeters, location = selectedLocation, - product = productToPeriodPalsIcon(productFilter!!).textId, + product = productFilter?.let { productToPeriodPalsIcon(it).textId } + ?: FILTERS_NO_PREFERENCE_TEXT, urgency = - if (urgencyFilter == null) context.getString(R.string.alert_lists_filter_default) - else urgencyToPeriodPalsIcon(urgencyFilter!!).textId, + urgencyFilter?.let { + urgencyToPeriodPalsIcon(it).textId + } ?: FILTERS_NO_PREFERENCE_TEXT, onDismiss = { showFilterDialog = false }, onLocationSelected = { selectedLocation = it }, onSave = { radius, product, urgency -> radiusInMeters = radius productFilter = stringToProduct(product) urgencyFilter = stringToUrgency(urgency) - isFilterApplied = true - if (selectedLocation != null) { + isFilterApplied = + (radius != 100.0) || + (productFilter != Product.NO_PREFERENCE) || + (urgencyFilter != null) + + selectedLocation?.let { alertViewModel.fetchAlertsWithinRadius( - selectedLocation!!, - radiusInMeters, - onSuccess = { - palsAlertsList = alertViewModel.palAlerts - Log.d(TAG, "Alerts within radius: $palsAlertsList") - }, - onFailure = { e -> Log.d(TAG, "Error fetching alerts within radius: $e") }) - } + location = it, + radius = radiusInMeters, + onSuccess = { + Log.d(TAG, "Successfully fetched alerts within radius: $radiusInMeters") + }, + onFailure = { e -> Log.e(TAG, "Error fetching alerts within radius", e) }) + } ?: Log.d(TAG, "Selected location is null") // if a product filter was selected, show only alerts with said product marked as needed // (or alerts with no product preference)