|
|
|
|
@ -1,4 +1,4 @@ |
|
|
|
|
package net.pokeranalytics.android.ui.modules.handhistory |
|
|
|
|
package net.pokeranalytics.android.ui.modules.handhistory.editor |
|
|
|
|
|
|
|
|
|
import android.animation.ValueAnimator |
|
|
|
|
import android.app.Activity |
|
|
|
|
@ -29,6 +29,7 @@ import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType |
|
|
|
|
import net.pokeranalytics.android.ui.modules.datalist.DataListActivity |
|
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.HandHistoryActivity |
|
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.* |
|
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.views.KeyboardListener |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
@ -37,7 +38,7 @@ import net.pokeranalytics.android.util.extensions.findById |
|
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardListener { |
|
|
|
|
class EditorFragment : RealmFragment(), RowRepresentableDelegate, KeyboardListener { |
|
|
|
|
|
|
|
|
|
private enum class BundleKey(var value: String) { |
|
|
|
|
HAND_HISTORY_ID("hand_history_id"), |
|
|
|
|
@ -48,12 +49,12 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
/*** |
|
|
|
|
* The fragment's ViewModel |
|
|
|
|
*/ |
|
|
|
|
private lateinit var model: HandHistoryViewModel |
|
|
|
|
private lateinit var model: EditorViewModel |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* The custom adapter |
|
|
|
|
*/ |
|
|
|
|
private lateinit var handHistoryAdapter: HandHistoryAdapter |
|
|
|
|
private lateinit var editorAdapter: EditorAdapter |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* The fragment's menu |
|
|
|
|
@ -69,8 +70,9 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
fun newInstance(id: String? = null, configurationId: String? = null, attached: Boolean = false): HandHistoryFragment { |
|
|
|
|
val fragment = HandHistoryFragment() |
|
|
|
|
fun newInstance(id: String? = null, configurationId: String? = null, attached: Boolean = false): EditorFragment { |
|
|
|
|
val fragment = |
|
|
|
|
EditorFragment() |
|
|
|
|
val bundle = Bundle() |
|
|
|
|
bundle.putSerializable(BundleKey.HAND_HISTORY_ID.value, id) |
|
|
|
|
bundle.putSerializable(BundleKey.CONFIGURATION_ID.value, configurationId) |
|
|
|
|
@ -85,7 +87,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
|
|
|
|
|
|
this.model = activity?.run { |
|
|
|
|
ViewModelProviders.of(this)[HandHistoryViewModel::class.java] |
|
|
|
|
ViewModelProviders.of(this)[EditorViewModel::class.java] |
|
|
|
|
} ?: throw Exception("Invalid Activity") |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -129,7 +131,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
|
|
|
|
|
setDisplayHomeAsUpEnabled(true) |
|
|
|
|
|
|
|
|
|
this.handHistoryAdapter = HandHistoryAdapter(this.model, this) |
|
|
|
|
this.editorAdapter = |
|
|
|
|
EditorAdapter( |
|
|
|
|
this.model, |
|
|
|
|
this |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// val swipeToDelete = SwipeToDeleteCallback { position -> |
|
|
|
|
// this.model.deleteIfPossible(position) |
|
|
|
|
@ -139,7 +145,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
recyclerView.apply { |
|
|
|
|
setHasFixedSize(true) |
|
|
|
|
layoutManager = SmoothScrollLinearLayoutManager(requireContext()) |
|
|
|
|
adapter = handHistoryAdapter |
|
|
|
|
adapter = editorAdapter |
|
|
|
|
// itemTouchHelper.attachToRecyclerView(this) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -149,7 +155,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val observer = Observer<MutableList<RowRepresentable>> { |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
this.editorAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
this.model.rowsLiveData.observe(this, observer) |
|
|
|
|
|
|
|
|
|
@ -190,7 +196,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
getRealm().findById<Player>(playerId)?.let { player -> |
|
|
|
|
this.model.playerSelected(player) |
|
|
|
|
} ?: throw PAIllegalStateException("Player (id=$playerId) not found") |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
this.editorAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -289,7 +295,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
val handRow = this.model.rowRepresentableForPosition(selection.index) as? HandHistoryRow |
|
|
|
|
|
|
|
|
|
val holder = |
|
|
|
|
recyclerView.findViewHolderForAdapterPosition(selection.index) as? HandHistoryAdapter.RowHandHolder |
|
|
|
|
recyclerView.findViewHolderForAdapterPosition(selection.index) as? EditorAdapter.RowHandHolder |
|
|
|
|
holder?.let { |
|
|
|
|
val amountEditText = it.editTextForTag(selection.tag) |
|
|
|
|
this.keyboard.setAmountEditText( |
|
|
|
|
@ -313,7 +319,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
this.replayerItem?.isEnabled = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
this.editorAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
@ -339,7 +345,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
|
|
|
|
|
// The whole data set is refreshed because of a weird EditText bug where |
|
|
|
|
// the EditText wasn't displayed when the previous + current rows were refreshed separately |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
this.editorAdapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
|
|
// this.refreshCells(startIndex) |
|
|
|
|
} |
|
|
|
|
@ -350,7 +356,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
// Timber.d("onRowSelected: $position, tag = $tag, row = $row") |
|
|
|
|
if (row == HandRowType.SETTINGS_HEADER) { |
|
|
|
|
this.model.toggleSettingsRows() |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
this.editorAdapter.notifyDataSetChanged() |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -420,29 +426,29 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
when (row) { |
|
|
|
|
HandRowType.COMMENT -> { |
|
|
|
|
this.model.handHistory.comment = value as? String |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row)) |
|
|
|
|
this.editorAdapter.notifyItemChanged(this.indexOfRowRepresentable(row)) |
|
|
|
|
} |
|
|
|
|
HandRowType.PLAYER_NUMBER -> { |
|
|
|
|
this.model.setNumberOfPlayers(value as Int) |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
this.editorAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
HandRowType.ANTE -> { |
|
|
|
|
this.model.setAnte(value as Double? ?: 0.0) |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
this.editorAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
HandRowType.BIG_BLIND_ANTE -> { |
|
|
|
|
this.model.setBigBlindAnte(value as Boolean) |
|
|
|
|
// val f = { this.handHistoryAdapter.notifyDataSetChanged() } |
|
|
|
|
Handler().postDelayed({ this.handHistoryAdapter.notifyDataSetChanged() }, 250L) |
|
|
|
|
Handler().postDelayed({ this.editorAdapter.notifyDataSetChanged() }, 250L) |
|
|
|
|
// this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
HandRowType.HERO_POSITION -> { |
|
|
|
|
this.model.setHeroPosition(value as Position) |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
this.editorAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
HandRowType.PLAYER_POSITION -> { |
|
|
|
|
this.model.createPlayerSetupForPosition(value as Position) |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
this.editorAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
is ComputedAction -> { |
|
|
|
|
this.model.amountChanged(value as String) |
|
|
|
|
@ -490,7 +496,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
override fun amountValidated() { |
|
|
|
|
Timber.d(">>> amount validated") |
|
|
|
|
this.model.amountValidated() |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() // a stack update can change an allin amount |
|
|
|
|
this.editorAdapter.notifyDataSetChanged() // a stack update can change an allin amount |
|
|
|
|
this.findNextActionToEdit(userInitiated = true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -504,19 +510,19 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
|
|
|
|
|
override fun cardValueSelected(value: Card.Value) { |
|
|
|
|
this.model.cardValueSelected(value) |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) |
|
|
|
|
this.editorAdapter.notifyItemChanged(this.model.currentSelection.index) |
|
|
|
|
this.findNextActionToEdit() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun cardSuitSelected(suit: Card.Suit) { |
|
|
|
|
this.model.cardSuitSelected(suit) |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) |
|
|
|
|
this.editorAdapter.notifyItemChanged(this.model.currentSelection.index) |
|
|
|
|
this.findNextActionToEdit() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun clearCards() { |
|
|
|
|
this.model.clearCards() |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() // multiple rows can be impacted |
|
|
|
|
this.editorAdapter.notifyDataSetChanged() // multiple rows can be impacted |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun cardSelectionEnded() { |
|
|
|
|
@ -526,7 +532,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
|
|
|
|
|
override fun cardBackSpaceSelected() { |
|
|
|
|
this.model.deleteLastCardProperty() |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) |
|
|
|
|
this.editorAdapter.notifyItemChanged(this.model.currentSelection.index) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
@ -548,7 +554,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
override fun closeKeyboard() { |
|
|
|
|
val currentIndex = this.model.currentSelection.index |
|
|
|
|
this.model.clearSelection() |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(currentIndex) |
|
|
|
|
this.editorAdapter.notifyItemChanged(currentIndex) |
|
|
|
|
this.animateKeyboard(false) |
|
|
|
|
// this.hideKeyboard() |
|
|
|
|
} |
|
|
|
|
@ -561,7 +567,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
val rowRepresentableIndex = this.model.nextActionIndexForPosition(position) |
|
|
|
|
this.model.rowRepresentableForPosition(rowRepresentableIndex)?.let { |
|
|
|
|
onRowSelected(rowRepresentableIndex, it, ComputedAction.Tag.ACTION.ordinal) |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(rowRepresentableIndex) |
|
|
|
|
this.editorAdapter.notifyItemChanged(rowRepresentableIndex) |
|
|
|
|
this.scrollToPosition(rowRepresentableIndex) |
|
|
|
|
} |
|
|
|
|
?: throw PAIllegalStateException("RowRepresentable not found at index $rowRepresentableIndex") |
|
|
|
|
@ -581,7 +587,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
* Refreshes the cell at [index] and also selected row |
|
|
|
|
*/ |
|
|
|
|
private fun refreshRowAtIndexAndCurrent(index: Int) { |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(index) |
|
|
|
|
this.editorAdapter.notifyItemChanged(index) |
|
|
|
|
refreshSelectedRow() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -591,7 +597,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
private fun refreshSelectedRow() { |
|
|
|
|
if (this.model.hasSelection()) { |
|
|
|
|
val index = this.model.currentSelection.index |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(index) |
|
|
|
|
this.editorAdapter.notifyItemChanged(index) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|