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 {
file.delete()
}
if (file.exists()) {
try {
file.delete()
} catch (ignored: Exception) {
}
}
}
private val undoDeletion = View.OnClickListener {

View file

@ -4,14 +4,11 @@ import android.app.Activity
import android.app.WallpaperManager
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import android.support.design.widget.Snackbar
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.request.animation.GlideAnimation
import com.bumptech.glide.request.target.SimpleTarget
@ -32,9 +29,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
companion object {
private val TAG = MediaActivity::class.java.simpleName
private var mSnackbar: Snackbar? = null
private var mToBeDeleted = ArrayList<String>()
private var mMedia = ArrayList<Medium>()
private var mPath = ""
@ -67,11 +61,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
tryloadGallery()
}
override fun onPause() {
super.onPause()
deleteFiles()
}
private fun tryloadGallery() {
if (hasStoragePermission()) {
val dirName = getHumanizedFilename(mPath)
@ -96,7 +85,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} else {
media_grid.adapter = adapter
}
media_grid.setOnTouchListener { view, motionEvent -> checkDelete(); false }
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
@ -196,7 +184,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
return
mIsGettingMedia = true
GetMediaAsynctask(applicationContext, mPath, mIsGetVideoIntent, mIsGetImageIntent, mToBeDeleted, mShowAll) {
GetMediaAsynctask(applicationContext, mPath, mIsGetVideoIntent, mIsGetImageIntent, mShowAll) {
gotMedia(it)
}.execute()
}
@ -210,44 +198,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
false
}
override fun prepareForDeleting(paths: ArrayList<String>) {
toast(R.string.deleting)
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)
override fun deleteFiles(files: ArrayList<File>) {
for (file in files) {
if (file.exists() && file.isImageVideoGif()) {
if (needsStupidWritePermissions(file.absolutePath)) {
if (isShowingPermDialog(file))
@ -257,38 +209,20 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
// 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.delete()) {
wereFilesDeleted = true
}
document.delete()
}
} else {
if (file.delete())
wereFilesDeleted = true
}
if (file.exists()) {
try {
file.delete()
} catch (ignored: Exception) {
}
file.delete()
}
}
}
if (wereFilesDeleted) {
scanPaths(mToBeDeleted) {
if (mMedia.isEmpty()) {
finish()
}
scanFiles(files) {
if (mMedia.isEmpty()) {
finish()
}
updateMediaView()
}
mToBeDeleted.clear()
}
private val undoDeletion = View.OnClickListener {
mSnackbar!!.dismiss()
mToBeDeleted.clear()
updateMediaView()
}
private fun updateMediaView() {
@ -349,12 +283,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
initializeGallery()
}
fun checkDelete() {
if (mSnackbar?.isShown == true) {
deleteFiles()
}
}
override fun refreshItems() {
getMedia()
}

View file

@ -213,13 +213,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
file.delete()
}
try {
if (file.exists())
file.delete()
} catch (ignored: Exception) {
}
val values = ContentValues()
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
@ -251,7 +244,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
private fun reloadViewPager() {
GetMediaAsynctask(applicationContext, mDirectory, false, false, ArrayList<String>(), mShowAll) {
GetMediaAsynctask(applicationContext, mDirectory, false, false, mShowAll) {
mMedia = it
if (isDirEmpty())
return@GetMediaAsynctask

View file

@ -168,17 +168,17 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
private fun askConfirmDelete() {
ConfirmationDialog(activity) {
actMode?.finish()
prepareForDeleting()
deleteFiles()
}
}
private fun getCurrentFile() = File(media[multiSelector.selectedPositions[0]].path)
private fun prepareForDeleting() {
private fun deleteFiles() {
val selections = multiSelector.selectedPositions
val paths = ArrayList<String>(selections.size)
selections.forEach { paths.add(media[it].path) }
listener?.prepareForDeleting(paths)
val files = ArrayList<File>(selections.size)
selections.forEach { files.add(File(media[it].path)) }
listener?.deleteFiles(files)
}
private fun getSelectedMedia(): List<Medium> {
@ -265,6 +265,6 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
interface MediaOperationsListener {
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.*
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>>() {
lateinit var mConfig: Config
@ -49,24 +49,22 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
if (cursor?.moveToFirst() == true) {
do {
val curPath = cursor.getStringValue(MediaStore.Images.Media.DATA) ?: continue
if (!mToBeDeleted.contains(curPath)) {
val file = File(curPath)
val size = cursor.getLongValue(MediaStore.Images.Media.SIZE)
val file = File(curPath)
val size = cursor.getLongValue(MediaStore.Images.Media.SIZE)
if (size == 0L) {
invalidFiles.add(file)
continue
}
// exclude images of subdirectories
if (!showAll && file.parent != mPath)
continue
val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: ""
val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED)
val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
media.add(Medium(name, curPath, i == 1, dateModified, dateTaken, size))
if (size == 0L) {
invalidFiles.add(file)
continue
}
// exclude images of subdirectories
if (!showAll && file.parent != mPath)
continue
val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: ""
val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED)
val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
media.add(Medium(name, curPath, i == 1, dateModified, dateTaken, size))
} while (cursor.moveToNext())
}
} finally {

View file

@ -1,23 +1,17 @@
<?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:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:id="@+id/media_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/media_holder"
<android.support.v7.widget.RecyclerView
android:id="@+id/media_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layoutManager="android.support.v7.widget.GridLayoutManager"
app:spanCount="@integer/photo_columns"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/media_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layoutManager="android.support.v7.widget.GridLayoutManager"
app:spanCount="@integer/photo_columns"/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>

View file

@ -55,11 +55,6 @@
<item quantity="other">%1$d Ordner gelöscht</item>
</plurals>
<plurals name="files_deleted">
<item quantity="one">1 Datei gelöscht</item>
<item quantity="other">%1$d Dateien gelöscht</item>
</plurals>
<!-- Resizing -->
<string name="resize">Resize</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>
</plurals>
<plurals name="files_deleted">
<item quantity="one">1 archivo eliminado</item>
<item quantity="other">%1$d archivos eliminados</item>
</plurals>
<!-- Resizing -->
<string name="resize">Resize</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>
</plurals>
<plurals name="files_deleted">
<item quantity="one">1 file eliminato</item>
<item quantity="other">%1$d file eliminati</item>
</plurals>
<!-- Resizing -->
<string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string>

View file

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

View file

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

View file

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