mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-06-05 21:59:17 +02:00
add an initial check related to exiting the app with unsaved changes
This commit is contained in:
@ -51,6 +51,7 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
|||||||
private var uriToLoad: Uri? = null
|
private var uriToLoad: Uri? = null
|
||||||
private var color = 0
|
private var color = 0
|
||||||
private var brushSize = 0f
|
private var brushSize = 0f
|
||||||
|
private var savedPathsHash = 0L
|
||||||
private var isEraserOn = false
|
private var isEraserOn = false
|
||||||
private var isImageCaptureIntent = false
|
private var isImageCaptureIntent = false
|
||||||
private var isEditIntent = false
|
private var isEditIntent = false
|
||||||
@ -140,6 +141,11 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
val hasUnsavedChanges = savedPathsHash != my_canvas.getDrawingHashCode()
|
||||||
|
super.onBackPressed()
|
||||||
|
}
|
||||||
|
|
||||||
private fun launchSettings() {
|
private fun launchSettings() {
|
||||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||||
}
|
}
|
||||||
@ -344,6 +350,7 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
|||||||
|
|
||||||
private fun saveImage() {
|
private fun saveImage() {
|
||||||
SaveImageDialog(this, defaultExtension, defaultPath, defaultFilename) {
|
SaveImageDialog(this, defaultExtension, defaultPath, defaultFilename) {
|
||||||
|
savedPathsHash = my_canvas.getDrawingHashCode()
|
||||||
saveFile(it)
|
saveFile(it)
|
||||||
defaultPath = it.getParentPath()
|
defaultPath = it.getParentPath()
|
||||||
defaultFilename = it.getFilenameFromPath()
|
defaultFilename = it.getFilenameFromPath()
|
||||||
|
@ -248,6 +248,8 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
|
|||||||
mListener?.toggleUndoVisibility(mPaths.isNotEmpty() || mLastPaths.isNotEmpty())
|
mListener?.toggleUndoVisibility(mPaths.isNotEmpty() || mLastPaths.isNotEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getDrawingHashCode() = mPaths.hashCode().toLong() + (mBackgroundBitmap?.hashCode()?.toLong() ?: 0L)
|
||||||
|
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
if (mAllowZooming) {
|
if (mAllowZooming) {
|
||||||
mScaleDetector!!.onTouchEvent(event)
|
mScaleDetector!!.onTouchEvent(event)
|
||||||
|
Reference in New Issue
Block a user