Fixes #35 : crash when switching back and forth between the replayer and the editor

bs
Laurent 5 years ago
parent 00086cc9e1
commit 4f32bb6df8
  1. 15
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt
  2. 17
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.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) {

@ -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<CharSequence>(
getString(R.string.remove)
)
) { _, index ->
// The 'which' argument contains the index position
builder.setItems(arrayOf<CharSequence>(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()
}
}
Loading…
Cancel
Save