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 95349e78..87688c66 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 @@ -9,15 +9,16 @@ import kotlinx.android.synthetic.main.fragment_filter_details.view.* import net.pokeranalytics.android.R import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter +import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource 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.view.RowRepresentable +import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow import timber.log.Timber -open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { +open class FilterDetailsFragment : PokerAnalyticsFragment(), RowRepresentableDataSource, RowRepresentableDelegate { lateinit var parentActivity: PokerAnalyticsActivity lateinit var item: RealmObject @@ -59,10 +60,7 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta return true } - override fun adapterRows(): List? { - return rows - } - + /* override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { super.onRowSelected(position, row, fromAction) } @@ -70,6 +68,29 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta override fun onRowValueChanged(value: Any?, row: RowRepresentable) { super.onRowValueChanged(value, row) } + */ + + override fun adapterRows(): List? { + return rows + } + + override fun rowRepresentableForPosition(position: Int): RowRepresentable? { + return rows[position] + } + + override fun numberOfRows(): Int { + return rows.size + } + + override fun viewTypeForPosition(position: Int): Int { + val rowViewType = rowRepresentableForPosition(position)?.viewType ?: -1 + return if (rowViewType != -1) rowViewType else RowViewType.TITLE_CHECK.ordinal + } + + override fun indexForRow(row: RowRepresentable): Int { + return rows.indexOf(row) + } + /** * Init UI @@ -102,40 +123,15 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta this.appBar.toolbar.title = it.localizedTitle(requireContext()) this.rows.clear() - this.rows.addAll(it.getSubcategories()) - Timber.d("initData: ${this.rows.size}") + for (subcategory in it.getSubcategories()) { + this.rows.add(subcategory) + this.rows.addAll(subcategory.getFilterRows(getRealm())) + } this.rowRepresentableAdapter = RowRepresentableAdapter(this, this) this.recyclerView.adapter = rowRepresentableAdapter - } - /* - if (this.dataType != null) { - val proxyItem: RealmObject? = this.liveDataType.getData(this.getRealm(), primaryKey) - proxyItem?.let { - //TODO: Localize - this.appBar.toolbar.title = "Update ${this.liveDataType.localizedTitle(this.parentActivity).toLowerCase().capitalize()}" - isUpdating = true - } ?: run { - //TODO: Localize - this.appBar.toolbar.title = this.liveDataType.newEntityLocalizedTitle(requireContext()) - } - this.item = this.liveDataType.updateOrCreate(this.getRealm(), primaryKey) - - val dataSource = getDataSource() - this.rowRepresentableAdapter = RowRepresentableAdapter(getDataSource(), this) - this.recyclerView.adapter = rowRepresentableAdapter - - // When creating an object, open automatically the keyboard for the first row - if (!isUpdating && shouldOpenKeyboard) { - val row = dataSource.adapterRows()?.firstOrNull() - row?.let { - onRowSelected(0, it) - } - } - } - */ } /** @@ -211,8 +207,6 @@ open class FilterDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresenta */ fun setData(filterCategory: Int) { - Timber.d("Filter Category: ${FilterCategoryRow.values()[filterCategory]}") - Timber.d("Filter Subcategories: ${FilterCategoryRow.values()[filterCategory].getSubcategories()}") this.filterCategory = FilterCategoryRow.values()[filterCategory] /* diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterRow.kt new file mode 100644 index 00000000..67ee210f --- /dev/null +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterRow.kt @@ -0,0 +1,27 @@ +package net.pokeranalytics.android.ui.view.rowrepresentable + +import net.pokeranalytics.android.R +import net.pokeranalytics.android.ui.view.RowRepresentable +import net.pokeranalytics.android.ui.view.RowViewType + +enum class FilterRow : RowRepresentable { + + // General + CASH_GAME, + TOURNAMENT, + LIVE, + ONLINE; + + override val resId: Int? + get() { + return when (this) { + CASH_GAME -> R.string.cash_game + TOURNAMENT -> R.string.tournament + LIVE -> R.string.live + ONLINE -> R.string.online + } + } + + override val viewType: Int = RowViewType.TITLE_CHECK.ordinal + +} \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSubcategoryRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSubcategoryRow.kt index bc4e4aa9..a9a30dbc 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSubcategoryRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/FilterSubcategoryRow.kt @@ -1,6 +1,11 @@ package net.pokeranalytics.android.ui.view.rowrepresentable +import io.realm.Realm +import io.realm.RealmResults import net.pokeranalytics.android.R +import net.pokeranalytics.android.model.Limit +import net.pokeranalytics.android.model.LiveData +import net.pokeranalytics.android.model.realm.Game import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowViewType @@ -60,6 +65,11 @@ enum class FilterSubcategoryRow : RowRepresentable { NUMBER_OF_PLAYERS, MULTI_PLAYER; + enum class Type { + SINGLE, + MULTIPLE, + } + override val resId: Int? get() { return when(this) { @@ -105,8 +115,31 @@ enum class FilterSubcategoryRow : RowRepresentable { override val viewType: Int = RowViewType.CLASSIC_HEADER_TITLE.ordinal - fun getFilterRow() : ArrayList { + /** + * Return the type of the selection + */ + fun getType() : Type { + return when(this) { + GAME -> Type.MULTIPLE + else -> Type.SINGLE + } + } + + /** + * Returns the filter rows + */ + fun getFilterRows(realm: Realm) : ArrayList { val rows = ArrayList() + when(this) { + 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.values()) + else -> rows.addAll(arrayListOf()) + } return rows }