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 c441b4ee..f6a39399 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 @@ -30,7 +30,8 @@ class HandHistoryActivity : BaseActivity() { ATTACHED("attached") } - private var currentFragment: Fragment? = null + private var replayerFragment: ReplayerFragment? = null + private var handHistoryFragment: HandHistoryFragment? = null companion object { @@ -95,20 +96,22 @@ class HandHistoryActivity : BaseActivity() { val sessionId = intent.getStringExtra(IntentKey.SESSION_CONFIGURATION.keyName) val attached = intent.getBooleanExtra(IntentKey.ATTACHED.keyName, false) - val fragment = HandHistoryFragment.newInstance(handHistoryId, sessionId, attached) + val fragment = this.handHistoryFragment ?: HandHistoryFragment.newInstance(handHistoryId, sessionId, attached) + this.handHistoryFragment = fragment + showFragment(fragment, R.id.container) - this.currentFragment = fragment } fun showReplayer(handHistoryId: String) { - val fragment = ReplayerFragment.newInstance(handHistoryId) + val fragment = this.replayerFragment ?: ReplayerFragment.newInstance(handHistoryId) + this.replayerFragment = fragment + showFragment(fragment, R.id.container) - this.currentFragment = fragment } override fun onBackPressed() { - val shouldShowDataLossWarning = ((this.currentFragment as? HandHistoryFragment)?.isEditing == true) + val shouldShowDataLossWarning = (this.handHistoryFragment?.isEditing == true) if (shouldShowDataLossWarning) { 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/HandHistoryFragment.kt index bf6ee318..41ea37a1 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/HandHistoryFragment.kt @@ -564,7 +564,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.handHistoryAdapter.notifyItemChanged(rowRepresentableIndex) this.scrollToPosition(rowRepresentableIndex) } - ?: throw PAIllegalStateException("Rowrepresentable not fouind at index $rowRepresentableIndex") + ?: throw PAIllegalStateException("RowRepresentable not found at index $rowRepresentableIndex") } // Table @@ -589,16 +589,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL * Refreshes the selected row */ private fun refreshSelectedRow() { - if (this.model.hasSelection()) { val index = this.model.currentSelection.index this.handHistoryAdapter.notifyItemChanged(index) } - -// this.model.selectionLiveData.value?.index?.let { -// Timber.d("refreshes row at index = $it") -// this.handHistoryAdapter.notifyItemChanged(it) -// } } /*** @@ -681,12 +675,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL val builder: AlertDialog.Builder = AlertDialog.Builder(context) builder.setTitle(R.string.position) - builder.setItems( - arrayOf( - getString(R.string.remove) - ) - ) { _, index -> - // The 'which' argument contains the index position + builder.setItems(arrayOf(getString(R.string.remove))) { _, index -> + // The 'when' argument contains the index position // of the selected item when (index) { 0 -> this.removePlayer(positionIndex) @@ -700,5 +690,4 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.model.clearSelection() } - } \ No newline at end of file