mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
simplify delete checking
This commit is contained in:
parent
38169b1203
commit
b5a1600dab
2 changed files with 9 additions and 27 deletions
|
@ -12,7 +12,6 @@ import android.support.design.widget.Snackbar
|
||||||
import android.support.v4.app.ActivityCompat
|
import android.support.v4.app.ActivityCompat
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.MotionEvent
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.simplemobiletools.filepicker.extensions.*
|
import com.simplemobiletools.filepicker.extensions.*
|
||||||
import com.simplemobiletools.gallery.Constants
|
import com.simplemobiletools.gallery.Constants
|
||||||
|
@ -26,7 +25,7 @@ import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesListener, View.OnTouchListener, DirectoryAdapter.DirOperationsListener {
|
class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesListener, DirectoryAdapter.DirOperationsListener {
|
||||||
companion object {
|
companion object {
|
||||||
private val STORAGE_PERMISSION = 1
|
private val STORAGE_PERMISSION = 1
|
||||||
private val PICK_MEDIA = 2
|
private val PICK_MEDIA = 2
|
||||||
|
@ -36,7 +35,6 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis
|
||||||
lateinit var mDirs: ArrayList<Directory>
|
lateinit var mDirs: ArrayList<Directory>
|
||||||
lateinit var mToBeDeleted: ArrayList<String>
|
lateinit var mToBeDeleted: ArrayList<String>
|
||||||
|
|
||||||
private var mIsSnackbarShown = false
|
|
||||||
private var mIsPickImageIntent = false
|
private var mIsPickImageIntent = false
|
||||||
private var mIsPickVideoIntent = false
|
private var mIsPickVideoIntent = false
|
||||||
private var mIsGetImageContentIntent = false
|
private var mIsGetImageContentIntent = false
|
||||||
|
@ -170,7 +168,6 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis
|
||||||
setActionTextColor(Color.WHITE)
|
setActionTextColor(Color.WHITE)
|
||||||
show()
|
show()
|
||||||
}
|
}
|
||||||
mIsSnackbarShown = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteDirs() {
|
private fun deleteDirs() {
|
||||||
|
@ -178,7 +175,6 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis
|
||||||
return
|
return
|
||||||
|
|
||||||
mSnackbar?.dismiss()
|
mSnackbar?.dismiss()
|
||||||
mIsSnackbarShown = false
|
|
||||||
|
|
||||||
val updatedFiles = ArrayList<File>()
|
val updatedFiles = ArrayList<File>()
|
||||||
for (delPath in mToBeDeleted) {
|
for (delPath in mToBeDeleted) {
|
||||||
|
@ -217,7 +213,6 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis
|
||||||
|
|
||||||
private val undoDeletion = View.OnClickListener {
|
private val undoDeletion = View.OnClickListener {
|
||||||
mSnackbar!!.dismiss()
|
mSnackbar!!.dismiss()
|
||||||
mIsSnackbarShown = false
|
|
||||||
mToBeDeleted.clear()
|
mToBeDeleted.clear()
|
||||||
getDirectories()
|
getDirectories()
|
||||||
}
|
}
|
||||||
|
@ -302,18 +297,16 @@ class MainActivity : SimpleActivity(), GetDirectoriesAsynctask.GetDirectoriesLis
|
||||||
itemClicked(it.path)
|
itemClicked(it.path)
|
||||||
}
|
}
|
||||||
directories_grid.adapter = adapter
|
directories_grid.adapter = adapter
|
||||||
directories_grid.setOnTouchListener(this)
|
directories_grid.setOnTouchListener { view, motionEvent -> checkDelete(); false }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun refreshItems() {
|
override fun refreshItems() {
|
||||||
getDirectories()
|
getDirectories()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTouch(v: View, event: MotionEvent): Boolean {
|
fun checkDelete() {
|
||||||
if (mIsSnackbarShown) {
|
if (mSnackbar?.isShown == true) {
|
||||||
deleteDirs()
|
deleteDirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import android.support.design.widget.Snackbar
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.MotionEvent
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.request.animation.GlideAnimation
|
import com.bumptech.glide.request.animation.GlideAnimation
|
||||||
|
@ -29,7 +28,7 @@ import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.MediaOperationsListener {
|
class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
companion object {
|
companion object {
|
||||||
private val TAG = MediaActivity::class.java.simpleName
|
private val TAG = MediaActivity::class.java.simpleName
|
||||||
|
|
||||||
|
@ -39,7 +38,6 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
|
||||||
lateinit var mMedia: ArrayList<Medium>
|
lateinit var mMedia: ArrayList<Medium>
|
||||||
|
|
||||||
private var mPath = ""
|
private var mPath = ""
|
||||||
private var mIsSnackbarShown = false
|
|
||||||
private var mIsGetImageIntent = false
|
private var mIsGetImageIntent = false
|
||||||
private var mIsGetVideoIntent = false
|
private var mIsGetVideoIntent = false
|
||||||
private var mIsGetAnyIntent = false
|
private var mIsGetAnyIntent = false
|
||||||
|
@ -90,8 +88,7 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
|
||||||
}
|
}
|
||||||
|
|
||||||
media_grid.adapter = adapter
|
media_grid.adapter = adapter
|
||||||
media_grid.setOnTouchListener(this)
|
media_grid.setOnTouchListener { view, motionEvent -> checkDelete(); false }
|
||||||
mIsSnackbarShown = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
@ -212,7 +209,6 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
|
||||||
setActionTextColor(Color.WHITE)
|
setActionTextColor(Color.WHITE)
|
||||||
show()
|
show()
|
||||||
}
|
}
|
||||||
mIsSnackbarShown = true
|
|
||||||
updateMediaView()
|
updateMediaView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,11 +217,7 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
|
||||||
if (mToBeDeleted.isEmpty())
|
if (mToBeDeleted.isEmpty())
|
||||||
return
|
return
|
||||||
|
|
||||||
if (mSnackbar != null) {
|
mSnackbar?.dismiss()
|
||||||
mSnackbar!!.dismiss()
|
|
||||||
}
|
|
||||||
|
|
||||||
mIsSnackbarShown = false
|
|
||||||
var wereFilesDeleted = false
|
var wereFilesDeleted = false
|
||||||
|
|
||||||
for (delPath in mToBeDeleted) {
|
for (delPath in mToBeDeleted) {
|
||||||
|
@ -262,7 +254,6 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
|
||||||
|
|
||||||
private val undoDeletion = View.OnClickListener {
|
private val undoDeletion = View.OnClickListener {
|
||||||
mSnackbar!!.dismiss()
|
mSnackbar!!.dismiss()
|
||||||
mIsSnackbarShown = false
|
|
||||||
mToBeDeleted.clear()
|
mToBeDeleted.clear()
|
||||||
updateMediaView()
|
updateMediaView()
|
||||||
}
|
}
|
||||||
|
@ -313,12 +304,10 @@ class MediaActivity : SimpleActivity(), View.OnTouchListener, MediaAdapter.Media
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTouch(v: View, event: MotionEvent): Boolean {
|
fun checkDelete() {
|
||||||
if (mIsSnackbarShown) {
|
if (mSnackbar?.isShown == true) {
|
||||||
deleteFiles()
|
deleteFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun refreshItems() {
|
override fun refreshItems() {
|
||||||
|
|
Loading…
Reference in a new issue