From 6933b3ef06a05ffaee32d39afc47b2505b18f522 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 18 Apr 2023 15:43:43 +0200 Subject: [PATCH] Shows hands of player --- .../android/model/realm/Player.kt | 6 +++ .../ui/modules/data/PlayerDataFragment.kt | 20 ++++++--- .../ui/modules/data/PlayerDataViewModel.kt | 29 ++++++++++--- .../android/ui/view/PlayerImageView.kt | 2 +- .../android/ui/view/RowViewType.kt | 27 ++++++++++++ .../ui/view/rows/PlayerPropertiesRow.kt | 29 +++---------- app/src/main/res/layout/row_tab.xml | 43 +++++++++++++++++++ 7 files changed, 121 insertions(+), 35 deletions(-) create mode 100644 app/src/main/res/layout/row_tab.xml diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/Player.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/Player.kt index b4176788..8398a903 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/Player.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/Player.kt @@ -4,10 +4,12 @@ import android.content.Context import io.realm.Realm import io.realm.RealmList import io.realm.RealmObject +import io.realm.RealmResults import io.realm.annotations.Ignore import io.realm.annotations.PrimaryKey import net.pokeranalytics.android.R import net.pokeranalytics.android.model.interfaces.* +import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowUpdatable import net.pokeranalytics.android.ui.view.RowViewType @@ -92,4 +94,8 @@ open class Player : RealmObject(), NameManageable, Savable, Deletable, RowRepres } } + fun hands(realm: Realm): RealmResults { + return realm.where(HandHistory::class.java).equalTo("playerSetups.player.id", this.id).findAll() + } + } \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/data/PlayerDataFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/data/PlayerDataFragment.kt index 69c66230..cab56f4b 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/data/PlayerDataFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/data/PlayerDataFragment.kt @@ -18,11 +18,13 @@ import net.pokeranalytics.android.R import net.pokeranalytics.android.databinding.FragmentPlayerBinding import net.pokeranalytics.android.model.realm.Comment import net.pokeranalytics.android.model.realm.Player +import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.ui.activity.ColorPickerActivity import net.pokeranalytics.android.ui.activity.components.MediaActivity import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource import net.pokeranalytics.android.ui.extensions.showAlertDialog +import net.pokeranalytics.android.ui.modules.handhistory.HandHistoryActivity import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor import net.pokeranalytics.android.ui.view.RowViewType @@ -137,8 +139,8 @@ class PlayerDataFragment : EditableDataFragment(), StaticRowRepresentableDataSou tag: Int ): CharSequence { return when (row) { - PlayerPropertiesRow.NAME -> if (player.name.isNotEmpty()) player.name else NULL_TEXT - PlayerPropertiesRow.SUMMARY -> if (player.summary.isNotEmpty()) player.summary else NULL_TEXT + PlayerPropertiesRow.NAME -> player.name.ifEmpty { NULL_TEXT } + PlayerPropertiesRow.SUMMARY -> player.summary.ifEmpty { NULL_TEXT } else -> super.charSequenceForRow(row, context, 0) } } @@ -150,6 +152,9 @@ class PlayerDataFragment : EditableDataFragment(), StaticRowRepresentableDataSou val data = arrayListOf(RowRepresentableEditDescriptor(row.content)) showBottomSheet(row, this, data, isClearable = false, isDeletable = true) } + is HandHistory -> { + HandHistoryActivity.newInstance(this, row.id) + } else -> super.onRowSelected(position, row, tag) } } @@ -163,9 +168,14 @@ class PlayerDataFragment : EditableDataFragment(), StaticRowRepresentableDataSou } else -> { super.onRowValueChanged(value, row) - if (row == PlayerPropertiesRow.NAME) { - rowRepresentableAdapter.refreshRow(PlayerPropertiesRow.IMAGE) - + when (row) { + PlayerPropertiesRow.NAME -> { + rowRepresentableAdapter.refreshRow(PlayerPropertiesRow.IMAGE) + } + PlayerPropertiesRow.TAB_SELECTOR -> { + this.playerModel.selectedTab = value as Int + rowRepresentableAdapter.notifyDataSetChanged() + } } } } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/data/PlayerDataViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/data/PlayerDataViewModel.kt index a151b100..00dc11aa 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/data/PlayerDataViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/data/PlayerDataViewModel.kt @@ -3,7 +3,6 @@ package net.pokeranalytics.android.ui.modules.data import android.content.Context import io.realm.Realm import io.realm.kotlin.where -import net.pokeranalytics.android.R import net.pokeranalytics.android.model.realm.Comment import net.pokeranalytics.android.model.realm.Player import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource @@ -25,6 +24,12 @@ class PlayerDataViewModel : DataManagerViewModel(), StaticRowRepresentableDataSo private var commentsToDelete: ArrayList = ArrayList() + var selectedTab: Int = 0 + set(value) { + field = value + this.updateRowRepresentation() + } + private val player: Player get() { return this.item as Player @@ -58,9 +63,25 @@ class PlayerDataViewModel : DataManagerViewModel(), StaticRowRepresentableDataSo rows.add(PlayerPropertiesRow.NAME) rows.add(PlayerPropertiesRow.SUMMARY) + val realm = Realm.getDefaultInstance() + val hands = this.player.hands(realm) + realm.close() + + if (this.player.comments.isNotEmpty() || hands.isNotEmpty()) { + rows.add(PlayerPropertiesRow.TAB_SELECTOR) + } + + when(this.selectedTab) { + 0 -> this.addCommentSection(rows) + 1 -> rows.addAll(hands) + } + + return rows + } + + private fun addCommentSection(rows: ArrayList) { + if (this.player.comments.size > 0) { - // Adds Comments section - rows.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, R.string.comments)) val currentCommentCalendar = Calendar.getInstance() val currentDateCalendar = Calendar.getInstance() @@ -81,11 +102,9 @@ class PlayerDataViewModel : DataManagerViewModel(), StaticRowRepresentableDataSo // Adds comment rows.add(comment) } - rows.add(SeparatorRow()) } - return rows } /** diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/PlayerImageView.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/PlayerImageView.kt index 15a03abf..927767df 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/PlayerImageView.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/PlayerImageView.kt @@ -109,7 +109,7 @@ class PlayerImageView : FrameLayout { player.color != null -> player.color as Int player.hasPicture() -> Color.TRANSPARENT isHero -> getColor(context, R.color.kaki_lighter) - else -> getColor(context, R.color.kaki) + else -> getColor(context, R.color.kaki_medium) } // Stroke & initial 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 79c68c16..379d4567 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 @@ -17,6 +17,7 @@ import com.github.mikephil.charting.charts.LineChart import com.github.mikephil.charting.data.* import com.google.android.material.chip.Chip import com.google.android.material.chip.ChipGroup +import com.google.android.material.tabs.TabLayout import kotlinx.android.synthetic.main.cell_calendar_time_unit.view.* import net.pokeranalytics.android.R import net.pokeranalytics.android.calculus.ComputedStat @@ -96,6 +97,7 @@ enum class RowViewType(private var layoutRes: Int) : ViewIdentifier { HAND_HISTORY(R.layout.row_hand_history_view), CALENDAR_GRID_CELL(R.layout.cell_calendar_grid), CALENDAR_TIME_UNIT_CELL(R.layout.cell_calendar_time_unit), + ROW_TAB(R.layout.row_tab), // ROW_HAND_ACTION(R.layout.row_hand_action), // ROW_HAND_STREET(R.layout.row_hand_cards), @@ -162,6 +164,8 @@ enum class RowViewType(private var layoutRes: Int) : ViewIdentifier { CALENDAR_GRID_CELL -> CalendarGridCellHolder(layout) CALENDAR_TIME_UNIT_CELL -> CalendarTimeUnitCellHolder(layout) + ROW_TAB -> RowTabViewHolder(layout) + // Separator SEPARATOR -> SeparatorViewHolder(layout) @@ -442,6 +446,29 @@ enum class RowViewType(private var layoutRes: Int) : ViewIdentifier { } } + + /** + * Display a button in a row + */ + inner class RowTabViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), + BindableHolder { + override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { + val tabLayout = itemView.findViewById(R.id.tabs) + + val listener = object: TabLayout.OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab?) { + adapter.delegate?.onRowValueChanged(tabLayout.selectedTabPosition, row) + } + override fun onTabUnselected(tab: TabLayout.Tab?) { + } + override fun onTabReselected(tab: TabLayout.Tab?) { + } + } + tabLayout.addOnTabSelectedListener(listener) + } + } + + /** * Display a session view */ diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rows/PlayerPropertiesRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rows/PlayerPropertiesRow.kt index fd9a0f85..c7ce1b2c 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/rows/PlayerPropertiesRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rows/PlayerPropertiesRow.kt @@ -12,12 +12,13 @@ import net.pokeranalytics.android.ui.view.RowViewType enum class PlayerPropertiesRow : RowRepresentable { IMAGE, NAME, - SUMMARY; + SUMMARY, + TAB_SELECTOR; override val resId: Int? get() { return when (this) { - IMAGE -> null + IMAGE, TAB_SELECTOR -> null NAME -> R.string.name SUMMARY -> R.string.summary } @@ -29,13 +30,14 @@ enum class PlayerPropertiesRow : RowRepresentable { IMAGE -> RowViewType.ROW_PLAYER_IMAGE.ordinal NAME -> RowViewType.TITLE_SUBTITLE.ordinal SUMMARY -> RowViewType.TITLE_SUBTITLE.ordinal + TAB_SELECTOR -> RowViewType.ROW_TAB.ordinal } } override val bottomSheetType: BottomSheetType get() { return when (this) { - IMAGE -> BottomSheetType.NONE + IMAGE, TAB_SELECTOR -> BottomSheetType.NONE NAME -> BottomSheetType.EDIT_TEXT SUMMARY -> BottomSheetType.EDIT_TEXT_MULTI_LINES } @@ -45,25 +47,4 @@ enum class PlayerPropertiesRow : RowRepresentable { return null } - - // override fun editingDescriptors(map: Map): ArrayList? { -// -// -// } - -// override fun startEditing(dataSource: Any?, parent: Fragment?) { -// if (dataSource == null) return -// if (dataSource !is Player) return -// if (parent == null) return -// if (parent !is RowRepresentableDelegate) return -// val data = RowEditableDataSource() -// when (this) { -// NAME -> data.append(dataSource.name) -// SUMMARY -> data.append(dataSource.summary) -// else -> PokerAnalyticsException.InputFragmentException -// } -// -// InputFragment.buildAndShow(this, parent, data) -// } - } \ No newline at end of file diff --git a/app/src/main/res/layout/row_tab.xml b/app/src/main/res/layout/row_tab.xml new file mode 100644 index 00000000..5e0a8eef --- /dev/null +++ b/app/src/main/res/layout/row_tab.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + +