oday
03/06/2018, 8:01 AMAndreas Sinz
03/06/2018, 8:14 AMfold
over the list of filters and the car listif(selectedCarModelId != null)
filters.add { selectedCarModelId == it.model_id }
if(selectedCarSubModelId != null)
filters.add { selectedCarSubModelId == it.submodel_id }
filters.fold(carList) { cars, filter -> cars.filter(::filter) }
oday
03/06/2018, 8:17 AMfilters
value would be mutableListOf({})
?Andreas Sinz
03/06/2018, 8:19 AMmutableListOf<(YourCarType) -> Boolean>()
oday
03/06/2018, 8:19 AMAndreas Sinz
03/06/2018, 8:20 AMCar
and returns a Boolean
oday
03/06/2018, 8:20 AMAndreas Sinz
03/06/2018, 8:23 AMfold
then just takes the original list of cars and applies every filter
to your list and returns the filtered list of carskristofdho
03/06/2018, 8:29 AMcarListings.filter {
(selectedCarModelId == null || selectedCarModelId == it.model_id)
&& (selectedCarSubModelId == null || selectedCarSubModelId == it.submodel_id)
&& (selectedCarTrimId == null || selectedCarTrimId == it.trim_id)
&& (fromYearSelected == null || fromYearSelected < it.year)
&& (toYearSelected == null || toYearSelected > it.year)
&& it.mileage < mileageValue
&& it.price < budgetValue
}
oday
03/06/2018, 8:31 AMAndreas Sinz
03/06/2018, 8:32 AModay
03/06/2018, 8:33 AMkristofdho
03/06/2018, 8:34 AModay
03/06/2018, 8:35 AMkristofdho
03/06/2018, 8:36 AMvar budgetValue = try {
nf.parse(budgetValueTV.text.toString()).toInt()
} catch (e: ParseException) {
Timber.d("Budget was never entered because in offline mode.")
return emptyList()
}
budgetValue
after thatoday
03/06/2018, 8:36 AMkristofdho
03/06/2018, 8:36 AModay
03/06/2018, 8:36 AMAndreas Sinz
03/06/2018, 8:39 AMit.price < budgetValue
and now its budgetValue < it.price
. same for mileageoday
03/06/2018, 8:40 AMkristofdho
03/06/2018, 8:45 AModay
03/06/2018, 8:45 AMAndreas Sinz
03/06/2018, 8:54 AM