Creates menu options + blinds auto update

hh
Laurent 6 years ago
parent 2aa63f8400
commit 457cb4f95e
  1. 12
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  2. 104
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 16
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  4. 20
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  5. 22
      app/src/main/res/menu/toolbar_hand_history.xml
  6. 1
      app/src/main/res/values/strings.xml

@ -41,11 +41,23 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
* The small blind * The small blind
*/ */
var smallBlind: Double? = null var smallBlind: Double? = null
set(value) {
field = value
if (this.bigBlind == null && value != null) {
this.bigBlind = value * 2
}
}
/*** /***
* The big blind * The big blind
*/ */
var bigBlind: Double? = null var bigBlind: Double? = null
set(value) {
field = value
if (this.smallBlind == null && value != null) {
this.smallBlind = value / 2
}
}
/*** /***
* The ante * The ante

@ -117,32 +117,51 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val row = this.model.rowRepresentableForPosition(it.index) as HandHistoryRow val row = this.model.rowRepresentableForPosition(it.index) as HandHistoryRow
val keyboard = row.keyboardForTag(it.tag) row.keyboardForTag(it.tag)?.let { keyboard ->
when (keyboard) {
HHKeyboard.ACTION -> { when (keyboard) {
configureActionKeyboard() HHKeyboard.ACTION -> {
} configureActionKeyboard()
HHKeyboard.AMOUNT -> { }
retrieveEditTextInputConnection(selection) HHKeyboard.AMOUNT -> {
retrieveEditTextInputConnection(selection)
}
else -> {}
} }
else -> {}
}
keyboard?.let { this.showKeyboard(keyboard) {
// this.animateKeyboard(true)
this.showKeyboard(it) {
this.scrollToPosition(selection.index) this.scrollToPosition(selection.index)
} }
// this.keyboard.show(it)
} ?: run { } ?: run {
this.animateKeyboard(false) this.animateKeyboard(false)
} }
// val keyboard = row.keyboardForTag(it.tag)
// when (keyboard) {
// HHKeyboard.ACTION -> {
// configureActionKeyboard()
// }
// HHKeyboard.AMOUNT -> {
// retrieveEditTextInputConnection(selection)
// }
// else -> {}
// }
//
// keyboard?.let { kb ->
//// this.animateKeyboard(true)
// this.showKeyboard(kb) {
// this.scrollToPosition(selection.index)
// }
//// this.keyboard.show(it)
// } ?: run {
// this.animateKeyboard(false)
// }
} ?: run { } ?: run {
this.animateKeyboard(false) this.animateKeyboard(false)
} }
} }
val observer = Observer<MutableList<RowRepresentable>> { val observer = Observer<MutableList<RowRepresentable>> {
@ -162,7 +181,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
} }
} }
initKeyboard() initKeyboardDefaultHeight()
this.keyboard.keyboardListener = this this.keyboard.keyboardListener = this
this.keyboard.setCardCentralizer(this.model) this.keyboard.setCardCentralizer(this.model)
} }
@ -185,6 +204,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
override fun onOptionsItemSelected(item: MenuItem?): Boolean { override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item!!.itemId) { when (item!!.itemId) {
R.id.edit_save -> saveOrEdit() R.id.edit_save -> saveOrEdit()
R.id.add -> addNewHand()
R.id.delete -> deleteHand()
R.id.back -> showPreviousHand()
R.id.forward -> showNextHand()
} }
return true return true
} }
@ -402,6 +425,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
// this.hideKeyboard() // this.hideKeyboard()
} }
/***
* Method called when a shortcut [position] has been selected
* Jumps the selection to the next action of the [position]
*/
override fun positionSelected(position: Position) { override fun positionSelected(position: Position) {
val rowRepresentableIndex = this.model.nextActionIndexForPosition(position) val rowRepresentableIndex = this.model.nextActionIndexForPosition(position)
this.model.rowRepresentableForPosition(rowRepresentableIndex)?.let { this.model.rowRepresentableForPosition(rowRepresentableIndex)?.let {
@ -438,7 +465,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
} }
} }
/***
* Shows the given [keyboard]
* Notifies the [endHandler] when the keyboard has finished animating
*/
private fun showKeyboard(keyboard: HHKeyboard, endHandler: (() -> (Unit))? = null) { private fun showKeyboard(keyboard: HHKeyboard, endHandler: (() -> (Unit))? = null) {
val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams
@ -448,6 +478,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.keyboard.show(keyboard) this.keyboard.show(keyboard)
} }
/***
* Animates the keyboard
* [show] defines whether the keyboard should be shown or hidden
* Notifies the [endHandler] when the keyboard has finished animating
*/
private fun animateKeyboard(show: Boolean, endHandler: (() -> (Unit))? = null) { private fun animateKeyboard(show: Boolean, endHandler: (() -> (Unit))? = null) {
val height = 310.0f.px val height = 310.0f.px
@ -474,10 +509,43 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
valueAnimator.start() valueAnimator.start()
} }
/***
private fun initKeyboard() { * Starts by hiding the keyboard
*/
private fun initKeyboardDefaultHeight() {
val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams
lp.guideEnd = 0 lp.guideEnd = 0
} }
private fun showNextHand() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
private fun showPreviousHand() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
/***
* Deletes the current hand
* Finishes the activity to go back
*/
private fun deleteHand() {
if (this.model.handHistory.isManaged) {
getRealm().executeTransaction {
this.model.handHistory.deleteFromRealm()
}
}
this.activity?.finish()
}
/***
* Creates a new hand using the current hand setup
*/
private fun addNewHand() {
getRealm().executeTransaction {
this.model.createNewHandHistoryWithCurrentSetup(it)
}
this.findNextActionToEdit(0)
}
} }

@ -561,15 +561,13 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
/*** /***
* Updates the small blind amount * Updates the small blind amount
*/ */
fun updateSmallBlind(amount: Double) { fun updateBlinds() {
this.firstOrNull { it.action.type == Action.Type.POST_SB }?.setAmount(amount) this.handHistory.smallBlind?.let { sb ->
} this.firstOrNull { it.action.type == Action.Type.POST_SB }?.setAmount(sb)
}
/*** this.handHistory.bigBlind?.let { bb ->
* Updates the big blind amount this.firstOrNull { it.action.type == Action.Type.POST_BB }?.setAmount(bb)
*/ }
fun updateBigBlind(amount: Double) {
this.firstOrNull { it.action.type == Action.Type.POST_BB }?.setAmount(amount)
} }
} }

@ -141,8 +141,22 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
*/ */
fun createNewHandHistory(realm: Realm, handSetup: HandSetup) { fun createNewHandHistory(realm: Realm, handSetup: HandSetup) {
this.handSetup = handSetup this.handSetup = handSetup
createHandHistory(realm)
}
/***
* Creates a new hand history using the current HandSetup
*/
fun createNewHandHistoryWithCurrentSetup(realm: Realm) {
createHandHistory(realm)
}
/***
* Creates a hand history using the c
*/
private fun createHandHistory(realm: Realm) {
val handHistory = HandHistory() val handHistory = HandHistory()
handHistory.configure(handSetup) handHistory.configure(this.handSetup)
this.playerHandMaxCards = handSetup.game?.playerHandMaxCards this.playerHandMaxCards = handSetup.game?.playerHandMaxCards
this.loadHandHistory(realm.copyToRealm(handHistory)) this.loadHandHistory(realm.copyToRealm(handHistory))
} }
@ -390,11 +404,11 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
when (this.currentSelection.tag) { when (this.currentSelection.tag) {
0 -> { 0 -> {
this.handHistory.smallBlind = amount this.handHistory.smallBlind = amount
this.sortedActions.updateSmallBlind(amount) this.sortedActions.updateBlinds()
} }
1 -> { 1 -> {
this.handHistory.bigBlind = amount this.handHistory.bigBlind = amount
this.sortedActions.updateBigBlind(amount) this.sortedActions.updateBlinds()
} }
2 -> this.handHistory.ante = amount 2 -> this.handHistory.ante = amount
} }

@ -5,6 +5,28 @@
<item <item
android:id="@+id/edit_save" android:id="@+id/edit_save"
android:title="@string/save" android:title="@string/save"
app:showAsAction="always" />
<item
android:id="@+id/add"
android:title="@string/add_a_hand_history"
android:icon="@drawable/ic_add"
app:showAsAction="ifRoom" />
<item
android:id="@+id/delete"
android:title="@string/delete"
android:icon="@drawable/ic_outline_delete"
app:showAsAction="ifRoom" />
<item
android:id="@+id/back"
android:title="@string/back"
app:showAsAction="ifRoom" />
<item
android:id="@+id/forward"
android:title="@string/forward"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
</menu> </menu>

@ -793,5 +793,6 @@
<string name="backspace"></string> <string name="backspace"></string>
<string name="mississipi">mississipi</string> <string name="mississipi">mississipi</string>
<string name="add_vilain">Add vilain</string> <string name="add_vilain">Add vilain</string>
<string name="forward">Forward</string>
</resources> </resources>

Loading…
Cancel
Save