mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-01-10 06:53:15 +01:00
add an initial check related to exiting the app with unsaved changes
This commit is contained in:
parent
b904cd7cb4
commit
1ac25358b8
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user