Shows hands of player

realmasync
Laurent 3 years ago
parent 9bf524b1e3
commit 6933b3ef06
  1. 6
      app/src/main/java/net/pokeranalytics/android/model/realm/Player.kt
  2. 20
      app/src/main/java/net/pokeranalytics/android/ui/modules/data/PlayerDataFragment.kt
  3. 29
      app/src/main/java/net/pokeranalytics/android/ui/modules/data/PlayerDataViewModel.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/PlayerImageView.kt
  5. 27
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  6. 29
      app/src/main/java/net/pokeranalytics/android/ui/view/rows/PlayerPropertiesRow.kt
  7. 43
      app/src/main/res/layout/row_tab.xml

@ -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<HandHistory> {
return realm.where(HandHistory::class.java).equalTo("playerSetups.player.id", this.id).findAll()
}
}

@ -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()
}
}
}
}

@ -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<Comment> = 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<RowRepresentable>) {
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
}
/**

@ -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

@ -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<TabLayout>(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
*/

@ -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<String, Any?>): ArrayList<RowRepresentableEditDescriptor>? {
//
//
// }
// 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)
// }
}

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="48dp">
<include layout="@layout/layout_swipe_to_delete" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/foreground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_darker"
android:foreground="?selectableItemBackground">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/kaki_darker"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:tabMode="scrollable">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/comments" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hands_history" />
</com.google.android.material.tabs.TabLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
Loading…
Cancel
Save