diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt index f6a39399..8c436f19 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.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) { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/editor/EditorAdapter.kt similarity index 99% rename from app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt rename to app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/editor/EditorAdapter.kt index d87f0af5..1063f113 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/editor/EditorAdapter.kt @@ -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(), @@ -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 -> 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/editor/EditorFragment.kt similarity index 90% rename from app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt rename to app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/editor/EditorFragment.kt index 41ea37a1..1f676b89 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/editor/EditorFragment.kt @@ -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> { - this.handHistoryAdapter.notifyDataSetChanged() + this.editorAdapter.notifyDataSetChanged() } this.model.rowsLiveData.observe(this, observer) @@ -190,7 +196,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL getRealm().findById(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) } } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt index 2ee6ae09..1ed89f58 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt @@ -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, diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt index 7349a728..4c1072d1 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt @@ -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 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/EditorViewModel.kt similarity index 99% rename from app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt rename to app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt index 0ebe9f0b..869162b2 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/EditorViewModel.kt @@ -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 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 2fd96aa8..b2ddf14d 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 @@ -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, diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt index a1e90553..514b4d69 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt @@ -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, diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StraddleRowRepresentable.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StraddleRowRepresentable.kt index 4baac1f1..f10ce251 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StraddleRowRepresentable.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StraddleRowRepresentable.kt @@ -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( 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 62939334..00e5ec33 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 @@ -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() { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetHeaderRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetHeaderRow.kt index 91f460c6..23f5c27f 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetHeaderRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetHeaderRow.kt @@ -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