Implemented checking for unsaved changes on back button press
This commit is contained in:
parent
d73e359c27
commit
9e072f1d5e
|
@ -1,5 +1,6 @@
|
|||
package net.dankito.banking.ui.android.dialogs.settings
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
|
@ -45,6 +46,25 @@ abstract class SettingsDialogBase : DialogFragment() {
|
|||
}
|
||||
|
||||
|
||||
override fun setupDialog(dialog: Dialog, style: Int) {
|
||||
super.setupDialog(dialog, style)
|
||||
|
||||
dialog.setOnKeyListener { _, keyCode, event ->
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {
|
||||
return@setOnKeyListener handleBackButtonPress()
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun handleBackButtonPress(): Boolean {
|
||||
askToDismissChanges()
|
||||
|
||||
return hasUnsavedChanges
|
||||
}
|
||||
|
||||
|
||||
protected open fun setupToolbar(toolbar: Toolbar, dialogTitle: String, showSaveButton: Boolean = true) {
|
||||
toolbar.apply {
|
||||
title = dialogTitle
|
||||
|
@ -103,7 +123,7 @@ abstract class SettingsDialogBase : DialogFragment() {
|
|||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface) {
|
||||
log.info("Dismissung Fragment $this")
|
||||
log.info("Dismissing Fragment $this")
|
||||
|
||||
super.onDismiss(dialog)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue