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 e6b75aecb..bc77f6923 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -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 { 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 88ed7b30b..e66a36236 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -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() private var mMedia = ArrayList() 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) { - 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) { + 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() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 390505321..58cef5980 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -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(), mShowAll) { + GetMediaAsynctask(applicationContext, mDirectory, false, false, mShowAll) { mMedia = it if (isDirEmpty()) return@GetMediaAsynctask diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index e1dc63988..8bc9f3aea 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -168,17 +168,17 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, 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(selections.size) - selections.forEach { paths.add(media[it].path) } - listener?.prepareForDeleting(paths) + val files = ArrayList(selections.size) + selections.forEach { files.add(File(media[it].path)) } + listener?.deleteFiles(files) } private fun getSelectedMedia(): List { @@ -265,6 +265,6 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, interface MediaOperationsListener { fun refreshItems() - fun prepareForDeleting(paths: ArrayList) + fun deleteFiles(files: ArrayList) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index 56fb7cf48..34401195e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -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 = ArrayList(), val showAll: Boolean, val callback: (media: ArrayList) -> Unit) : + val showAll: Boolean, val callback: (media: ArrayList) -> Unit) : AsyncTask>() { 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 { diff --git a/app/src/main/res/layout/activity_media.xml b/app/src/main/res/layout/activity_media.xml index 07fd16a4d..10a646e64 100644 --- a/app/src/main/res/layout/activity_media.xml +++ b/app/src/main/res/layout/activity_media.xml @@ -1,23 +1,17 @@ - + 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"/> - - - - + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 9603538f5..f0b579b30 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -55,11 +55,6 @@ %1$d Ordner gelöscht - - 1 Datei gelöscht - %1$d Dateien gelöscht - - Resize Resize selection and save diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 902df993c..ebb193eeb 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -55,11 +55,6 @@ %1$d carpetas eliminadas - - 1 archivo eliminado - %1$d archivos eliminados - - Resize Resize selection and save diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 731a6aa11..6bd3fa967 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -55,11 +55,6 @@ %1$d cartelle eliminate - - 1 file eliminato - %1$d file eliminati - - Resize Resize selection and save diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 7aa0308b6..06a5b514d 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -55,11 +55,6 @@ %1$d フォルダーを削除しました - - 1 ファイルを削除しました - %1$d ファイルを削除しました - - Resize Resize selection and save diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index f6d56f4f8..e6794082c 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -55,11 +55,6 @@ %1$d pastas apagadas - - 1 ficheiro apagado - %1$d ficheiros apagados - - Resize Resize selection and save diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index fdf41eedc..180d20a43 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -56,11 +56,6 @@ Папок удалено: %1$d - - 1 файл удалён - Файлов удалено: %1$d - - Изменить размер Изменить выбранное и сохранить diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index f463aa355..0f6928044 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -55,11 +55,6 @@ %1$d mappar borttagna - - 1 fil borttagen - %1$d filer borttagna - - Resize Resize selection and save diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index d23948606..2587fe83b 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -56,11 +56,6 @@ %1$d folders deleted - - 1 file deleted - %1$d files deleted - - Resize Resize selection and save diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f55d2e886..8b87a371e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -55,11 +55,6 @@ %1$d folders deleted - - 1 file deleted - %1$d files deleted - - Resize Resize selection and save