remove the Undo function from folder view

This commit is contained in:
tibbi 2017-01-07 12:22:25 +01:00
parent e9b40a6c13
commit 61a621fc3c
16 changed files with 25 additions and 163 deletions

View file

@ -4,16 +4,13 @@ import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.support.design.widget.Snackbar
import android.support.v4.app.ActivityCompat
import android.support.v7.widget.GridLayoutManager
import android.view.Menu
import android.view.MenuItem
import android.view.View
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.extensions.*
@ -39,9 +36,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private val PICK_MEDIA = 2
private val PICK_WALLPAPER = 3
private var mSnackbar: Snackbar? = null
lateinit var mDirs: ArrayList<Directory>
lateinit var mToBeDeleted: ArrayList<String>
private var mIsPickImageIntent = false
private var mIsPickVideoIntent = false
@ -66,7 +61,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
mIsThirdPartyIntent = mIsPickImageIntent || mIsPickVideoIntent || mIsGetImageContentIntent || mIsGetVideoContentIntent ||
mIsGetAnyContentIntent || mIsSetWallpaperIntent
mToBeDeleted = ArrayList<String>()
directories_holder.setOnRefreshListener({ getDirectories() })
mDirs = ArrayList<Directory>()
}
@ -98,7 +92,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
override fun onPause() {
super.onPause()
deleteDirs()
storeDirectories()
}
@ -143,7 +136,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
gotDirectories(dirs)
mIsGettingDirs = true
GetDirectoriesAsynctask(applicationContext, mIsPickVideoIntent || mIsGetVideoContentIntent, mIsPickImageIntent || mIsGetImageContentIntent, mToBeDeleted) {
GetDirectoriesAsynctask(applicationContext, mIsPickVideoIntent || mIsGetVideoContentIntent, mIsPickImageIntent || mIsGetImageContentIntent) {
gotDirectories(it)
}.execute()
}
@ -170,36 +163,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
}
}
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) {
val res = resources
val msg = res.getQuantityString(R.plurals.folders_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()
}
}
private fun deleteDirs() {
if (mToBeDeleted.isEmpty())
return
mSnackbar?.dismiss()
override fun deleteFiles(paths: ArrayList<String>) {
val updatedFiles = ArrayList<File>()
for (delPath in mToBeDeleted) {
for (delPath in paths) {
val dir = File(delPath)
if (dir.exists()) {
val files = dir.listFiles() ?: continue
@ -216,7 +182,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
}
scanFiles(updatedFiles) {}
mToBeDeleted.clear()
}
private fun deleteItem(file: File) {
@ -233,12 +198,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
}
}
private val undoDeletion = View.OnClickListener {
mSnackbar!!.dismiss()
mToBeDeleted.clear()
getDirectories()
}
private fun handleZooming() {
val layoutManager = directories_grid.layoutManager as GridLayoutManager
layoutManager.spanCount = config.dirColumnCnt
@ -350,19 +309,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
}
directories_grid.adapter = adapter
directories_grid.setOnTouchListener { view, motionEvent -> checkDelete(); false }
}
override fun refreshItems() {
getDirectories()
}
fun checkDelete() {
if (mSnackbar?.isShown == true) {
deleteDirs()
}
}
private fun checkWhatsNewDialog() {
arrayListOf<Release>().apply {
add(Release(46, R.string.release_46))

View file

@ -231,11 +231,13 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
private fun askConfirmDelete() {
ConfirmationDialog(activity) {
actMode?.finish()
prepareForDeleting()
Thread({
deleteFiles()
}).start()
}
}
private fun prepareForDeleting() {
private fun deleteFiles() {
val selections = multiSelector.selectedPositions
val paths = ArrayList<String>(selections.size)
val removeDirs = ArrayList<Directory>(selections.size)
@ -245,11 +247,13 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
val directory = dirs[it]
paths.add(directory.path)
removeDirs.add(directory)
activity.runOnUiThread {
notifyItemRemoved(it)
}
}
dirs.removeAll(removeDirs)
listener?.prepareForDeleting(paths)
listener?.deleteFiles(paths)
}
private fun getSelectedPaths(): HashSet<String> {
@ -333,6 +337,6 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
interface DirOperationsListener {
fun refreshItems()
fun prepareForDeleting(paths: ArrayList<String>)
fun deleteFiles(paths: ArrayList<String>)
}
}

View file

@ -16,7 +16,7 @@ import java.io.File
import java.util.*
class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, val isPickImage: Boolean,
val mToBeDeleted: List<String>, val callback: (dirs: ArrayList<Directory>) -> Unit) : AsyncTask<Void, Void, ArrayList<Directory>>() {
val callback: (dirs: ArrayList<Directory>) -> Unit) : AsyncTask<Void, Void, ArrayList<Directory>>() {
lateinit var mConfig: Config
override fun onPreExecute() {
@ -80,7 +80,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
val newImageCnt = directory.mediaCnt + 1
directory.mediaCnt = newImageCnt
directory.addSize(size)
} else if (!mToBeDeleted.contains(parentDir)) {
} else {
var dirName = context.getHumanizedFilename(parentDir)
if (mConfig.getIsFolderHidden(parentDir)) {
dirName += " ${context.resources.getString(R.string.hidden)}"

View file

@ -12,7 +12,6 @@ import com.simplemobiletools.gallery.adapters.DirectoryAdapter
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
import com.simplemobiletools.gallery.helpers.Config
import kotlinx.android.synthetic.main.dialog_album_picker.view.*
import java.util.*
class PickAlbumDialog(val activity: SimpleActivity, val callback: (path: String) -> Unit) {
var directoriesGrid: RecyclerView
@ -28,7 +27,7 @@ class PickAlbumDialog(val activity: SimpleActivity, val callback: (path: String)
.create().apply {
activity.setupDialogStuff(view, this, R.string.select_destination)
GetDirectoriesAsynctask(activity, false, false, ArrayList<String>()) {
GetDirectoriesAsynctask(activity, false, false) {
val adapter = DirectoryAdapter(activity, it, null) {
callback.invoke(it.path)
dismiss()

View file

@ -1,15 +1,10 @@
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/directories_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent">
<com.simplemobiletools.gallery.views.MyScalableRecyclerView
android:id="@+id/directories_grid"
@ -19,5 +14,4 @@
app:layoutManager="android.support.v7.widget.GridLayoutManager"
app:spanCount="@integer/directory_columns"/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>

View file

@ -4,10 +4,7 @@
<string name="app_launcher_name">Galerie</string>
<string name="share_via">Teilen via</string>
<string name="no_permissions">Ohne Zugriff auf deinen Speicher gibt es hier nicht viel zu tun</string>
<string name="deleting">Lösche</string>
<string name="edit">Bearbeiten</string>
<string name="undo">Rückgängig</string>
<string name="file_deleted">Datei gelöscht</string>
<string name="open_camera">Kamera öffnen</string>
<string name="unknown_error">Ein unbekannter Fehler ist aufgetreten</string>
<string name="open_with">Öffnen mit</string>
@ -24,11 +21,6 @@
<string name="folder_view">wechsle zu Ordner Ansicht</string>
<string name="other_folder">Other folder</string>
<plurals name="folders_deleted">
<item quantity="one">1 Ordner gelöscht</item>
<item quantity="other">%1$d Ordner gelöscht</item>
</plurals>
<!-- Resizing -->
<string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string>

View file

@ -4,10 +4,7 @@
<string name="app_launcher_name">Gallery</string>
<string name="share_via">Compartir vía</string>
<string name="no_permissions">No hay mucho que hacer en una galería sin acceso al almacenamiento</string>
<string name="deleting">Eliminando</string>
<string name="edit">Edit</string>
<string name="undo">Deshacer</string>
<string name="file_deleted">Archivo eliminado</string>
<string name="open_camera">Abrir cámara</string>
<string name="unknown_error">Ocurrió un error desconocido</string>
<string name="open_with">Abrir con&#8230;</string>
@ -24,11 +21,6 @@
<string name="folder_view">Switch to folder view</string>
<string name="other_folder">Other folder</string>
<plurals name="folders_deleted">
<item quantity="one">1 carpeta eliminada</item>
<item quantity="other">%1$d carpetas eliminadas</item>
</plurals>
<!-- Resizing -->
<string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string>

View file

@ -4,10 +4,7 @@
<string name="app_launcher_name">Galerie</string>
<string name="share_via">Partager via</string>
<string name="no_permissions">Peu de choses à faire dans l\'album sans accès à la mémoire</string>
<string name="deleting">Suppression</string>
<string name="edit">Édition</string>
<string name="undo">Annuler</string>
<string name="file_deleted">Fichier supprimé</string>
<string name="open_camera">Ouvrir caméra</string>
<string name="unknown_error">Une erreur inconnue est survenue.</string>
<string name="open_with">Ouvrir avec</string>
@ -24,11 +21,6 @@
<string name="folder_view">Permuter vers la vue du dossier</string>
<string name="other_folder">Autre dossier</string>
<plurals name="folders_deleted">
<item quantity="one">1 dossier supprimé</item>
<item quantity="other">%1$d dossiers supprimés</item>
</plurals>
<!-- Resizing -->
<string name="resize">Redimensionner</string>
<string name="resize_and_save">Redimensionner la sélection et enregistrer</string>

View file

@ -4,10 +4,7 @@
<string name="app_launcher_name">Galleria</string>
<string name="share_via">Condividi via</string>
<string name="no_permissions">Non c\'è molto da fare in una galleria senza l\'accesso all\'archiviazione</string>
<string name="deleting">Eliminazione</string>
<string name="edit">Modifica</string>
<string name="undo">Annulla</string>
<string name="file_deleted">File eliminato</string>
<string name="open_camera">Apri fotocamera</string>
<string name="unknown_error">Riscontrato un errore sconosciuto</string>
<string name="open_with">Apri con</string>
@ -24,11 +21,6 @@
<string name="folder_view">Switch to folder view</string>
<string name="other_folder">Other folder</string>
<plurals name="folders_deleted">
<item quantity="one">1 cartella eliminata</item>
<item quantity="other">%1$d cartelle eliminate</item>
</plurals>
<!-- Resizing -->
<string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string>

View file

@ -4,10 +4,7 @@
<string name="app_launcher_name">ギャラリー</string>
<string name="share_via">共有&#8230;</string>
<string name="no_permissions">ストレージにアクセスしないとギャラリーでできることはほとんどありません</string>
<string name="deleting">削除中</string>
<string name="edit">編集</string>
<string name="undo">元に戻す</string>
<string name="file_deleted">ファイルを削除しました</string>
<string name="open_camera">カメラを開く</string>
<string name="unknown_error">不明なエラーが発生しました</string>
<string name="open_with">&#8230;で開く</string>
@ -24,11 +21,6 @@
<string name="folder_view">Switch to folder view</string>
<string name="other_folder">Other folder</string>
<plurals name="folders_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

@ -1,12 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Simple Gallery</string>
<string name="app_launcher_name">Galeria</string>
<string name="share_via">Partilhar via</string>
<string name="no_permissions">É necessário o acesso ao armazenamento para a galeria ter utilidade</string>
<string name="deleting">A apagar</string>
<string name="edit">Editar</string>
<string name="undo">Desfazer</string>
<string name="file_deleted">Ficheiro apagado</string>
<string name="open_camera">Abrir câmara</string>
<string name="unknown_error">Ocorreu um erro desconhecido</string>
<string name="open_with">Abrir com</string>
@ -23,11 +21,6 @@
<string name="folder_view">Alternar para a vista de pastas</string>
<string name="other_folder">Outra pasta</string>
<plurals name="folders_deleted">
<item quantity="one">1 pasta apagada</item>
<item quantity="other">%1$d pastas apagadas</item>
</plurals>
<!-- Resizing -->
<string name="resize">Redimensionar</string>
<string name="resize_and_save">Redimensionar seleção e guardar</string>

View file

@ -4,10 +4,7 @@
<string name="app_launcher_name">Галерея</string>
<string name="share_via">Отправить по</string>
<string name="no_permissions">Не предоставлено разрешение для доступа к файловой системе</string>
<string name="deleting">Удаление</string>
<string name="edit">Редактировать</string>
<string name="undo">Отменить</string>
<string name="file_deleted">Файл удален</string>
<string name="open_camera">Открыть камеру</string>
<string name="unknown_error">Произошла неизвестная ошибка</string>
<string name="open_with">Открыть в</string>
@ -24,11 +21,6 @@
<string name="folder_view">Переключиться к виду с папками</string>
<string name="other_folder">Другая папка</string>
<plurals name="folders_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

@ -4,10 +4,7 @@
<string name="app_launcher_name">Gallery</string>
<string name="share_via">Dela via</string>
<string name="no_permissions">Inte mycket att göra i ett galleri om jag inte kommer åt lagringsutrymmet</string>
<string name="deleting">Tar bort</string>
<string name="edit">Edit</string>
<string name="undo">Ångra</string>
<string name="file_deleted">Fil borttagen</string>
<string name="open_camera">Starta kameran</string>
<string name="unknown_error">Ett okänt fel har uppstått</string>
<string name="open_with">Open with</string>
@ -24,11 +21,6 @@
<string name="folder_view">Switch to folder view</string>
<string name="other_folder">Другая папка</string>
<plurals name="folders_deleted">
<item quantity="one">1 mapp borttagen</item>
<item quantity="other">%1$d mappar borttagna</item>
</plurals>
<!-- Resizing -->
<string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string>

View file

@ -4,10 +4,7 @@
<string name="app_launcher_name">相册</string>
<string name="share_via">分享到</string>
<string name="no_permissions">需要访问储存权限</string>
<string name="deleting">删除中</string>
<string name="edit">编辑</string>
<string name="undo">撤销</string>
<string name="file_deleted">文件删除成功</string>
<string name="open_camera">打开相机</string>
<string name="unknown_error">未知错误</string>
<string name="open_with">打开方式</string>
@ -24,11 +21,6 @@
<string name="folder_view">切换到文件夹视图</string>
<string name="other_folder">其他文件夹</string>
<plurals name="folders_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

@ -4,10 +4,7 @@
<string name="app_launcher_name">藝廊</string>
<string name="share_via">分享到</string>
<string name="no_permissions">一個沒有權限存取您的儲存空間的藝廊能做的事情寥寥無幾</string>
<string name="deleting">正在刪除</string>
<string name="edit">編輯</string>
<string name="undo">復原</string>
<string name="file_deleted">檔案成功刪除</string>
<string name="open_camera">開啟相機</string>
<string name="unknown_error">未知錯誤</string>
<string name="open_with">以其他應用軟體開啟</string>
@ -24,11 +21,6 @@
<string name="folder_view">切換到資料夾檢視</string>
<string name="other_folder">其他資料夾</string>
<plurals name="folders_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

@ -4,10 +4,7 @@
<string name="app_launcher_name">Gallery</string>
<string name="share_via">Share via</string>
<string name="no_permissions">Not much to do in a gallery without accessing your storage</string>
<string name="deleting">Deleting</string>
<string name="edit">Edit</string>
<string name="undo">Undo</string>
<string name="file_deleted">File deleted</string>
<string name="open_camera">Open camera</string>
<string name="unknown_error">An unknown error occurred</string>
<string name="open_with">Open with</string>
@ -24,11 +21,6 @@
<string name="folder_view">Switch to folder view</string>
<string name="other_folder">Other folder</string>
<plurals name="folders_deleted">
<item quantity="one">1 folder deleted</item>
<item quantity="other">%1$d folders deleted</item>
</plurals>
<!-- Resizing -->
<string name="resize">Resize</string>
<string name="resize_and_save">Resize selection and save</string>