diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index 14d54554..aa625dcb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -14,6 +14,7 @@ import com.simplemobiletools.filemanager.Config import com.simplemobiletools.filemanager.R import com.simplemobiletools.filemanager.activities.SimpleActivity import com.simplemobiletools.filemanager.dialogs.RenameItemDialog +import com.simplemobiletools.filepicker.dialogs.ConfirmationDialog import com.simplemobiletools.filepicker.extensions.formatSize import com.simplemobiletools.filepicker.extensions.isGif import com.simplemobiletools.filepicker.extensions.toast @@ -60,6 +61,10 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List, shareFiles() true } + R.id.cab_delete -> { + askConfirmDelete() + true + } else -> false } } @@ -125,6 +130,23 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List, } } + private fun askConfirmDelete() { + ConfirmationDialog(activity, listener = object : ConfirmationDialog.OnConfirmedListener { + override fun onConfirmed() { + actMode?.finish() + prepareForDeleting() + } + }) + } + + private fun prepareForDeleting() { + val selections = multiSelector.selectedPositions + val paths = ArrayList(selections.size) + selections.forEach { paths.add(mItems[it].path) } + listener?.prepareForDeleting(paths) + } + + private fun getSelectedMedia(): List { val positions = multiSelector.selectedPositions val selectedMedia = ArrayList(positions.size) @@ -199,5 +221,7 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List, interface ItemOperationsListener { fun refreshItems() + + fun prepareForDeleting(paths: ArrayList) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt index ea0698cc..7e1b9df3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt @@ -7,11 +7,9 @@ import android.net.Uri import android.os.Bundle import android.support.design.widget.Snackbar import android.view.LayoutInflater -import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.webkit.MimeTypeMap -import android.widget.AdapterView import com.simplemobiletools.filemanager.Config import com.simplemobiletools.filemanager.PATH import com.simplemobiletools.filemanager.R @@ -27,7 +25,7 @@ import kotlinx.android.synthetic.main.items_fragment.* import java.io.File import java.util.* -class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClickListener, ItemsAdapter.ItemOperationsListener, View.OnTouchListener { +class ItemsFragment : android.support.v4.app.Fragment(), ItemsAdapter.ItemOperationsListener { private var mListener: ItemInteractionListener? = null private var mSnackbar: Snackbar? = null @@ -78,11 +76,11 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick mItems = newItems val adapter = ItemsAdapter(activity as SimpleActivity, mItems, this) { - + itemClicked(it) } items_list.adapter = adapter items_list.addItemDecoration(RecyclerViewDivider(context)) - items_list.setOnTouchListener(this) + items_list.setOnTouchListener { view, motionEvent -> checkDelete(); true } } fun setListener(listener: ItemInteractionListener) { @@ -125,8 +123,7 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick return 0 } - override fun onItemClick(parent: AdapterView<*>, view: View, position: Int, id: Long) { - val item = mItems[position] + fun itemClicked(item: FileDirItem) { if (item.isDirectory) { mListener?.itemClicked(item) } else { @@ -177,26 +174,12 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick return type + "/*" } - /*override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { - val menuItem = menu.findItem(R.id.cab_rename) - menuItem.isVisible = mSelectedItemsCnt == 1 - return true - } - - override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { + /*override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { when (item.itemId) { - R.id.cab_rename -> { - displayRenameDialog() - mode.finish() - } R.id.cab_copy -> { displayCopyDialog() mode.finish() } - R.id.cab_delete -> { - prepareForDeleting() - mode.finish() - } else -> return false } @@ -227,15 +210,6 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick }) } - private fun getSelectedItem(): FileDirItem? { - val itemIndexes = getSelectedItemIndexes() - if (itemIndexes.isEmpty()) - return null - - val itemIndex = itemIndexes[0] - return mItems[itemIndex] - } - private fun getSelectedItemIndexes(): List { /*val items = items_list.checkedItemPositions val cnt = items.size() @@ -246,21 +220,15 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick return ArrayList() } - private fun prepareForDeleting() { - mToBeDeleted.clear() - /*val items = items_list.checkedItemPositions - val cnt = items.size() - var deletedCnt = 0 - for (i in 0..cnt - 1) { - if (items.valueAt(i)) { - val id = items.keyAt(i) - val path = mItems[id].path - mToBeDeleted.add(path) - deletedCnt++ - } - } + override fun prepareForDeleting(paths: ArrayList) { + activity.toast(R.string.deleting) + mToBeDeleted = paths + val deletedCnt = mToBeDeleted.size - notifyDeletion(deletedCnt)*/ + if ((activity as SimpleActivity).isShowingPermDialog(File(mToBeDeleted[0]))) + return + + notifyDeletion(deletedCnt) } private fun notifyDeletion(cnt: Int) { @@ -275,12 +243,10 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick fillItems() } - override fun onTouch(v: View, event: MotionEvent): Boolean { - if (mSnackbar != null && mSnackbar!!.isShown) { + fun checkDelete() { + if (mSnackbar?.isShown == true) { deleteItems() } - - return false } private fun deleteItems() { diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 7d2b61cc..66c8d68d 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -13,6 +13,7 @@ Please enter a name Ein unbekannter Fehler ist aufgetreten Löschen + Lösche Rückgängig Umbenennen Eigenschaften diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index c7164d8a..5f8b405e 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -13,6 +13,7 @@ Por favor, introduce un nombre Se ha producido un error inesperado Eliminar + Eliminando Deshacer Renombrar Propiedades diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 8ddf3fee..edd7d1d6 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -13,6 +13,7 @@ Inserisci un nome Riscontrato un errore sconosciuto Elimina + Eliminazione Annulla Rinomina Proprietà diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 5ce44862..1a321908 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -13,6 +13,7 @@ Please enter a name 不明なエラーが発生しました 削除 + 削除中 元に戻す 名前を変更 Properties diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 561dbe83..117a53cd 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -13,6 +13,7 @@ Por favor digite o nome Ocorreu um erro desconhecido Apagar + A apagar Desfazer Renomear Propriedades diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 1a8ce626..5a66b027 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -13,6 +13,7 @@ Please enter a name Ett okänt fel har uppstått Ta bort + Tar bort Ångra Döp om Properties diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b86a5191..2750ed10 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,6 +13,7 @@ Please enter a name An unknown error occurred Delete + Deleting Undo Rename Properties