Fixes #21 : unwanted back provokes data loss

hh
Laurent 6 years ago
parent 33dc5aaf1e
commit d4697d537e
  1. 38
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryActivity.kt
  2. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 1
      app/src/main/res/values/strings.xml

@ -1,14 +1,15 @@
package net.pokeranalytics.android.ui.modules.handhistory
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.activity.components.BaseActivity
import net.pokeranalytics.android.ui.activity.components.RequestCode
import net.pokeranalytics.android.ui.modules.handhistory.evaluator.Hand
import timber.log.Timber
class HandHistoryActivity : BaseActivity() {
@ -18,6 +19,8 @@ class HandHistoryActivity : BaseActivity() {
ATTACHED("attached")
}
private var fragment: HandHistoryFragment? = null
companion object {
fun newInstance(fragment: Fragment, session: Session, attached: Boolean) {
@ -57,18 +60,31 @@ class HandHistoryActivity : BaseActivity() {
fragmentTransaction.add(R.id.container, fragment)
fragmentTransaction.commit()
// test()
this.fragment = fragment
}
fun test() {
override fun onBackPressed() {
var shouldShowDataLossWarning = false
this.fragment?.let { hhFragment ->
if (hhFragment.isEditing) {
shouldShowDataLossWarning = true
}
}
if (shouldShowDataLossWarning) {
val h1 = Hand.fromString("Kd Ts Jc Ah Qc")
val h2 = Hand.fromString("Kd 5d Jd Ad Qd")
val r1 = Hand.evaluate(h1)
val r2 = Hand.evaluate(h2)
Timber.d(">>> Hand evaluation = $r1")
Timber.d(">>> Hand evaluation = $r2")
AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(R.string.your_attention)
.setMessage(R.string.data_loss_warning)
.setPositiveButton(R.string.yes) { _, _ -> finish() }
.setNegativeButton(R.string.no, null)
.show()
} else {
super.onBackPressed()
}
}

@ -60,6 +60,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
*/
private var menu: Menu? = null
val isEditing: Boolean
get() {
return this.model.isEdited
}
companion object {
fun newInstance(id: String? = null, configurationId: String? = null, attached: Boolean = false): HandHistoryFragment {

@ -799,5 +799,6 @@
<string name="text">Text</string>
<string name="hh_player_setting">tap to set player, hand or stack</string>
<string name="board">board</string>
<string name="data_loss_warning">All unsaved changes will be lost. Do you really want to continue?</string>
</resources>

Loading…
Cancel
Save