diff --git a/app/src/main/java/net/vonforst/evmap/model/FiltersModel.kt b/app/src/main/java/net/vonforst/evmap/model/FiltersModel.kt index 66587561..2693aa90 100644 --- a/app/src/main/java/net/vonforst/evmap/model/FiltersModel.kt +++ b/app/src/main/java/net/vonforst/evmap/model/FiltersModel.kt @@ -48,6 +48,8 @@ sealed class FilterValue : BaseObservable(), Equatable { abstract val key: String var dataSource: String = "" var profile: Long = FILTERS_CUSTOM + + abstract fun hasSameValueAs(other: FilterValue): Boolean } @Entity( @@ -62,7 +64,11 @@ sealed class FilterValue : BaseObservable(), Equatable { data class BooleanFilterValue( override val key: String, var value: Boolean -) : FilterValue() +) : FilterValue() { + override fun hasSameValueAs(other: FilterValue): Boolean { + return other is BooleanFilterValue && other.value == this.value + } +} @Entity( foreignKeys = [ForeignKey( @@ -78,23 +84,14 @@ data class MultipleChoiceFilterValue( var values: MutableSet, var all: Boolean ) : FilterValue() { - override fun equals(other: Any?): Boolean { - if (other == null || other !is MultipleChoiceFilterValue) return false - if (key != other.key) return false - return if (all) { - other.all + override fun hasSameValueAs(other: FilterValue): Boolean { + return other is MultipleChoiceFilterValue && if (other.all) { + this.all } else { - !other.all && values == other.values + !this.all && other.values == this.values } } - - override fun hashCode(): Int { - var result = key.hashCode() - result = 31 * result + all.hashCode() - result = 31 * result + if (all) 0 else values.hashCode() - return result - } } @Entity( @@ -109,7 +106,11 @@ data class MultipleChoiceFilterValue( data class SliderFilterValue( override val key: String, var value: Int -) : FilterValue() +) : FilterValue() { + override fun hasSameValueAs(other: FilterValue): Boolean { + return other is SliderFilterValue && other.value == this.value + } +} data class FilterWithValue(val filter: Filter, val value: T) : Equatable diff --git a/app/src/main/java/net/vonforst/evmap/viewmodel/FilterViewModel.kt b/app/src/main/java/net/vonforst/evmap/viewmodel/FilterViewModel.kt index e940264b..2f70c740 100644 --- a/app/src/main/java/net/vonforst/evmap/viewmodel/FilterViewModel.kt +++ b/app/src/main/java/net/vonforst/evmap/viewmodel/FilterViewModel.kt @@ -97,7 +97,6 @@ class FilterViewModel(application: Application) : AndroidViewModel(application) val value = it.value value.profile = FILTERS_CUSTOM value.dataSource = prefs.dataSource - db.filterValueDao().insert(value) value }?.let { db.filterValueDao().insert(*it.toTypedArray()) diff --git a/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt b/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt index 6f4e1688..8ad8a5e4 100644 --- a/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt +++ b/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt @@ -124,7 +124,7 @@ class MapViewModel(application: Application) : AndroidViewModel(application) { value = 0 addSource(filtersWithValue) { filtersWithValue -> value = filtersWithValue.count { - it.filter.defaultValue() != it.value + !it.value.hasSameValueAs(it.filter.defaultValue()) } } }