|
|
|
|
@ -4,7 +4,9 @@ import io.realm.MutableRealmInteger |
|
|
|
|
import io.realm.RealmList |
|
|
|
|
import io.realm.RealmObject |
|
|
|
|
import io.realm.annotations.PrimaryKey |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategory |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElement |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSection |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
//import net.pokeranalytics.android.FilterComponent |
|
|
|
|
@ -25,31 +27,66 @@ open class Filter : RealmObject() { |
|
|
|
|
var components: RealmList<FilterComponent> = RealmList() |
|
|
|
|
|
|
|
|
|
fun componentsFrom(filterElements: ArrayList<FilterElement>) { |
|
|
|
|
|
|
|
|
|
components.clear() |
|
|
|
|
|
|
|
|
|
var sections = filterElements.mapNotNull { |
|
|
|
|
it.filterSection |
|
|
|
|
}.distinct() |
|
|
|
|
|
|
|
|
|
sections.forEach { section -> |
|
|
|
|
var _filterElements = filterElements.filter { |
|
|
|
|
it.filterSection?.let { _section -> |
|
|
|
|
_section == section |
|
|
|
|
} ?: run { |
|
|
|
|
false |
|
|
|
|
} |
|
|
|
|
filterElements |
|
|
|
|
.map { |
|
|
|
|
it.filterSection |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (_filterElements.size == 1) { |
|
|
|
|
var component : FilterComponent = FilterComponent(_filterElements.first()) |
|
|
|
|
components.add(component) |
|
|
|
|
} else { |
|
|
|
|
var casted = arrayListOf<FilterElement>() |
|
|
|
|
casted.addAll(_filterElements) |
|
|
|
|
var component : FilterComponent = FilterComponent(casted) |
|
|
|
|
components.add(component) |
|
|
|
|
.distinct() |
|
|
|
|
.forEach { section -> |
|
|
|
|
filterElements |
|
|
|
|
.filter { |
|
|
|
|
it.filterSection == section |
|
|
|
|
} |
|
|
|
|
.apply { |
|
|
|
|
if (this.size == 1) { |
|
|
|
|
components.add(FilterComponent(this.first())) |
|
|
|
|
} else { |
|
|
|
|
val casted = arrayListOf<FilterElement>() |
|
|
|
|
casted.addAll(this) |
|
|
|
|
components.add(FilterComponent(casted)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun numberOfElementIn(filterCategory: FilterCategory) : Int { |
|
|
|
|
val sections = FilterSection.filterSectionsFor(filterCategory) |
|
|
|
|
return components.count { |
|
|
|
|
sections.contains(FilterSection.valueOf(it.sectionName)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun isFilterElementExists(filterElement:FilterElement) : Boolean { |
|
|
|
|
|
|
|
|
|
val filtered = components.filter { |
|
|
|
|
it.filterType == filterElement.filterType |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (filtered.isEmpty()) { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return when (filterElement) { |
|
|
|
|
is FilterElement.Game -> filtered.filter { |
|
|
|
|
it.ids?.contains(filterElement.game.id) ?: false |
|
|
|
|
}.isNotEmpty() |
|
|
|
|
is FilterElement.Year -> TODO() |
|
|
|
|
is FilterElement.Month -> TODO() |
|
|
|
|
is FilterElement.Day -> TODO() |
|
|
|
|
is FilterElement.Limit -> TODO() |
|
|
|
|
is FilterElement.TableSize -> TODO() |
|
|
|
|
is FilterElement.Bankroll -> TODO() |
|
|
|
|
is FilterElement.Location -> TODO() |
|
|
|
|
is FilterElement.TournamentName -> TODO() |
|
|
|
|
is FilterElement.TournamentFeature -> TODO() |
|
|
|
|
|
|
|
|
|
is FilterElement.From -> TODO() |
|
|
|
|
is FilterElement.To -> TODO() |
|
|
|
|
is FilterElement.PastDays -> TODO() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else -> return true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|