From b5a1600dab64cbde24cb1942c6479620bdfd067c Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 20 Nov 2016 23:00:15 +0100 Subject: [PATCH] simplify delete checking --- .../gallery/activities/MainActivity.kt | 15 ++++--------- .../gallery/activities/MediaActivity.kt | 21 +++++-------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 2ca7086d4..7dab55c05 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -12,7 +12,6 @@ import android.support.design.widget.Snackbar import android.support.v4.app.ActivityCompat import android.view.Menu import android.view.MenuItem -import android.view.MotionEvent import android.view.View import com.simplemobiletools.filepicker.extensions.* import com.simplemobiletools.gallery.Constants @@ -26,7 +25,7 @@ import kotlinx.android.synthetic.main.activity_main.* import java.io.File import java.util.* -class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesListener, View.OnTouchListener, DirectoryAdapter.DirOperationsListener { +class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesListener, DirectoryAdapter.DirOperationsListener { companion object { private val STORAGE_PERMISSION = 1 private val PICK_MEDIA = 2 @@ -36,7 +35,6 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis lateinit var mDirs: ArrayList lateinit var mToBeDeleted: ArrayList - private var mIsSnackbarShown = false private var mIsPickImageIntent = false private var mIsPickVideoIntent = false private var mIsGetImageContentIntent = false @@ -170,7 +168,6 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis setActionTextColor(Color.WHITE) show() } - mIsSnackbarShown = true } private fun deleteDirs() { @@ -178,7 +175,6 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis return mSnackbar?.dismiss() - mIsSnackbarShown = false val updatedFiles = ArrayList() for (delPath in mToBeDeleted) { @@ -217,7 +213,6 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis private val undoDeletion = View.OnClickListener { mSnackbar!!.dismiss() - mIsSnackbarShown = false mToBeDeleted.clear() getDirectories() } @@ -302,18 +297,16 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis itemClicked(it.path) } directories_grid.adapter = adapter - directories_grid.setOnTouchListener(this) + directories_grid.setOnTouchListener { view, motionEvent -> checkDelete(); false } } override fun refreshItems() { getDirectories() } - override fun onTouch(v: View, event: MotionEvent): Boolean { - if (mIsSnackbarShown) { + fun checkDelete() { + if (mSnackbar?.isShown == true) { deleteDirs() } - - return false } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 370fa695a..b95d69744 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -11,7 +11,6 @@ import android.support.design.widget.Snackbar import android.util.Log import android.view.Menu import android.view.MenuItem -import android.view.MotionEvent import android.view.View import com.bumptech.glide.Glide import com.bumptech.glide.request.animation.GlideAnimation @@ -29,7 +28,7 @@ import java.io.File import java.io.IOException import java.util.* -class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.MediaOperationsListener { +class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { companion object { private val TAG = MediaActivity::class.java.simpleName @@ -39,7 +38,6 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media lateinit var mMedia: ArrayList private var mPath = "" - private var mIsSnackbarShown = false private var mIsGetImageIntent = false private var mIsGetVideoIntent = false private var mIsGetAnyIntent = false @@ -90,8 +88,7 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media } media_grid.adapter = adapter - media_grid.setOnTouchListener(this) - mIsSnackbarShown = false + media_grid.setOnTouchListener { view, motionEvent -> checkDelete(); false } } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -212,7 +209,6 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media setActionTextColor(Color.WHITE) show() } - mIsSnackbarShown = true updateMediaView() } } @@ -221,11 +217,7 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media if (mToBeDeleted.isEmpty()) return - if (mSnackbar != null) { - mSnackbar!!.dismiss() - } - - mIsSnackbarShown = false + mSnackbar?.dismiss() var wereFilesDeleted = false for (delPath in mToBeDeleted) { @@ -262,7 +254,6 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media private val undoDeletion = View.OnClickListener { mSnackbar!!.dismiss() - mIsSnackbarShown = false mToBeDeleted.clear() updateMediaView() } @@ -313,12 +304,10 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media } } - override fun onTouch(v: View, event: MotionEvent): Boolean { - if (mIsSnackbarShown) { + fun checkDelete() { + if (mSnackbar?.isShown == true) { deleteFiles() } - - return false } override fun refreshItems() {