From 457cb4f95e06408f24d504c0a71e019e429348ed Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 18 Feb 2020 15:23:30 +0100 Subject: [PATCH] Creates menu options + blinds auto update --- .../model/realm/handhistory/HandHistory.kt | 12 ++ .../handhistory/HandHistoryFragment.kt | 104 +++++++++++++++--- .../modules/handhistory/model/ActionList.kt | 16 ++- .../handhistory/model/HandHistoryViewModel.kt | 20 +++- .../main/res/menu/toolbar_hand_history.xml | 22 ++++ app/src/main/res/values/strings.xml | 1 + 6 files changed, 145 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt index 54270486..af061c05 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt @@ -41,11 +41,23 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab * The small blind */ var smallBlind: Double? = null + set(value) { + field = value + if (this.bigBlind == null && value != null) { + this.bigBlind = value * 2 + } + } /*** * The big blind */ var bigBlind: Double? = null + set(value) { + field = value + if (this.smallBlind == null && value != null) { + this.smallBlind = value / 2 + } + } /*** * The ante diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt index dfa1a347..ce8d0e2c 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt @@ -117,32 +117,51 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL val row = this.model.rowRepresentableForPosition(it.index) as HandHistoryRow - val keyboard = row.keyboardForTag(it.tag) - when (keyboard) { - HHKeyboard.ACTION -> { - configureActionKeyboard() - } - HHKeyboard.AMOUNT -> { - retrieveEditTextInputConnection(selection) + row.keyboardForTag(it.tag)?.let { keyboard -> + + when (keyboard) { + HHKeyboard.ACTION -> { + configureActionKeyboard() + } + HHKeyboard.AMOUNT -> { + retrieveEditTextInputConnection(selection) + } + else -> {} } - else -> {} - } - keyboard?.let { -// this.animateKeyboard(true) - this.showKeyboard(it) { + this.showKeyboard(keyboard) { this.scrollToPosition(selection.index) } -// this.keyboard.show(it) + } ?: run { 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 { this.animateKeyboard(false) } - } val observer = Observer> { @@ -162,7 +181,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL } } - initKeyboard() + initKeyboardDefaultHeight() this.keyboard.keyboardListener = this this.keyboard.setCardCentralizer(this.model) } @@ -185,6 +204,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL override fun onOptionsItemSelected(item: MenuItem?): Boolean { when (item!!.itemId) { R.id.edit_save -> saveOrEdit() + R.id.add -> addNewHand() + R.id.delete -> deleteHand() + R.id.back -> showPreviousHand() + R.id.forward -> showNextHand() } return true } @@ -402,6 +425,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL // 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) { val rowRepresentableIndex = this.model.nextActionIndexForPosition(position) 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) { val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams @@ -448,6 +478,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL 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) { val height = 310.0f.px @@ -474,10 +509,43 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL valueAnimator.start() } - - private fun initKeyboard() { + /*** + * Starts by hiding the keyboard + */ + private fun initKeyboardDefaultHeight() { val lp = this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams 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) + } + } \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt index 44aa951a..ac5092fb 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt @@ -561,15 +561,13 @@ class ActionList(var listener: ActionListListener) : ArrayList() /*** * Updates the small blind amount */ - fun updateSmallBlind(amount: Double) { - this.firstOrNull { it.action.type == Action.Type.POST_SB }?.setAmount(amount) - } - - /*** - * Updates the big blind amount - */ - fun updateBigBlind(amount: Double) { - this.firstOrNull { it.action.type == Action.Type.POST_BB }?.setAmount(amount) + fun updateBlinds() { + this.handHistory.smallBlind?.let { sb -> + this.firstOrNull { it.action.type == Action.Type.POST_SB }?.setAmount(sb) + } + this.handHistory.bigBlind?.let { bb -> + this.firstOrNull { it.action.type == Action.Type.POST_BB }?.setAmount(bb) + } } } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt index 25b885e9..e34bf092 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt @@ -141,8 +141,22 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra */ fun createNewHandHistory(realm: Realm, 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() - handHistory.configure(handSetup) + handHistory.configure(this.handSetup) this.playerHandMaxCards = handSetup.game?.playerHandMaxCards this.loadHandHistory(realm.copyToRealm(handHistory)) } @@ -390,11 +404,11 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra when (this.currentSelection.tag) { 0 -> { this.handHistory.smallBlind = amount - this.sortedActions.updateSmallBlind(amount) + this.sortedActions.updateBlinds() } 1 -> { this.handHistory.bigBlind = amount - this.sortedActions.updateBigBlind(amount) + this.sortedActions.updateBlinds() } 2 -> this.handHistory.ante = amount } diff --git a/app/src/main/res/menu/toolbar_hand_history.xml b/app/src/main/res/menu/toolbar_hand_history.xml index 52037b10..c147419b 100644 --- a/app/src/main/res/menu/toolbar_hand_history.xml +++ b/app/src/main/res/menu/toolbar_hand_history.xml @@ -5,6 +5,28 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b7d43541..cecfd0ab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -793,5 +793,6 @@ mississipi Add vilain + Forward