Merge branch 'dev' of gitlab.com:stax-river/poker-analytics into dev

feature/top10
Laurent 7 years ago
commit b12949a077
  1. BIN
      app/src/androidTest/assets/schema_2.realm
  2. 13
      app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt
  3. 52
      app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt
  4. 114
      app/src/main/java/net/pokeranalytics/android/model/realm/FilterCondition.kt
  5. 43
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  6. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  7. 5
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt
  8. 53
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt
  9. 107
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt
  10. 22
      app/src/main/java/net/pokeranalytics/android/util/extensions/DateExtension.kt

@ -6,7 +6,11 @@ import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.realm.FilterCondition import net.pokeranalytics.android.model.realm.FilterCondition
import net.pokeranalytics.android.model.realm.FilterElementBlind import net.pokeranalytics.android.model.realm.FilterElementBlind
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import java.time.*
import java.util.* import java.util.*
import java.time.temporal.TemporalQueries.zoneId
/** /**
@ -58,6 +62,12 @@ enum class QueryCondition(var operator: Operator? = null) {
YEAR, YEAR,
WEEK_DAY, WEEK_DAY,
WEEK_END, WEEK_END,
TODAY,
YESTERDAY,
TODAY_AND_YESTERDAY,
THIS_WEEK,
THIS_MONTH,
THIS_YEAR,
CURRENCY, CURRENCY,
CURRENCY_CODE, CURRENCY_CODE,
@ -232,6 +242,9 @@ enum class QueryCondition(var operator: Operator? = null) {
} }
query.`in`(fieldName, arrayOf(Calendar.SATURDAY, Calendar.SUNDAY)) query.`in`(fieldName, arrayOf(Calendar.SATURDAY, Calendar.SUNDAY))
} }
TODAY, YESTERDAY, TODAY_AND_YESTERDAY, THIS_WEEK, THIS_MONTH, THIS_YEAR -> {
realmQuery
}
else -> { else -> {
throw PokerAnalyticsException.QueryTypeUnhandled throw PokerAnalyticsException.QueryTypeUnhandled
} }

@ -19,25 +19,25 @@ import java.util.*
*/ */
open class Filter : RealmObject() { open class Filter : RealmObject() {
private var entityType : Int? = Entity.SESSION.ordinal private var entityType: Int? = Entity.SESSION.ordinal
private enum class Entity { private enum class Entity {
SESSION, SESSION,
; ;
} }
companion object { companion object {
// Create a new instance // Create a new instance
fun newInstance(realm: Realm) : Filter { fun newInstance(realm: Realm): Filter {
val filter = Filter() val filter = Filter()
return realm.copyToRealm(filter) return realm.copyToRealm(filter)
} }
// Get a filter by its id // Get a filter by its id
fun getFilterBydId(realm: Realm, filterId: String) : Filter? { fun getFilterBydId(realm: Realm, filterId: String): Filter? {
return realm.where<Filter>().equalTo("id", filterId).findFirst() return realm.where<Filter>().equalTo("id", filterId).findFirst()
} }
@TestOnly @TestOnly
inline fun <reified T : Filterable> queryOn(realm: Realm, queries: List<QueryCondition>): RealmResults<T> { inline fun <reified T : Filterable> queryOn(realm: Realm, queries: List<QueryCondition>): RealmResults<T> {
@ -49,15 +49,15 @@ open class Filter : RealmObject() {
} }
} }
@PrimaryKey @PrimaryKey
var id = UUID.randomUUID().toString() var id = UUID.randomUUID().toString()
// the filter name // the filter name
var name: String = "" var name: String = ""
// the number of use of the filter, // the number of use of the filter,
// for MutableRealmInteger, see https://realm.io/docs/java/latest/#counters // for MutableRealmInteger, see https://realm.io/docs/java/latest/#counters
val usageCount: MutableRealmInteger = MutableRealmInteger.valueOf(0) val usageCount: MutableRealmInteger = MutableRealmInteger.valueOf(0)
var filterConditions: RealmList<FilterCondition> = RealmList() var filterConditions: RealmList<FilterCondition> = RealmList()
private set private set
@ -84,9 +84,9 @@ open class Filter : RealmObject() {
filterConditions.add(FilterCondition(casted)) filterConditions.add(FilterCondition(casted))
} }
} }
} }
} }
fun countBy(filterCategoryRow: FilterCategoryRow) : Int { fun countBy(filterCategoryRow: FilterCategoryRow) : Int {
val sections = filterCategoryRow.filterSectionRows val sections = filterCategoryRow.filterSectionRows
@ -113,7 +113,7 @@ open class Filter : RealmObject() {
realmQuery = it.filter(realmQuery) realmQuery = it.filter(realmQuery)
} }
return realmQuery.findAll() return realmQuery.findAll()
} }
} }

@ -18,16 +18,24 @@ open class FilterCondition() : RealmObject() {
constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) { constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) {
val filterName : String = this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName val filterName : String = this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName
this.stringValues = when (QueryCondition.valueOf(filterName)) { this.stringValues = when (QueryCondition.valueOf(filterName)) {
QueryCondition.GAME, QueryCondition.BANKROLL, QueryCondition.TOURNAMENT_NAME, QueryCondition.ALL_TOURNAMENT_FEATURES, QueryCondition.ANY_TOURNAMENT_FEATURES, QueryCondition.LOCATION -> { QueryCondition.GAME, QueryCondition.BANKROLL, QueryCondition.TOURNAMENT_NAME, QueryCondition.ALL_TOURNAMENT_FEATURES, QueryCondition.ANY_TOURNAMENT_FEATURES, QueryCondition.LOCATION -> {
RealmList<String>().apply { RealmList<String>().apply {
this.addAll(filterElementRows.map { this.addAll(filterElementRows.map {
(it as DataFilterElementRow).id (it as DataFilterElementRow).id
}) })
} }
} }
else -> null QueryCondition.LIMIT, QueryCondition.TABLE_SIZE -> {
RealmList<String>().apply {
this.addAll(filterElementRows.map {
(it as StaticDataFilterElementRow).id
})
}
}
else -> null
} }
this.numericValues = when (QueryCondition.valueOf(filterName)) { this.numericValues = when (QueryCondition.valueOf(filterName)) {
QueryCondition.LIMIT -> { QueryCondition.LIMIT -> {
RealmList<Double>().apply { RealmList<Double>().apply {
@ -79,15 +87,15 @@ open class FilterCondition() : RealmObject() {
} }
} }
constructor(filterElementRow:FilterElementRow) : this(arrayListOf(filterElementRow)) { constructor(filterElementRow: FilterElementRow) : this(arrayListOf(filterElementRow)) {
when (filterElementRow) { when (filterElementRow) {
is From -> dateValue = filterElementRow.date is From -> dateValue = filterElementRow.date
is To -> dateValue= filterElementRow.date is To -> dateValue = filterElementRow.date
} }
} }
var filterName : String? = null var filterName: String? = null
var sectionName : String? = null var sectionName: String? = null
val queryCondition : QueryCondition val queryCondition : QueryCondition
get() = QueryCondition.valueOf(this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName) get() = QueryCondition.valueOf(this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName)
@ -95,58 +103,58 @@ open class FilterCondition() : RealmObject() {
this.updateValueMap(this@FilterCondition) this.updateValueMap(this@FilterCondition)
} }
private var numericValues: RealmList<Double>? = null private var numericValues: RealmList<Double>? = null
private var dateValue : Date? = null private var dateValue: Date? = null
private var stringValues : RealmList<String>? = null private var stringValues: RealmList<String>? = null
private var blindValues : RealmList<FilterElementBlind>? = null private var blindValues: RealmList<FilterElementBlind>? = null
val ids : Array<String> val ids: Array<String>
get() = stringValues?.toTypedArray()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = stringValues?.toTypedArray() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val blinds : RealmList<FilterElementBlind> val blinds: RealmList<FilterElementBlind>
get() { get() {
blindValues?.let { blindValues?.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
return it return it
} else { } else {
throw PokerAnalyticsException.FilterElementExpectedValueMissing throw PokerAnalyticsException.FilterElementExpectedValueMissing
} }
} }
throw PokerAnalyticsException.FilterElementExpectedValueMissing throw PokerAnalyticsException.FilterElementExpectedValueMissing
} }
val date : Date val date: Date
get() = dateValue?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = dateValue ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val values : Array<Int> val values: Array<Int>
get() = numericValues?.map { get() = numericValues?.map {
it.toInt() it.toInt()
}?.toTypedArray()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing }?.toTypedArray() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val value : Double val value: Double
get() = numericValues?.first()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.first() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val leftValue : Double val leftValue: Double
get() = numericValues?.first()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.first() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val rightValue : Double val rightValue: Double
get() = numericValues?.last()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.last() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val dayOfWeek : Int val dayOfWeek: Int
get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val month : Int val month: Int
get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
val year : Int val year: Int
get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
} }

@ -18,6 +18,7 @@ import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
@ -60,24 +61,37 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
super.onRowSelected(position, row, fromAction) super.onRowSelected(position, row, fromAction)
val oldRows = ArrayList<RowRepresentable>() Timber.d("Row: $row")
oldRows.addAll(rows)
if (selectedRows.contains(row)) { when (row) {
selectedRows.remove(row) is FilterElementRow.ResultMoreThan -> {
} else { val data = row.editingDescriptors(mapOf("defaultValue" to ""))
if (row is FilterElementRow) { BottomSheetFragment.create(fragmentManager, row, this, data, null)
row.sectionToExclude?.let { filterSectionToExclude -> }
val excludedFilters = selectedRows.filter { else -> {
filterSectionToExclude.contains(it.filterSectionRow)
} val oldRows = ArrayList<RowRepresentable>()
excludedFilters.forEach { oldRows.addAll(rows)
selectedRows.remove(it) if (selectedRows.contains(row)) {
rowRepresentableAdapter.refreshRow(it) selectedRows.remove(row)
} else {
if (row is FilterElementRow) {
row.sectionToExclude?.let { filterSectionToExclude ->
val excludedFilters = selectedRows.filter {
filterSectionToExclude.contains(it.filterSectionRow)
}
excludedFilters.forEach {
selectedRows.remove(it)
rowRepresentableAdapter.refreshRow(it)
}
}
selectedRows.add(row)
} }
} }
selectedRows.add(row)
} }
} }
/* /*
Timber.d("Row: $row") Timber.d("Row: $row")
when (row) { when (row) {
@ -103,6 +117,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta
override fun onRowValueChanged(value: Any?, row: RowRepresentable) { override fun onRowValueChanged(value: Any?, row: RowRepresentable) {
super.onRowValueChanged(value, row) super.onRowValueChanged(value, row)
Timber.d("onRowValueChanged: $row $value")
selectedRows.add(row as FilterElementRow) selectedRows.add(row as FilterElementRow)
rowRepresentableAdapter.refreshRow(row) rowRepresentableAdapter.refreshRow(row)
} }

@ -76,9 +76,7 @@ enum class RowViewType(private var layoutRes: Int) {
HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG, HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG,
LOCATION_TITLE, INFO, LOCATION_TITLE, INFO,
TITLE, TITLE_ARROW, TITLE_VALUE, TITLE_VALUE_ARROW, TITLE_GRID, TITLE_SWITCH, TITLE_CHECK, TITLE_VALUE_CHECK, TITLE, TITLE_ARROW, TITLE_VALUE, TITLE_VALUE_ARROW, TITLE_GRID, TITLE_SWITCH, TITLE_CHECK, TITLE_VALUE_CHECK,
DATA, BOTTOM_SHEET_DATA, LOADER -> RowViewHolder( DATA, BOTTOM_SHEET_DATA, LOADER -> RowViewHolder(layout)
layout
)
// Row Session // Row Session
ROW_SESSION -> RowSessionViewHolder(layout) ROW_SESSION -> RowSessionViewHolder(layout)

@ -45,6 +45,10 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In
DAY_OF_WEEK, DAY_OF_WEEK,
MONTH_OF_YEAR MONTH_OF_YEAR
) )
TIME_FRAME -> arrayListOf(
SESSION_DURATION,
RANGE
)
BANKROLLS -> arrayListOf( BANKROLLS -> arrayListOf(
BANKROLL BANKROLL
) )
@ -74,7 +78,6 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In
VALUE VALUE
) )
TIME_FRAME -> arrayListOf()
SESSION -> arrayListOf() SESSION -> arrayListOf()
TRANSACTION_TYPES -> arrayListOf() TRANSACTION_TYPES -> arrayListOf()
} }

@ -30,13 +30,10 @@ sealed class FilterElementRow : RowRepresentable {
val name: String = (data as RowRepresentable).getDisplayName() val name: String = (data as RowRepresentable).getDisplayName()
} }
open class StaticDataFilterElementRow(var row: RowRepresentable) : FilterElementRow() { open class StaticDataFilterElementRow(var row: RowRepresentable, var id: String) : FilterElementRow() {
override val resId: Int? = row.resId override val resId: Int? = row.resId
val name: String = row.getDisplayName()
fun getDataDisplayName() : String {
return row.getDisplayName()
}
fun getDataLocalizedTitle(context: Context): String { fun getDataLocalizedTitle(context: Context): String {
return row.localizedTitle(context) return row.localizedTitle(context)
@ -52,8 +49,8 @@ sealed class FilterElementRow : RowRepresentable {
data class Month(val month: Int) : SingleValueFilterElementRow(month) data class Month(val month: Int) : SingleValueFilterElementRow(month)
data class Day(val day: Int) : SingleValueFilterElementRow(day) data class Day(val day: Int) : SingleValueFilterElementRow(day)
data class PastDays(var lastDays: Int = 0) : FilterElementRow() data class PastDays(var lastDays: Int = 0) : FilterElementRow()
data class Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit) data class Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit, limit.longName)
data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize) data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize, tableSize.numberOfPlayer.toString())
data class Bankroll(val bankroll: Manageable) : DataFilterElementRow(bankroll) data class Bankroll(val bankroll: Manageable) : DataFilterElementRow(bankroll)
data class Game(val game: Manageable) : DataFilterElementRow(game) data class Game(val game: Manageable) : DataFilterElementRow(game)
data class Location(val location: Manageable) : DataFilterElementRow(location) data class Location(val location: Manageable) : DataFilterElementRow(location)
@ -82,16 +79,15 @@ sealed class FilterElementRow : RowRepresentable {
is Online -> QueryCondition.ONLINE is Online -> QueryCondition.ONLINE
is Weekday -> QueryCondition.WEEK_DAY is Weekday -> QueryCondition.WEEK_DAY
is Weekend -> QueryCondition.WEEK_END is Weekend -> QueryCondition.WEEK_END
is Today -> QueryCondition.TODAY
/* is Yesterday -> QueryCondition.YESTERDAY
is Today -> QueryCondition. is TodayAndYesterday -> QueryCondition.TODAY_AND_YESTERDAY
is Yesterday -> R.string.yesterday is CurrentWeek -> QueryCondition.THIS_WEEK
is TodayAndYesterday -> R.string.yesterday_and_today is CurrentMonth -> QueryCondition.THIS_MONTH
is CurrentWeek -> R.string.current_week is CurrentYear -> QueryCondition.THIS_YEAR
is CurrentMonth -> R.string.current_month /*
is CurrentYear -> R.string.current_year is PastDays -> R.string.period_in_days
is PastDays -> R.string.period_in_days */
*/
is Limit -> QueryCondition.LIMIT is Limit -> QueryCondition.LIMIT
is TableSize -> QueryCondition.TABLE_SIZE is TableSize -> QueryCondition.TABLE_SIZE
@ -112,7 +108,10 @@ sealed class FilterElementRow : RowRepresentable {
is DataFilterElementRow -> filterConditions.any { is DataFilterElementRow -> filterConditions.any {
it.ids.contains(this.id) it.ids.contains(this.id)
} }
else -> return true is StaticDataFilterElementRow -> filterConditions.any {
it.ids.contains(this.id)
}
else -> true
} }
} }
@ -138,17 +137,25 @@ sealed class FilterElementRow : RowRepresentable {
is Month -> R.string.month_of_the_year is Month -> R.string.month_of_the_year
is Day -> R.string.day_of_the_week is Day -> R.string.day_of_the_week
is PastDays -> R.string.period_in_days is PastDays -> R.string.period_in_days
is Blind -> TODO() is Blind -> R.string.blinds
is ResultMoreThan -> TODO() is ResultMoreThan -> R.string.more_than
is ResultLessThan -> TODO() is ResultLessThan -> R.string.less_than
else -> null else -> null
} }
} }
override val viewType: Int
get() {
return when (this) {
is ResultMoreThan -> RowViewType.TITLE_VALUE_CHECK.ordinal
else -> RowViewType.TITLE_CHECK.ordinal
}
}
override fun getDisplayName(): String { override fun getDisplayName(): String {
return when (this) { return when (this) {
is DataFilterElementRow -> this.name is DataFilterElementRow -> this.name
is StaticDataFilterElementRow -> this.getDataDisplayName() is StaticDataFilterElementRow -> this.name
else -> super.getDisplayName() else -> super.getDisplayName()
} }
} }
@ -160,8 +167,6 @@ sealed class FilterElementRow : RowRepresentable {
} }
} }
override val viewType: Int = RowViewType.TITLE_CHECK.ordinal
val sectionToExclude: List<FilterSectionRow>? val sectionToExclude: List<FilterSectionRow>?
get() { get() {
val excluded = arrayListOf<FilterSectionRow>() val excluded = arrayListOf<FilterSectionRow>()

@ -8,6 +8,7 @@ import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.* import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.*
import java.util.*
enum class FilterSectionRow(override val resId: Int?) : RowRepresentable { enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
CASH_TOURNAMENT(net.pokeranalytics.android.R.string.cash_or_tournament), CASH_TOURNAMENT(net.pokeranalytics.android.R.string.cash_or_tournament),
@ -125,9 +126,8 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
MULTI_PLAYER -> arrayListOf() MULTI_PLAYER -> arrayListOf()
RANGE -> arrayListOf() SESSION_DURATION -> arrayListOf(ResultMoreThan(0.0), ResultLessThan(0.0))
RANGE -> arrayListOf(From(Date()), To(Date()))
SESSION_DURATION -> arrayListOf()
VALUE -> arrayListOf() VALUE -> arrayListOf()
@ -164,104 +164,3 @@ enum class FilterSectionRow(override val resId: Int?) : RowRepresentable {
} }
} }
} }
/*
/**
* Return the type of the selection
*/
fun getType(): Type {
return when (this) {
GAME, LIMIT_TYPE -> Type.MULTIPLE
FIXED_DATE, YEAR, WEEKDAYS_OR_WEEKEND, DAY_OF_WEEK, MONTH_OF_YEAR -> Type.MULTIPLE
else -> Type.SINGLE
}
}
/**
* Returns the filter rows
*/
fun getFilterRows(realm: Realm): ArrayList<RowRepresentable> {
val rows = ArrayList<RowRepresentable>()
when (this) {
// General
CASH_TOURNAMENT -> rows.addAll(arrayListOf(FilterRow.CASH_GAME, FilterRow.TOURNAMENT))
LIVE_ONLINE -> rows.addAll(arrayListOf(FilterRow.LIVE, FilterRow.ONLINE))
GAME -> {
val games = realm.copyFromRealm(LiveData.GAME.items(realm) as RealmResults<Game>)
rows.addAll(games)
}
LIMIT_TYPE -> rows.addAll(Limit.numericValues())
TABLE_SIZE -> {
val sessions = realm.where<Session>().sort("tableSize").distinct("tableSize").findAll()
for (session in sessions) {
session.tableSize?.let {
rows.add(TableSize(it, RowViewType.TITLE_CHECK.ordinal))
}
}
}
// Date
DYNAMIC_DATE -> rows.addAll(
arrayListOf(
FilterRow.TODAY, FilterRow.YESTERDAY, FilterRow.TODAY_AND_YESTERDAY, FilterRow.CURRENT_WEEK,
FilterRow.CURRENT_MONTH, FilterRow.CURRENT_YEAR
)
)
FIXED_DATE -> {
rows.addAll(arrayListOf(FilterRow.FROM, FilterRow.TO))
}
DURATION -> rows.addAll(arrayListOf(FilterRow.PAST_DAYS))
YEAR -> {
//TODO: Maybe move this code
val calendar = Calendar.getInstance()
val sessions = realm.where<Session>().sort("endDate", Sort.DESCENDING).findAll()
val years = ArrayList<Int>()
for (session in sessions) {
session.endDate?.let {
calendar.time = it
val year = calendar.get(Calendar.YEAR)
if (!years.contains(year)) {
years.add(year)
}
}
}
for (year in years) {
rows.add(CustomizableRowRepresentable(customViewType = RowViewType.TITLE_CHECK, title = year.toString(), isSelectable = true))
}
}
WEEKDAYS_OR_WEEKEND -> rows.addAll(arrayListOf(FilterRow.WEEKDAYS, FilterRow.WEEKEND))
DAY_OF_WEEK -> {
val dfs = DateFormatSymbols.getInstance(Locale.getDefault())
for (day in dfs.weekdays) {
if (day.isNotEmpty()) {
rows.add(CustomizableRowRepresentable(customViewType = RowViewType.TITLE_CHECK, title = day, isSelectable = true))
}
}
}
MONTH_OF_YEAR -> {
val dfs = DateFormatSymbols.getInstance(Locale.getDefault())
for (month in dfs.months) {
if (month.isNotEmpty()) {
rows.add(CustomizableRowRepresentable(customViewType = RowViewType.TITLE_CHECK, title = month, isSelectable = true))
}
}
}
else -> rows.addAll(arrayListOf())
}
return rows
}
}
*/

@ -96,3 +96,25 @@ fun Date.getFormattedDuration(toDate: Date) : String {
return "$hoursStr:$minutesStr" return "$hoursStr:$minutesStr"
} }
// Return the date of the beginning of the current date
fun Date.startOfDay() : Date {
val calendar = Calendar.getInstance()
calendar.time = this
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
calendar.set(Calendar.MILLISECOND, 0)
return calendar.time
}
// Return the date of the end of the current date
fun Date.endOfDay() : Date {
val calendar = Calendar.getInstance()
calendar.time = this
calendar.set(Calendar.HOUR_OF_DAY, 23)
calendar.set(Calendar.MINUTE, 59)
calendar.set(Calendar.SECOND, 59)
calendar.set(Calendar.MILLISECOND, 999)
return calendar.time
}
Loading…
Cancel
Save