show a saving prompt at exiting the app with unsaved changes

This commit is contained in:
tibbi 2019-09-02 21:32:31 +02:00
parent d5b9347569
commit 826ee92bbd
1 changed files with 12 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import android.view.WindowManager
import android.webkit.MimeTypeMap
import android.widget.SeekBar
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.LICENSE_GLIDE
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
@ -143,7 +144,17 @@ class MainActivity : SimpleActivity(), CanvasListener {
override fun onBackPressed() {
val hasUnsavedChanges = savedPathsHash != my_canvas.getDrawingHashCode()
super.onBackPressed()
if (hasUnsavedChanges) {
ConfirmationAdvancedDialog(this, "", R.string.save_before_closing, R.string.save, R.string.discard) {
if (it) {
trySaveImage()
} else {
super.onBackPressed()
}
}
} else {
super.onBackPressed()
}
}
private fun launchSettings() {