Start of edit/save + blind setting from the actions

hh
Laurent 6 years ago
parent 82ce3c76b3
commit d4dd65a09d
  1. 40
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  2. 15
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  3. 9
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  4. 29
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  5. 3
      app/src/main/java/net/pokeranalytics/android/ui/view/RowRepresentable.kt
  6. 10
      app/src/main/res/menu/toolbar_hand_history.xml

@ -1,9 +1,7 @@
package net.pokeranalytics.android.ui.modules.handhistory package net.pokeranalytics.android.ui.modules.handhistory
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.*
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders import androidx.lifecycle.ViewModelProviders
import kotlinx.android.synthetic.main.fragment_hand_history.* import kotlinx.android.synthetic.main.fragment_hand_history.*
@ -39,6 +37,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
*/ */
private lateinit var handHistoryAdapter: HandHistoryAdapter private lateinit var handHistoryAdapter: HandHistoryAdapter
/***
* The fragment's menu
*/
private var menu: Menu? = null
companion object { companion object {
fun newInstance(id: String? = null): HandHistoryFragment { fun newInstance(id: String? = null): HandHistoryFragment {
@ -153,6 +156,28 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.keyboard.setCardCentralizer(this.model) this.keyboard.setCardCentralizer(this.model)
} }
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
menu?.clear()
inflater?.inflate(R.menu.toolbar_hand_history, menu)
updateMenuUI()
super.onCreateOptionsMenu(menu, inflater)
}
/**
* Update menu UI
*/
private fun updateMenuUI() {
val titleResId = if (this.model.isEdited) R.string.save else R.string.edit
this.menu?.findItem(R.id.edit_save)?.setTitle(titleResId)
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item!!.itemId) {
R.id.edit_save -> saveOrEdit()
}
return true
}
private fun retrieveEditTextInputConnection(selection: HHSelection) { private fun retrieveEditTextInputConnection(selection: HHSelection) {
val handRow = this.model.rowRepresentableForPosition(selection.index) as? HandRowType val handRow = this.model.rowRepresentableForPosition(selection.index) as? HandRowType
@ -167,6 +192,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
} }
private fun saveOrEdit() {
this.model.isEdited = !this.model.isEdited
if (this.model.isEdited) {
this.findNextActionToEdit(0)
}
this.handHistoryAdapter.notifyDataSetChanged()
}
private fun edit() { private fun edit() {
this.model.isEdited = true this.model.isEdited = true
this.findNextActionToEdit(0) this.findNextActionToEdit(0)

@ -15,6 +15,7 @@ interface ActionManager {
fun getPlayerNextStreetActions(index: Int): List<ComputedAction> fun getPlayerNextStreetActions(index: Int): List<ComputedAction>
fun dropNextActions(index: Int) fun dropNextActions(index: Int)
fun allinAmountSet(positionIndex: Int) fun allinAmountSet(positionIndex: Int)
fun blindSet(type: Action.Type, amount: Double)
} }
interface ActionListListener : PlayerSetupCreationListener { interface ActionListListener : PlayerSetupCreationListener {
@ -456,6 +457,20 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
} }
} }
/***
* Sets the blinds value in the hand history
*/
override fun blindSet(type: Action.Type, amount: Double) {
when (type) {
Action.Type.POST_SB -> this.handHistory.smallBlind = amount
Action.Type.POST_BB -> this.handHistory.bigBlind = amount
else -> throw PAIllegalStateException("Should never happen")
}
}
/***
* Returns whether the player at [position] is all-in and its amount is set
*/
fun isPlayerAllinWithAmount(position: Int): Boolean { fun isPlayerAllinWithAmount(position: Int): Boolean {
val computedAction = this.lastOrNull { it.action.position == position && it.action.type?.isAllin == true } val computedAction = this.lastOrNull { it.action.position == position && it.action.type?.isAllin == true }
return computedAction?.action?.amount != null return computedAction?.action?.amount != null

@ -122,8 +122,13 @@ class ComputedAction(var manager: ActionManager,
else -> {} else -> {}
} }
if (this.action.type?.isAllin == true) { when {
this.manager.allinAmountSet(this.action.position) this.action.type?.isAllin == true -> {
this.manager.allinAmountSet(this.action.position)
}
this.action.type?.isBlind == true -> {
this.manager.blindSet(this.action.type!!, amount)
}
} }
} }

@ -53,6 +53,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
* Indicates whether the hand history is being edited or not * Indicates whether the hand history is being edited or not
*/ */
var isEdited = true var isEdited = true
set(value) {
field = value
createRowRepresentation()
}
/*** /***
* The user selection's live data inside the editor * The user selection's live data inside the editor
@ -167,6 +171,25 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
* Uses the action list to create the list of RowRepresentables, displayed to the user * Uses the action list to create the list of RowRepresentables, displayed to the user
*/ */
private fun createRowRepresentation() { private fun createRowRepresentation() {
this.rowsLiveData.value = if (this.isEdited) {
editionRowRepresentation()
} else {
readRowRepresentation()
}
}
private fun readRowRepresentation(): MutableList<RowRepresentable> {
val rows: MutableList<RowRepresentable> = mutableListOf()
// TODO remove useless settings, collapse multifolds
return rows
}
private fun editionRowRepresentation(): MutableList<RowRepresentable> {
val rows: MutableList<RowRepresentable> = mutableListOf() val rows: MutableList<RowRepresentable> = mutableListOf()
rows.add(HandRowType.COMMENT) rows.add(HandRowType.COMMENT)
@ -200,8 +223,8 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
if (this.sortedActions.activePositions(lastActionIndex).size < 2 || this.sortedActions.isStreetActionClosed(lastActionIndex) == Street.SUMMARY) { if (this.sortedActions.activePositions(lastActionIndex).size < 2 || this.sortedActions.isStreetActionClosed(lastActionIndex) == Street.SUMMARY) {
addStreetHeader(rows, street) addStreetHeader(rows, street)
val positions = this.sortedActions.activePositions(lastActionIndex, true) val activePositions = this.sortedActions.activePositions(lastActionIndex, true)
positions.forEach { position -> activePositions.forEach { position ->
val positionIndex = this.sortedActions.positions.indexOf(position) val positionIndex = this.sortedActions.positions.indexOf(position)
val playerCardsRow = PlayerCardsRow(this, val playerCardsRow = PlayerCardsRow(this,
position, position,
@ -221,7 +244,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
} }
} }
this.rowsLiveData.value = rows return rows
} }
/*** /***

@ -1,7 +1,6 @@
package net.pokeranalytics.android.ui.view package net.pokeranalytics.android.ui.view
import android.content.Context import android.content.Context
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.LiveData import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.util.NULL_TEXT import net.pokeranalytics.android.util.NULL_TEXT
@ -58,7 +57,7 @@ interface Displayable : Localizable {
*/ */
val viewType: Int val viewType: Int
get() { get() {
throw PAIllegalStateException("The Displayable instance $this must return a valid viewType") return -1
} }
val relatedResultsRepresentable: LiveData? val relatedResultsRepresentable: LiveData?

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/edit_save"
android:title="@string/save"
app:showAsAction="ifRoom" />
</menu>
Loading…
Cancel
Save