cleanup + crash fix

hh
Laurent 6 years ago
parent f4a4f7786e
commit 8b6c1d0ee2
  1. 103
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  2. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  4. 4
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt
  5. 9
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt

@ -91,11 +91,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
initData() initData()
initUI() initUI()
// if (this.model.isEdited) {
// this.findNextActionToEdit(0)
// }
} }
private fun initData() { private fun initData() {
@ -191,7 +186,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
initKeyboardDefaultHeight() initKeyboardDefaultHeight()
this.keyboard.keyboardListener = this this.keyboard.keyboardListener = this
// this.keyboard.setCardCentralizer(this.model)
} }
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
@ -344,58 +338,40 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
override fun onRowValueChanged(value: Any?, row: RowRepresentable) { override fun onRowValueChanged(value: Any?, row: RowRepresentable) {
getRealm().executeTransaction { when (row) {
HandRowType.COMMENT -> {
when (row) { this.model.handHistory.comment = value as? String
HandRowType.COMMENT -> { this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row))
this.model.handHistory.comment = value as? String }
this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row)) HandRowType.PLAYER_NUMBER -> {
} this.model.setNumberOfPlayers(value as Int)
HandRowType.PLAYER_NUMBER -> { this.handHistoryAdapter.notifyDataSetChanged()
this.model.setNumberOfPlayers(value as Int) }
this.handHistoryAdapter.notifyDataSetChanged() HandRowType.ANTE -> {
} this.model.setAnte(value as Double? ?: 0.0)
HandRowType.ANTE -> { this.handHistoryAdapter.notifyDataSetChanged()
this.model.setAnte(value as Double? ?: 0.0) }
this.handHistoryAdapter.notifyDataSetChanged() HandRowType.BIG_BLIND_ANTE -> {
} this.model.setBigBlindAnte(value as Boolean)
HandRowType.BIG_BLIND_ANTE -> { this.handHistoryAdapter.notifyDataSetChanged()
this.model.setBigBlindAnte(value as Boolean) }
this.handHistoryAdapter.notifyDataSetChanged() HandRowType.HERO_POSITION -> {
} this.model.setHeroPosition(value as Position)
HandRowType.HERO_POSITION -> { this.handHistoryAdapter.notifyDataSetChanged()
this.model.setHeroPosition(value as Position)
this.handHistoryAdapter.notifyDataSetChanged()
// this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row)) // 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<Position>)
}
// 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<Position>)
}
} }
} }
override fun onItemClick(position: Int, row: RowRepresentable, tag: Int) { override fun onItemClick(position: Int, row: RowRepresentable, tag: Int) {
@ -404,15 +380,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
is PositionalRow -> { is PositionalRow -> {
this.model.tappedPlayerPositionIndex = row.positionIndex this.model.tappedPlayerPositionIndex = row.positionIndex
DataListActivity.newDialogInstance(this, LiveData.PLAYER, true) 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) { override fun actionSelected(action: Action.Type) {
Timber.d(">>> action $action selected") Timber.d(">>> action $action selected")
getRealm().executeTransaction { this.model.actionSelected(action)
this.model.actionSelected(action)
}
this.findNextActionToEdit() this.findNextActionToEdit()
} }
@ -565,7 +530,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val start = if (show) 0.0f else height val start = if (show) 0.0f else height
val end = if (show) height else 0.0f val end = if (show) height else 0.0f
// val end = (this.kbTopGuideline.layoutParams as ConstraintLayout.LayoutParams).guideEnd
val valueAnimator = ValueAnimator.ofFloat(start, end) val valueAnimator = ValueAnimator.ofFloat(start, end)
valueAnimator.duration = 150L valueAnimator.duration = 150L
// set duration // set duration
@ -606,9 +570,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
* Finishes the activity to go back * Finishes the activity to go back
*/ */
private fun deleteHand() { private fun deleteHand() {
// if (this.model.handHistory.isManaged) {
// this.model.handHistory.deleteFromRealm()
// }
getRealm().findById<HandHistory>(this.model.handHistory.id)?.let { hh -> getRealm().findById<HandHistory>(this.model.handHistory.id)?.let { hh ->
getRealm().executeTransaction { getRealm().executeTransaction {

@ -12,7 +12,7 @@ interface CardHolder : RealmModel {
abstract class CardsRow : HandHistoryRow { abstract class CardsRow : HandHistoryRow {
private val MAXCARDS = 7 private val MAX_CARDS = 7
val cardCount: Int val cardCount: Int
get() { return this.cardHolder?.cards?.size ?: 0 } get() { return this.cardHolder?.cards?.size ?: 0 }
@ -21,8 +21,6 @@ abstract class CardsRow : HandHistoryRow {
abstract fun cardLimit() : Int? abstract fun cardLimit() : Int?
// abstract val realmInstance: Realm
abstract val cardHolder: CardHolder? abstract val cardHolder: CardHolder?
override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean { override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean {
@ -106,7 +104,6 @@ abstract class CardsRow : HandHistoryRow {
if (this.cardCount >= 5) { if (this.cardCount >= 5) {
Timber.w("The card holder currently have ${this.cardCount} cards") Timber.w("The card holder currently have ${this.cardCount} cards")
return return
// throw PAIllegalStateException("Can't add anymore cards")
} }
card.index = this.cardCount card.index = this.cardCount

@ -581,7 +581,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
this.handHistory.actions.addAll(actions) this.handHistory.actions.addAll(actions)
if (!this.handHistory.isManaged) { if (!this.handHistory.isManaged) {
realm.copyToRealm(this.handHistory) realm.copyToRealmOrUpdate(this.handHistory)
} }
} }
} }

@ -1,6 +1,5 @@
package net.pokeranalytics.android.ui.modules.handhistory.model package net.pokeranalytics.android.ui.modules.handhistory.model
import io.realm.Realm
import net.pokeranalytics.android.model.handhistory.Position import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup
@ -34,9 +33,6 @@ open class PlayerCardsRow(private var playerSetupCreationListener: PlayerSetupCr
return this.maxCards return this.maxCards
} }
// override val realmInstance: Realm
// get() { return this.handHistory.realm }
override fun holderCreated() { override fun holderCreated() {
this.playerSetupCreationListener?.playerSetupCreated() this.playerSetupCreationListener?.playerSetupCreated()
} }

@ -20,21 +20,12 @@ class StreetCardsRow(var street: Street, var handHistory: HandHistory) : CardsRo
override fun tagsForCompletion(): List<Int> { override fun tagsForCompletion(): List<Int> {
return listOf(this.street.ordinal) 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 { override fun cardLimit() : Int {
return this.street.totalBoardCards return this.street.totalBoardCards
} }
// override val realmInstance: Realm
// get() { return this.handHistory.realm }
override fun lastCard(): Card? { override fun lastCard(): Card? {
return when (this.street) { return when (this.street) {
Street.SUMMARY -> this.cardHolder?.cards?.lastOrNull() Street.SUMMARY -> this.cardHolder?.cards?.lastOrNull()

Loading…
Cancel
Save