diff --git a/app/src/androidTest/assets/schema_2.realm b/app/src/androidTest/assets/schema_2.realm new file mode 100644 index 00000000..4b7c34b6 Binary files /dev/null and b/app/src/androidTest/assets/schema_2.realm differ diff --git a/app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt b/app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt index 8dd1c786..0ad656f7 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/filter/QueryCondition.kt @@ -6,7 +6,11 @@ import net.pokeranalytics.android.exceptions.PokerAnalyticsException import net.pokeranalytics.android.model.realm.FilterCondition import net.pokeranalytics.android.model.realm.FilterElementBlind import net.pokeranalytics.android.model.realm.Session +import java.time.* import java.util.* +import java.time.temporal.TemporalQueries.zoneId + + /** @@ -58,6 +62,12 @@ enum class QueryCondition(var operator: Operator? = null) { YEAR, WEEK_DAY, WEEK_END, + TODAY, + YESTERDAY, + TODAY_AND_YESTERDAY, + THIS_WEEK, + THIS_MONTH, + THIS_YEAR, CURRENCY, CURRENCY_CODE, @@ -232,6 +242,9 @@ enum class QueryCondition(var operator: Operator? = null) { } query.`in`(fieldName, arrayOf(Calendar.SATURDAY, Calendar.SUNDAY)) } + TODAY, YESTERDAY, TODAY_AND_YESTERDAY, THIS_WEEK, THIS_MONTH, THIS_YEAR -> { + realmQuery + } else -> { throw PokerAnalyticsException.QueryTypeUnhandled } diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt index f6613ad5..9ccaa0a0 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt @@ -19,25 +19,25 @@ import java.util.* */ open class Filter : RealmObject() { - private var entityType : Int? = Entity.SESSION.ordinal + private var entityType: Int? = Entity.SESSION.ordinal - private enum class Entity { - SESSION, - ; - } + private enum class Entity { + SESSION, + ; + } - companion object { + companion object { - // Create a new instance - fun newInstance(realm: Realm) : Filter { + // Create a new instance + fun newInstance(realm: Realm): Filter { val filter = Filter() - return realm.copyToRealm(filter) - } + return realm.copyToRealm(filter) + } - // Get a filter by its id - fun getFilterBydId(realm: Realm, filterId: String) : Filter? { - return realm.where().equalTo("id", filterId).findFirst() - } + // Get a filter by its id + fun getFilterBydId(realm: Realm, filterId: String): Filter? { + return realm.where().equalTo("id", filterId).findFirst() + } @TestOnly inline fun queryOn(realm: Realm, queries: List): RealmResults { @@ -49,15 +49,15 @@ open class Filter : RealmObject() { } } - @PrimaryKey - var id = UUID.randomUUID().toString() + @PrimaryKey + var id = UUID.randomUUID().toString() - // the filter name - var name: String = "" + // the filter name + var name: String = "" - // the number of use of the filter, - // for MutableRealmInteger, see https://realm.io/docs/java/latest/#counters - val usageCount: MutableRealmInteger = MutableRealmInteger.valueOf(0) + // the number of use of the filter, + // for MutableRealmInteger, see https://realm.io/docs/java/latest/#counters + val usageCount: MutableRealmInteger = MutableRealmInteger.valueOf(0) var filterConditions: RealmList = RealmList() private set @@ -84,9 +84,9 @@ open class Filter : RealmObject() { filterConditions.add(FilterCondition(casted)) } - } - } - } + } + } + } fun countBy(filterCategoryRow: FilterCategoryRow) : Int { val sections = filterCategoryRow.filterSectionRows @@ -113,7 +113,7 @@ open class Filter : RealmObject() { realmQuery = it.filter(realmQuery) } - return realmQuery.findAll() - } + return realmQuery.findAll() + } } diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/FilterCondition.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/FilterCondition.kt index ec4a7745..be7aa78c 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/FilterCondition.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/FilterCondition.kt @@ -18,16 +18,24 @@ open class FilterCondition() : RealmObject() { constructor(filterElementRows: ArrayList) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) { val filterName : String = this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName this.stringValues = when (QueryCondition.valueOf(filterName)) { - QueryCondition.GAME, QueryCondition.BANKROLL, QueryCondition.TOURNAMENT_NAME, QueryCondition.ALL_TOURNAMENT_FEATURES, QueryCondition.ANY_TOURNAMENT_FEATURES, QueryCondition.LOCATION -> { - RealmList().apply { - this.addAll(filterElementRows.map { - (it as DataFilterElementRow).id - }) - } - } - else -> null + QueryCondition.GAME, QueryCondition.BANKROLL, QueryCondition.TOURNAMENT_NAME, QueryCondition.ALL_TOURNAMENT_FEATURES, QueryCondition.ANY_TOURNAMENT_FEATURES, QueryCondition.LOCATION -> { + RealmList().apply { + this.addAll(filterElementRows.map { + (it as DataFilterElementRow).id + }) + } + } + QueryCondition.LIMIT, QueryCondition.TABLE_SIZE -> { + RealmList().apply { + this.addAll(filterElementRows.map { + (it as StaticDataFilterElementRow).id + }) + } + } + else -> null } + this.numericValues = when (QueryCondition.valueOf(filterName)) { QueryCondition.LIMIT -> { RealmList().apply { @@ -79,15 +87,15 @@ open class FilterCondition() : RealmObject() { } } - constructor(filterElementRow:FilterElementRow) : this(arrayListOf(filterElementRow)) { - when (filterElementRow) { - is From -> dateValue = filterElementRow.date - is To -> dateValue= filterElementRow.date - } - } + constructor(filterElementRow: FilterElementRow) : this(arrayListOf(filterElementRow)) { + when (filterElementRow) { + is From -> dateValue = filterElementRow.date + is To -> dateValue = filterElementRow.date + } + } - var filterName : String? = null - var sectionName : String? = null + var filterName: String? = null + var sectionName: String? = null val queryCondition : QueryCondition get() = QueryCondition.valueOf(this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName) @@ -95,58 +103,58 @@ open class FilterCondition() : RealmObject() { this.updateValueMap(this@FilterCondition) } - private var numericValues: RealmList? = null - private var dateValue : Date? = null - private var stringValues : RealmList? = null - private var blindValues : RealmList? = null - - val ids : Array - get() = stringValues?.toTypedArray()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing - - val blinds : RealmList - get() { - blindValues?.let { - if (it.isNotEmpty()) { - return it - } else { - throw PokerAnalyticsException.FilterElementExpectedValueMissing - } - } - throw PokerAnalyticsException.FilterElementExpectedValueMissing - } + private var numericValues: RealmList? = null + private var dateValue: Date? = null + private var stringValues: RealmList? = null + private var blindValues: RealmList? = null + + val ids: Array + get() = stringValues?.toTypedArray() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing + + val blinds: RealmList + get() { + blindValues?.let { + if (it.isNotEmpty()) { + return it + } else { + throw PokerAnalyticsException.FilterElementExpectedValueMissing + } + } + throw PokerAnalyticsException.FilterElementExpectedValueMissing + } - val date : Date - get() = dateValue?: throw PokerAnalyticsException.FilterElementExpectedValueMissing + val date: Date + get() = dateValue ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing - val values : Array - get() = numericValues?.map { - it.toInt() - }?.toTypedArray()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing + val values: Array + get() = numericValues?.map { + it.toInt() + }?.toTypedArray() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing - val value : Double - get() = numericValues?.first()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing + val value: Double + get() = numericValues?.first() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing - val leftValue : Double - get() = numericValues?.first()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing + val leftValue: Double + get() = numericValues?.first() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing - val rightValue : Double - get() = numericValues?.last()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing + val rightValue: Double + get() = numericValues?.last() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing - val dayOfWeek : Int - get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing + val dayOfWeek: Int + get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing - val month : Int - get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing + val month: Int + get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing - val year : Int - get() = numericValues?.first()?.toInt()?: throw PokerAnalyticsException.FilterElementExpectedValueMissing + val year: Int + get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt index ad55f88b..84476e86 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt @@ -18,6 +18,7 @@ import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource 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.RowViewType 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) { super.onRowSelected(position, row, fromAction) - val oldRows = ArrayList() - oldRows.addAll(rows) - if (selectedRows.contains(row)) { - 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) + Timber.d("Row: $row") + + when (row) { + is FilterElementRow.ResultMoreThan -> { + val data = row.editingDescriptors(mapOf("defaultValue" to "")) + BottomSheetFragment.create(fragmentManager, row, this, data, null) + } + else -> { + + val oldRows = ArrayList() + oldRows.addAll(rows) + if (selectedRows.contains(row)) { + 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") when (row) { @@ -103,6 +117,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta override fun onRowValueChanged(value: Any?, row: RowRepresentable) { super.onRowValueChanged(value, row) + Timber.d("onRowValueChanged: $row $value") selectedRows.add(row as FilterElementRow) rowRepresentableAdapter.refreshRow(row) } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt index 4671f50b..c887ff71 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt @@ -76,9 +76,7 @@ enum class RowViewType(private var layoutRes: Int) { HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG, LOCATION_TITLE, INFO, TITLE, TITLE_ARROW, TITLE_VALUE, TITLE_VALUE_ARROW, TITLE_GRID, TITLE_SWITCH, TITLE_CHECK, TITLE_VALUE_CHECK, - DATA, BOTTOM_SHEET_DATA, LOADER -> RowViewHolder( - layout - ) + DATA, BOTTOM_SHEET_DATA, LOADER -> RowViewHolder(layout) // Row Session ROW_SESSION -> RowSessionViewHolder(layout) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt index 6dce883c..6cef6a31 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterCategoryRow.kt @@ -45,6 +45,10 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In DAY_OF_WEEK, MONTH_OF_YEAR ) + TIME_FRAME -> arrayListOf( + SESSION_DURATION, + RANGE + ) BANKROLLS -> arrayListOf( BANKROLL ) @@ -74,7 +78,6 @@ enum class FilterCategoryRow(override val resId: Int?, override val viewType: In VALUE ) - TIME_FRAME -> arrayListOf() SESSION -> arrayListOf() TRANSACTION_TYPES -> arrayListOf() } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt index 2a69bd62..f183236b 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterElementRow.kt @@ -30,13 +30,10 @@ sealed class FilterElementRow : RowRepresentable { 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 - - fun getDataDisplayName() : String { - return row.getDisplayName() - } + val name: String = row.getDisplayName() fun getDataLocalizedTitle(context: Context): String { return row.localizedTitle(context) @@ -52,8 +49,8 @@ sealed class FilterElementRow : RowRepresentable { data class Month(val month: Int) : SingleValueFilterElementRow(month) data class Day(val day: Int) : SingleValueFilterElementRow(day) data class PastDays(var lastDays: Int = 0) : FilterElementRow() - data class Limit(val limit: net.pokeranalytics.android.model.Limit) : StaticDataFilterElementRow(limit) - data class TableSize(val tableSize: net.pokeranalytics.android.model.TableSize) : StaticDataFilterElementRow(tableSize) + 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, tableSize.numberOfPlayer.toString()) data class Bankroll(val bankroll: Manageable) : DataFilterElementRow(bankroll) data class Game(val game: Manageable) : DataFilterElementRow(game) data class Location(val location: Manageable) : DataFilterElementRow(location) @@ -82,16 +79,15 @@ sealed class FilterElementRow : RowRepresentable { is Online -> QueryCondition.ONLINE is Weekday -> QueryCondition.WEEK_DAY is Weekend -> QueryCondition.WEEK_END - - /* - is Today -> QueryCondition. - is Yesterday -> R.string.yesterday - is TodayAndYesterday -> R.string.yesterday_and_today - is CurrentWeek -> R.string.current_week - is CurrentMonth -> R.string.current_month - is CurrentYear -> R.string.current_year - is PastDays -> R.string.period_in_days - */ + is Today -> QueryCondition.TODAY + is Yesterday -> QueryCondition.YESTERDAY + is TodayAndYesterday -> QueryCondition.TODAY_AND_YESTERDAY + is CurrentWeek -> QueryCondition.THIS_WEEK + is CurrentMonth -> QueryCondition.THIS_MONTH + is CurrentYear -> QueryCondition.THIS_YEAR + /* + is PastDays -> R.string.period_in_days + */ is Limit -> QueryCondition.LIMIT is TableSize -> QueryCondition.TABLE_SIZE @@ -112,7 +108,10 @@ sealed class FilterElementRow : RowRepresentable { is DataFilterElementRow -> filterConditions.any { 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 Day -> R.string.day_of_the_week is PastDays -> R.string.period_in_days - is Blind -> TODO() - is ResultMoreThan -> TODO() - is ResultLessThan -> TODO() + is Blind -> R.string.blinds + is ResultMoreThan -> R.string.more_than + is ResultLessThan -> R.string.less_than 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 { return when (this) { is DataFilterElementRow -> this.name - is StaticDataFilterElementRow -> this.getDataDisplayName() + is StaticDataFilterElementRow -> this.name else -> super.getDisplayName() } } @@ -160,8 +167,6 @@ sealed class FilterElementRow : RowRepresentable { } } - override val viewType: Int = RowViewType.TITLE_CHECK.ordinal - val sectionToExclude: List? get() { val excluded = arrayListOf() diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt index b812bf4f..19f4ed1d 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSectionRow.kt @@ -8,6 +8,7 @@ import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.* +import java.util.* enum class FilterSectionRow(override val resId: Int?) : RowRepresentable { 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() - RANGE -> arrayListOf() - - SESSION_DURATION -> arrayListOf() + SESSION_DURATION -> arrayListOf(ResultMoreThan(0.0), ResultLessThan(0.0)) + RANGE -> arrayListOf(From(Date()), To(Date())) 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 { - val rows = ArrayList() - 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) - rows.addAll(games) - } - LIMIT_TYPE -> rows.addAll(Limit.numericValues()) - TABLE_SIZE -> { - val sessions = realm.where().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().sort("endDate", Sort.DESCENDING).findAll() - val years = ArrayList() - - 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 - } - -} - - */ \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/util/extensions/DateExtension.kt b/app/src/main/java/net/pokeranalytics/android/util/extensions/DateExtension.kt index 34061212..6a5a6d10 100644 --- a/app/src/main/java/net/pokeranalytics/android/util/extensions/DateExtension.kt +++ b/app/src/main/java/net/pokeranalytics/android/util/extensions/DateExtension.kt @@ -96,3 +96,25 @@ fun Date.getFormattedDuration(toDate: Date) : String { 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 +} \ No newline at end of file