remove the Undo option at removing from media view

This commit is contained in:
tibbi 2016-12-07 20:36:42 +01:00
parent 62d11861ca
commit b28f7dcc78
15 changed files with 41 additions and 180 deletions

View file

@ -224,13 +224,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
} else { } else {
file.delete() file.delete()
} }
if (file.exists()) {
try {
file.delete()
} catch (ignored: Exception) {
}
}
} }
private val undoDeletion = View.OnClickListener { private val undoDeletion = View.OnClickListener {

View file

@ -4,14 +4,11 @@ import android.app.Activity
import android.app.WallpaperManager import android.app.WallpaperManager
import android.content.Intent import android.content.Intent
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Color
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
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.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
import com.bumptech.glide.request.target.SimpleTarget import com.bumptech.glide.request.target.SimpleTarget
@ -32,9 +29,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
companion object { companion object {
private val TAG = MediaActivity::class.java.simpleName private val TAG = MediaActivity::class.java.simpleName
private var mSnackbar: Snackbar? = null
private var mToBeDeleted = ArrayList<String>()
private var mMedia = ArrayList<Medium>() private var mMedia = ArrayList<Medium>()
private var mPath = "" private var mPath = ""
@ -67,11 +61,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
tryloadGallery() tryloadGallery()
} }
override fun onPause() {
super.onPause()
deleteFiles()
}
private fun tryloadGallery() { private fun tryloadGallery() {
if (hasStoragePermission()) { if (hasStoragePermission()) {
val dirName = getHumanizedFilename(mPath) val dirName = getHumanizedFilename(mPath)
@ -96,7 +85,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} else { } else {
media_grid.adapter = adapter media_grid.adapter = adapter
} }
media_grid.setOnTouchListener { view, motionEvent -> checkDelete(); false }
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
@ -196,7 +184,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
return return
mIsGettingMedia = true mIsGettingMedia = true
GetMediaAsynctask(applicationContext, mPath, mIsGetVideoIntent, mIsGetImageIntent, mToBeDeleted, mShowAll) { GetMediaAsynctask(applicationContext, mPath, mIsGetVideoIntent, mIsGetImageIntent, mShowAll) {
gotMedia(it) gotMedia(it)
}.execute() }.execute()
} }
@ -210,44 +198,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
false false
} }
override fun prepareForDeleting(paths: ArrayList<String>) { override fun deleteFiles(files: ArrayList<File>) {
toast(R.string.deleting) for (file in files) {
mToBeDeleted = paths
val deletedCnt = mToBeDeleted.size
if (isShowingPermDialog(File(mToBeDeleted[0])))
return
notifyDeletion(deletedCnt)
}
private fun notifyDeletion(cnt: Int) {
getMedia()
if (mMedia.isEmpty()) {
deleteFiles()
} else {
val res = resources
val msg = res.getQuantityString(R.plurals.files_deleted, cnt, cnt)
mSnackbar = Snackbar.make(coordinator_layout, msg, Snackbar.LENGTH_INDEFINITE)
mSnackbar!!.apply {
setAction(res.getString(R.string.undo), undoDeletion)
setActionTextColor(Color.WHITE)
show()
}
updateMediaView()
}
}
private fun deleteFiles() {
if (mToBeDeleted.isEmpty())
return
mSnackbar?.dismiss()
var wereFilesDeleted = false
for (delPath in mToBeDeleted) {
val file = File(delPath)
if (file.exists() && file.isImageVideoGif()) { if (file.exists() && file.isImageVideoGif()) {
if (needsStupidWritePermissions(file.absolutePath)) { if (needsStupidWritePermissions(file.absolutePath)) {
if (isShowingPermDialog(file)) if (isShowingPermDialog(file))
@ -257,39 +209,21 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
// double check we have the uri to the proper file path, not some parent folder // double check we have the uri to the proper file path, not some parent folder
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory) { if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory) {
if (document.delete()) { document.delete()
wereFilesDeleted = true
}
} }
} else { } else {
if (file.delete())
wereFilesDeleted = true
}
if (file.exists()) {
try {
file.delete() file.delete()
} catch (ignored: Exception) {
}
} }
} }
} }
if (wereFilesDeleted) { scanFiles(files) {
scanPaths(mToBeDeleted) {
if (mMedia.isEmpty()) { if (mMedia.isEmpty()) {
finish() finish()
} }
}
}
mToBeDeleted.clear()
}
private val undoDeletion = View.OnClickListener {
mSnackbar!!.dismiss()
mToBeDeleted.clear()
updateMediaView() updateMediaView()
} }
}
private fun updateMediaView() { private fun updateMediaView() {
if (!isDirEmpty()) { if (!isDirEmpty()) {
@ -349,12 +283,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
initializeGallery() initializeGallery()
} }
fun checkDelete() {
if (mSnackbar?.isShown == true) {
deleteFiles()
}
}
override fun refreshItems() { override fun refreshItems() {
getMedia() getMedia()
} }

View file

@ -213,13 +213,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
file.delete() file.delete()
} }
try {
if (file.exists())
file.delete()
} catch (ignored: Exception) {
}
val values = ContentValues() val values = ContentValues()
values.put(MediaStore.MediaColumns.DATA, file.absolutePath) values.put(MediaStore.MediaColumns.DATA, file.absolutePath)
val uri = if (file.isImageSlow()) MediaStore.Images.Media.EXTERNAL_CONTENT_URI else MediaStore.Video.Media.EXTERNAL_CONTENT_URI val uri = if (file.isImageSlow()) MediaStore.Images.Media.EXTERNAL_CONTENT_URI else MediaStore.Video.Media.EXTERNAL_CONTENT_URI
@ -251,7 +244,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
private fun reloadViewPager() { private fun reloadViewPager() {
GetMediaAsynctask(applicationContext, mDirectory, false, false, ArrayList<String>(), mShowAll) { GetMediaAsynctask(applicationContext, mDirectory, false, false, mShowAll) {
mMedia = it mMedia = it
if (isDirEmpty()) if (isDirEmpty())
return@GetMediaAsynctask return@GetMediaAsynctask

View file

@ -168,17 +168,17 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
private fun askConfirmDelete() { private fun askConfirmDelete() {
ConfirmationDialog(activity) { ConfirmationDialog(activity) {
actMode?.finish() actMode?.finish()
prepareForDeleting() deleteFiles()
} }
} }
private fun getCurrentFile() = File(media[multiSelector.selectedPositions[0]].path) private fun getCurrentFile() = File(media[multiSelector.selectedPositions[0]].path)
private fun prepareForDeleting() { private fun deleteFiles() {
val selections = multiSelector.selectedPositions val selections = multiSelector.selectedPositions
val paths = ArrayList<String>(selections.size) val files = ArrayList<File>(selections.size)
selections.forEach { paths.add(media[it].path) } selections.forEach { files.add(File(media[it].path)) }
listener?.prepareForDeleting(paths) listener?.deleteFiles(files)
} }
private fun getSelectedMedia(): List<Medium> { private fun getSelectedMedia(): List<Medium> {
@ -265,6 +265,6 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
interface MediaOperationsListener { interface MediaOperationsListener {
fun refreshItems() fun refreshItems()
fun prepareForDeleting(paths: ArrayList<String>) fun deleteFiles(files: ArrayList<File>)
} }
} }

View file

@ -13,7 +13,7 @@ import java.io.File
import java.util.* import java.util.*
class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo: Boolean = false, val isPickImage: Boolean = false, class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo: Boolean = false, val isPickImage: Boolean = false,
val mToBeDeleted: List<String> = ArrayList<String>(), val showAll: Boolean, val callback: (media: ArrayList<Medium>) -> Unit) : val showAll: Boolean, val callback: (media: ArrayList<Medium>) -> Unit) :
AsyncTask<Void, Void, ArrayList<Medium>>() { AsyncTask<Void, Void, ArrayList<Medium>>() {
lateinit var mConfig: Config lateinit var mConfig: Config
@ -49,7 +49,6 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
if (cursor?.moveToFirst() == true) { if (cursor?.moveToFirst() == true) {
do { do {
val curPath = cursor.getStringValue(MediaStore.Images.Media.DATA) ?: continue val curPath = cursor.getStringValue(MediaStore.Images.Media.DATA) ?: continue
if (!mToBeDeleted.contains(curPath)) {
val file = File(curPath) val file = File(curPath)
val size = cursor.getLongValue(MediaStore.Images.Media.SIZE) val size = cursor.getLongValue(MediaStore.Images.Media.SIZE)
@ -66,7 +65,6 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED)
val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN) val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
media.add(Medium(name, curPath, i == 1, dateModified, dateTaken, size)) media.add(Medium(name, curPath, i == 1, dateModified, dateTaken, size))
}
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }
} finally { } finally {

View file

@ -1,12 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout <android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/media_holder" android:id="@+id/media_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -20,4 +15,3 @@
app:spanCount="@integer/photo_columns"/> app:spanCount="@integer/photo_columns"/>
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>

View file

@ -55,11 +55,6 @@
<item quantity="other">%1$d Ordner gelöscht</item> <item quantity="other">%1$d Ordner gelöscht</item>
</plurals> </plurals>
<plurals name="files_deleted">
<item quantity="one">1 Datei gelöscht</item>
<item quantity="other">%1$d Dateien gelöscht</item>
</plurals>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string> <string name="resize_and_save">Resize selection and save</string>

View file

@ -55,11 +55,6 @@
<item quantity="other">%1$d carpetas eliminadas</item> <item quantity="other">%1$d carpetas eliminadas</item>
</plurals> </plurals>
<plurals name="files_deleted">
<item quantity="one">1 archivo eliminado</item>
<item quantity="other">%1$d archivos eliminados</item>
</plurals>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string> <string name="resize_and_save">Resize selection and save</string>

View file

@ -55,11 +55,6 @@
<item quantity="other">%1$d cartelle eliminate</item> <item quantity="other">%1$d cartelle eliminate</item>
</plurals> </plurals>
<plurals name="files_deleted">
<item quantity="one">1 file eliminato</item>
<item quantity="other">%1$d file eliminati</item>
</plurals>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string> <string name="resize_and_save">Resize selection and save</string>

View file

@ -55,11 +55,6 @@
<item quantity="other">%1$d フォルダーを削除しました</item> <item quantity="other">%1$d フォルダーを削除しました</item>
</plurals> </plurals>
<plurals name="files_deleted">
<item quantity="one">1 ファイルを削除しました</item>
<item quantity="other">%1$d ファイルを削除しました</item>
</plurals>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string> <string name="resize_and_save">Resize selection and save</string>

View file

@ -55,11 +55,6 @@
<item quantity="other">%1$d pastas apagadas</item> <item quantity="other">%1$d pastas apagadas</item>
</plurals> </plurals>
<plurals name="files_deleted">
<item quantity="one">1 ficheiro apagado</item>
<item quantity="other">%1$d ficheiros apagados</item>
</plurals>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string> <string name="resize_and_save">Resize selection and save</string>

View file

@ -56,11 +56,6 @@
<item quantity="other">Папок удалено: %1$d</item> <item quantity="other">Папок удалено: %1$d</item>
</plurals> </plurals>
<plurals name="files_deleted">
<item quantity="one">1 файл удалён</item>
<item quantity="other">Файлов удалено: %1$d</item>
</plurals>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Изменить размер</string> <string name="resize">Изменить размер</string>
<string name="resize_and_save">Изменить выбранное и сохранить</string> <string name="resize_and_save">Изменить выбранное и сохранить</string>

View file

@ -55,11 +55,6 @@
<item quantity="other">%1$d mappar borttagna</item> <item quantity="other">%1$d mappar borttagna</item>
</plurals> </plurals>
<plurals name="files_deleted">
<item quantity="one">1 fil borttagen</item>
<item quantity="other">%1$d filer borttagna</item>
</plurals>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string> <string name="resize_and_save">Resize selection and save</string>

View file

@ -56,11 +56,6 @@
<item quantity="other">%1$d folders deleted</item> <item quantity="other">%1$d folders deleted</item>
</plurals> </plurals>
<plurals name="files_deleted">
<item quantity="one">1 file deleted</item>
<item quantity="other">%1$d files deleted</item>
</plurals>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string> <string name="resize_and_save">Resize selection and save</string>

View file

@ -55,11 +55,6 @@
<item quantity="other">%1$d folders deleted</item> <item quantity="other">%1$d folders deleted</item>
</plurals> </plurals>
<plurals name="files_deleted">
<item quantity="one">1 file deleted</item>
<item quantity="other">%1$d files deleted</item>
</plurals>
<!-- Resizing --> <!-- Resizing -->
<string name="resize">Resize</string> <string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string> <string name="resize_and_save">Resize selection and save</string>