Renamed vague HandHistory prefix into Editor where needed

bs
Laurent 5 years ago
parent 4f32bb6df8
commit e3aaffc310
  1. 9
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt
  2. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/editor/EditorAdapter.kt
  3. 66
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/editor/EditorFragment.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt
  5. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  6. 4
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt
  7. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt
  8. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt
  9. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StraddleRowRepresentable.kt
  10. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt
  11. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetHeaderRow.kt

@ -15,6 +15,7 @@ import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.activity.components.BaseActivity
import net.pokeranalytics.android.ui.activity.components.RequestCode
import net.pokeranalytics.android.ui.modules.handhistory.editor.EditorFragment
import net.pokeranalytics.android.ui.modules.handhistory.replayer.ReplayExportService
import net.pokeranalytics.android.ui.modules.handhistory.replayer.ReplayerFragment
import timber.log.Timber
@ -31,7 +32,7 @@ class HandHistoryActivity : BaseActivity() {
}
private var replayerFragment: ReplayerFragment? = null
private var handHistoryFragment: HandHistoryFragment? = null
private var editorFragment: EditorFragment? = null
companion object {
@ -96,8 +97,8 @@ class HandHistoryActivity : BaseActivity() {
val sessionId = intent.getStringExtra(IntentKey.SESSION_CONFIGURATION.keyName)
val attached = intent.getBooleanExtra(IntentKey.ATTACHED.keyName, false)
val fragment = this.handHistoryFragment ?: HandHistoryFragment.newInstance(handHistoryId, sessionId, attached)
this.handHistoryFragment = fragment
val fragment = this.editorFragment ?: EditorFragment.newInstance(handHistoryId, sessionId, attached)
this.editorFragment = fragment
showFragment(fragment, R.id.container)
}
@ -111,7 +112,7 @@ class HandHistoryActivity : BaseActivity() {
override fun onBackPressed() {
val shouldShowDataLossWarning = (this.handHistoryFragment?.isEditing == true)
val shouldShowDataLossWarning = (this.editorFragment?.isEditing == true)
if (shouldShowDataLossWarning) {

@ -1,4 +1,4 @@
package net.pokeranalytics.android.ui.modules.handhistory
package net.pokeranalytics.android.ui.modules.handhistory.editor
import android.content.res.ColorStateList
import android.text.InputType
@ -102,7 +102,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable {
}
class HandHistoryAdapter(
class EditorAdapter(
override var dataSource: RowRepresentableDataSource,
override var delegate: RowRepresentableDelegate? = null) :
RecyclerView.Adapter<RecyclerView.ViewHolder>(),
@ -314,7 +314,7 @@ class HandHistoryAdapter(
val inflater = LayoutInflater.from(itemView.context)
val isEdited = (dataSource as HandHistoryViewModel).isEdited
val isEdited = (dataSource as EditorViewModel).isEdited
dataSource.rowRepresentableForPosition(this.currentPosition)?.let { row ->

@ -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)
}
}

@ -2,7 +2,7 @@ package net.pokeranalytics.android.ui.modules.handhistory.model
import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.handhistory.Action
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.editor.HandRowType
import net.pokeranalytics.android.ui.view.RowRepresentable
class ActionReadRow(var positions: MutableList<Position>,

@ -6,7 +6,7 @@ import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.model.realm.handhistory.Action
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.realm.handhistory.toReadRow
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.editor.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.replayer.HandStep
import timber.log.Timber
import kotlin.math.max

@ -21,7 +21,7 @@ import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.realm.handhistory.formatted
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.editor.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.views.CardCentralizer
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
@ -45,7 +45,7 @@ interface PlayerSetupCreationListener {
fun playerSetupCreated()
}
class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentralizer, ActionListListener {
class EditorViewModel : ViewModel(), RowRepresentableDataSource, CardCentralizer, ActionListListener {
private val coroutineContext: CoroutineContext
get() = Dispatchers.Main

@ -3,7 +3,7 @@ package net.pokeranalytics.android.ui.modules.handhistory.model
import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.editor.HandRowType
open class PlayerCardsRow(private var playerSetupCreationListener: PlayerSetupCreationListener?,
var position: Position,

@ -3,7 +3,7 @@ package net.pokeranalytics.android.ui.modules.handhistory.model
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.editor.HandRowType
class PlayerSetupRow(private var readMode: Boolean = false,
position: Position,

@ -1,7 +1,7 @@
package net.pokeranalytics.android.ui.modules.handhistory.model
import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.editor.HandRowType
import net.pokeranalytics.android.ui.view.RowRepresentable
class StraddleRowRepresentable(

@ -4,7 +4,7 @@ import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.editor.HandRowType
class StreetCardsRow(var street: Street, var handHistory: HandHistory) : CardsRow() {

@ -2,7 +2,7 @@ package net.pokeranalytics.android.ui.modules.handhistory.model
import android.content.Context
import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.editor.HandRowType
import net.pokeranalytics.android.ui.view.RowRepresentable

Loading…
Cancel
Save