add an initial check related to exiting the app with unsaved changes

This commit is contained in:
tibbi 2019-09-02 20:58:07 +02:00
parent b904cd7cb4
commit 1ac25358b8
2 changed files with 9 additions and 0 deletions

View File

@ -51,6 +51,7 @@ class MainActivity : SimpleActivity(), CanvasListener {
private var uriToLoad: Uri? = null
private var color = 0
private var brushSize = 0f
private var savedPathsHash = 0L
private var isEraserOn = false
private var isImageCaptureIntent = false
private var isEditIntent = false
@ -140,6 +141,11 @@ class MainActivity : SimpleActivity(), CanvasListener {
return true
}
override fun onBackPressed() {
val hasUnsavedChanges = savedPathsHash != my_canvas.getDrawingHashCode()
super.onBackPressed()
}
private fun launchSettings() {
startActivity(Intent(applicationContext, SettingsActivity::class.java))
}
@ -344,6 +350,7 @@ class MainActivity : SimpleActivity(), CanvasListener {
private fun saveImage() {
SaveImageDialog(this, defaultExtension, defaultPath, defaultFilename) {
savedPathsHash = my_canvas.getDrawingHashCode()
saveFile(it)
defaultPath = it.getParentPath()
defaultFilename = it.getFilenameFromPath()

View File

@ -248,6 +248,8 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
mListener?.toggleUndoVisibility(mPaths.isNotEmpty() || mLastPaths.isNotEmpty())
}
fun getDrawingHashCode() = mPaths.hashCode().toLong() + (mBackgroundBitmap?.hashCode()?.toLong() ?: 0L)
override fun onTouchEvent(event: MotionEvent): Boolean {
if (mAllowZooming) {
mScaleDetector!!.onTouchEvent(event)