From 8b6c1d0ee260797a86202125f8ffe5b91df72225 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 18 Mar 2020 12:26:24 +0100 Subject: [PATCH] cleanup + crash fix --- .../handhistory/HandHistoryFragment.kt | 103 ++++++------------ .../ui/modules/handhistory/model/CardsRow.kt | 5 +- .../handhistory/model/HandHistoryViewModel.kt | 2 +- .../handhistory/model/PlayerCardsRow.kt | 4 - .../handhistory/model/StreetCardsRow.kt | 9 -- 5 files changed, 34 insertions(+), 89 deletions(-) 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 b719896c..c65f2abd 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 @@ -91,11 +91,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL super.onViewCreated(view, savedInstanceState) initData() initUI() - -// if (this.model.isEdited) { -// this.findNextActionToEdit(0) -// } - } private fun initData() { @@ -191,7 +186,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL initKeyboardDefaultHeight() this.keyboard.keyboardListener = this -// this.keyboard.setCardCentralizer(this.model) } override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { @@ -344,58 +338,40 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL override fun onRowValueChanged(value: Any?, row: RowRepresentable) { - getRealm().executeTransaction { - - when (row) { - HandRowType.COMMENT -> { - this.model.handHistory.comment = value as? String - this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row)) - } - HandRowType.PLAYER_NUMBER -> { - this.model.setNumberOfPlayers(value as Int) - this.handHistoryAdapter.notifyDataSetChanged() - } - HandRowType.ANTE -> { - this.model.setAnte(value as Double? ?: 0.0) - this.handHistoryAdapter.notifyDataSetChanged() - } - HandRowType.BIG_BLIND_ANTE -> { - this.model.setBigBlindAnte(value as Boolean) - this.handHistoryAdapter.notifyDataSetChanged() - } - HandRowType.HERO_POSITION -> { - this.model.setHeroPosition(value as Position) - this.handHistoryAdapter.notifyDataSetChanged() + when (row) { + HandRowType.COMMENT -> { + this.model.handHistory.comment = value as? String + this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row)) + } + HandRowType.PLAYER_NUMBER -> { + this.model.setNumberOfPlayers(value as Int) + this.handHistoryAdapter.notifyDataSetChanged() + } + HandRowType.ANTE -> { + this.model.setAnte(value as Double? ?: 0.0) + this.handHistoryAdapter.notifyDataSetChanged() + } + HandRowType.BIG_BLIND_ANTE -> { + this.model.setBigBlindAnte(value as Boolean) + this.handHistoryAdapter.notifyDataSetChanged() + } + HandRowType.HERO_POSITION -> { + this.model.setHeroPosition(value as Position) + this.handHistoryAdapter.notifyDataSetChanged() // this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row)) - } - HandRowType.PLAYER_POSITION -> { - this.model.createPlayerSetupForPosition(value as Position) - this.handHistoryAdapter.notifyDataSetChanged() - } - is ComputedAction -> { - this.model.currentAmount = value as String - } - is StraddleRowRepresentable -> { - this.model.changeStraddleSelection(value as LinkedHashSet) - } -// is PlayerSetupRow -> { -// when (value) { -// is Position -> { -// this.model.setPlayerSetupPosition(row, value) -// val index = this.indexOfRowRepresentable(row) -// this.handHistoryAdapter.notifyItemChanged(index) -// -// // Change the focus only for the row, don't look elsewhere -//// val anyEmpty = row.tagsForCompletion().any { row.isFieldNeedsInput(it, this.model.handHistory) } -//// if (anyEmpty) { -//// this.findNextActionToEdit(index) -//// } -// } -// } -// } } - + HandRowType.PLAYER_POSITION -> { + this.model.createPlayerSetupForPosition(value as Position) + this.handHistoryAdapter.notifyDataSetChanged() + } + is ComputedAction -> { + this.model.currentAmount = value as String + } + is StraddleRowRepresentable -> { + this.model.changeStraddleSelection(value as LinkedHashSet) + } } + } override fun onItemClick(position: Int, row: RowRepresentable, tag: Int) { @@ -404,15 +380,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL is PositionalRow -> { this.model.tappedPlayerPositionIndex = row.positionIndex DataListActivity.newDialogInstance(this, LiveData.PLAYER, true) -// when (tag) { -// PlayerSetupRow.Tag.PLAYER.ordinal -> { -// this.model.clickPlayerPosition = position -// DataListActivity.newDialogInstance(this, LiveData.PLAYER, true) -// } -// else -> { -// Timber.d("onItemClick not configured for row: $row, position: $position, tag: $tag") -// } -// } } } @@ -429,9 +396,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL override fun actionSelected(action: Action.Type) { Timber.d(">>> action $action selected") - getRealm().executeTransaction { - this.model.actionSelected(action) - } + this.model.actionSelected(action) this.findNextActionToEdit() } @@ -565,7 +530,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL val start = if (show) 0.0f else height val end = if (show) height else 0.0f -// val end = (this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams).guideEnd val valueAnimator = ValueAnimator.ofFloat(start, end) valueAnimator.duration = 150L // set duration @@ -606,9 +570,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL * Finishes the activity to go back */ private fun deleteHand() { -// if (this.model.handHistory.isManaged) { -// this.model.handHistory.deleteFromRealm() -// } getRealm().findById(this.model.handHistory.id)?.let { hh -> getRealm().executeTransaction { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt index f2f1da74..ce8a8383 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt @@ -12,7 +12,7 @@ interface CardHolder : RealmModel { abstract class CardsRow : HandHistoryRow { - private val MAXCARDS = 7 + private val MAX_CARDS = 7 val cardCount: Int get() { return this.cardHolder?.cards?.size ?: 0 } @@ -21,8 +21,6 @@ abstract class CardsRow : HandHistoryRow { abstract fun cardLimit() : Int? -// abstract val realmInstance: Realm - abstract val cardHolder: CardHolder? override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean { @@ -106,7 +104,6 @@ abstract class CardsRow : HandHistoryRow { if (this.cardCount >= 5) { Timber.w("The card holder currently have ${this.cardCount} cards") return -// throw PAIllegalStateException("Can't add anymore cards") } card.index = this.cardCount 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 f01aeddd..66218992 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 @@ -581,7 +581,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra this.handHistory.actions.addAll(actions) if (!this.handHistory.isManaged) { - realm.copyToRealm(this.handHistory) + realm.copyToRealmOrUpdate(this.handHistory) } } } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt index 88b3b46a..bdee92bc 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt @@ -1,6 +1,5 @@ package net.pokeranalytics.android.ui.modules.handhistory.model -import io.realm.Realm import net.pokeranalytics.android.model.handhistory.Position import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup @@ -34,9 +33,6 @@ open class PlayerCardsRow(private var playerSetupCreationListener: PlayerSetupCr return this.maxCards } -// override val realmInstance: Realm -// get() { return this.handHistory.realm } - override fun holderCreated() { this.playerSetupCreationListener?.playerSetupCreated() } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt index a0cb8b00..93b7b7d8 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt @@ -20,21 +20,12 @@ class StreetCardsRow(var street: Street, var handHistory: HandHistory) : CardsRo override fun tagsForCompletion(): List { return listOf(this.street.ordinal) -// return when (this.street) { -// Street.PREFLOP -> listOf() -// Street.FLOP -> listOf(Street.FLOP.ordinal) -// Street.TURN -> listOf(Street.FLOP.ordinal, Street.TURN.ordinal) -// Street.RIVER, Street.SUMMARY -> listOf(Street.FLOP.ordinal, Street.TURN.ordinal, Street.RIVER.ordinal) -// } } override fun cardLimit() : Int { return this.street.totalBoardCards } -// override val realmInstance: Realm -// get() { return this.handHistory.realm } - override fun lastCard(): Card? { return when (this.street) { Street.SUMMARY -> this.cardHolder?.cards?.lastOrNull()