Make edit/save work as expected

hh
Laurent 6 years ago
parent 76c24895c1
commit f4a4f7786e
  1. 4
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Card.kt
  2. 4
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt
  3. 32
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  4. 7
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt
  5. 10
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  6. 4
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt
  7. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt
  8. 8
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardActionView.kt
  9. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt

@ -39,8 +39,8 @@ fun List<Card>.formatted(context: Context) : CharSequence? {
open class Card : RealmObject() {
companion object {
fun newInstance(realm: Realm?, value: Int? = null, suit: Suit? = null, index: Int = 0) : Card {
val card = if (realm != null) realm.createObject(Card::class.java) else Card()
fun newInstance(value: Int? = null, suit: Suit? = null, index: Int = 0) : Card {
val card = Card()
value?.let { card.value = it }
suit?.let { card.suit = it}
card.index = index

@ -176,6 +176,10 @@ interface DisplayableDataSource {
return null
}
fun textColor(position: Int, row: RowRepresentable): Int? {
return null
}
}
/**

@ -105,15 +105,14 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
handHistoryId?.let {
val handHistory = getRealm().findById<HandHistory>(it)
?: throw PAIllegalStateException("HandHistory not found")
this.model.setHandHistory(handHistory)
val hhCopy = getRealm().copyFromRealm(handHistory)
this.model.setHandHistory(hhCopy)
this.setEditing(false)
} ?: run {
val configurationId= this.arguments?.getString(BundleKey.CONFIGURATION_ID.value)
val attached= this.arguments?.getBoolean(BundleKey.ATTACHED.value) ?: false
getRealm().executeTransaction {
this.model.createNewHandHistory(it, configurationId, attached)
}
this.model.createNewHandHistory(getRealm(), configurationId, attached)
this.setEditing(true)
}
@ -438,9 +437,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
override fun amountValidated() {
Timber.d(">>> amount validated")
getRealm().executeTransaction {
this.model.amountValidated()
}
this.findNextActionToEdit(userInitiated = true)
}
@ -449,31 +446,23 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
}
override fun amountCleared() {
getRealm().executeTransaction {
this.model.clearAmount()
}
}
override fun cardValueSelected(value: Card.Value) {
getRealm().executeTransaction {
this.model.cardValueSelected(value)
}
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index)
this.findNextActionToEdit()
}
override fun cardSuitSelected(suit: Card.Suit) {
getRealm().executeTransaction {
this.model.cardSuitSelected(suit)
}
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index)
this.findNextActionToEdit()
}
override fun clearCards() {
getRealm().executeTransaction {
this.model.clearCards()
}
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index)
}
@ -483,9 +472,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
}
override fun cardBackSpaceSelected() {
getRealm().executeTransaction {
this.model.deleteLastCardProperty()
}
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index)
}
@ -619,11 +606,16 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
* Finishes the activity to go back
*/
private fun deleteHand() {
if (this.model.handHistory.isManaged) {
// if (this.model.handHistory.isManaged) {
// this.model.handHistory.deleteFromRealm()
// }
getRealm().findById<HandHistory>(this.model.handHistory.id)?.let { hh ->
getRealm().executeTransaction {
this.model.handHistory.deleteFromRealm()
hh.deleteFromRealm()
}
}
this.activity?.finish()
}
@ -631,9 +623,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
* Creates a new hand using the current hand setup
*/
private fun addNewHand() {
getRealm().executeTransaction {
this.model.createNewHandHistoryWithCurrentSetup(it)
}
this.model.createNewHandHistoryWithCurrentSetup()
this.findNextActionToEdit(0)
}

@ -1,6 +1,5 @@
package net.pokeranalytics.android.ui.modules.handhistory.model
import io.realm.Realm
import io.realm.RealmList
import io.realm.RealmModel
import net.pokeranalytics.android.model.realm.handhistory.Card
@ -22,7 +21,7 @@ abstract class CardsRow : HandHistoryRow {
abstract fun cardLimit() : Int?
abstract val realmInstance: Realm
// abstract val realmInstance: Realm
abstract val cardHolder: CardHolder?
@ -45,7 +44,7 @@ abstract class CardsRow : HandHistoryRow {
}
fun valueSelected(value: Card.Value) {
val card = Card.newInstance(this.realmInstance, value.value)
val card = Card.newInstance(value.value)
this.add(card)
}
@ -61,7 +60,7 @@ abstract class CardsRow : HandHistoryRow {
} ?: true
if (addNewCard) {
val card = Card.newInstance(this.realmInstance, suit = suit)
val card = Card.newInstance(suit = suit)
this.add(card)
}
}

@ -152,24 +152,24 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
fun createNewHandHistory(realm: Realm, configurationId: String?, attached: Boolean) {
this.handSetup = HandSetup.from(configurationId, attached, realm)
createHandHistory(realm)
createHandHistory()
}
/***
* Creates a new hand history using the current HandSetup
*/
fun createNewHandHistoryWithCurrentSetup(realm: Realm) {
createHandHistory(realm)
fun createNewHandHistoryWithCurrentSetup() {
createHandHistory()
}
/***
* Creates a hand history using the c
*/
private fun createHandHistory(realm: Realm) {
private fun createHandHistory() {
val handHistory = HandHistory()
handHistory.configure(this.handSetup)
this.playerHandMaxCards = handSetup.game?.playerHandMaxCards
this.loadHandHistory(realm.copyToRealm(handHistory))
this.loadHandHistory(handHistory)
}
/***

@ -34,8 +34,8 @@ open class PlayerCardsRow(private var playerSetupCreationListener: PlayerSetupCr
return this.maxCards
}
override val realmInstance: Realm
get() { return this.handHistory.realm }
// override val realmInstance: Realm
// get() { return this.handHistory.realm }
override fun holderCreated() {
this.playerSetupCreationListener?.playerSetupCreated()

@ -1,6 +1,5 @@
package net.pokeranalytics.android.ui.modules.handhistory.model
import io.realm.Realm
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.model.realm.handhistory.Card
@ -33,8 +32,8 @@ class StreetCardsRow(var street: Street, var handHistory: HandHistory) : CardsRo
return this.street.totalBoardCards
}
override val realmInstance: Realm
get() { return this.handHistory.realm }
// override val realmInstance: Realm
// get() { return this.handHistory.realm }
override fun lastCard(): Card? {
return when (this.street) {

@ -91,4 +91,12 @@ class KeyboardActionView(context: Context) : AbstractKeyboardView(context),
this.dataAdapter.notifyDataSetChanged()
}
override fun textColor(position: Int, row: RowRepresentable): Int? {
return if (isEnabled(row, 0)) {
R.color.white
} else {
R.color.kaki_light
}
}
}

@ -103,6 +103,10 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl
}
it.text = title
adapter.dataSource.textColor(position, row)?.let { textColor ->
it.setTextColor(itemView.context.getColor(textColor))
}
// val color = if (adapter.dataSource.isEnabled(row, 0)) {
// R.color.white
// } else {

Loading…
Cancel
Save