add deleting
This commit is contained in:
parent
037d0108d4
commit
205a6d26d5
|
@ -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<FileDirItem>,
|
|||
shareFiles()
|
||||
true
|
||||
}
|
||||
R.id.cab_delete -> {
|
||||
askConfirmDelete()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +130,23 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>,
|
|||
}
|
||||
}
|
||||
|
||||
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<String>(selections.size)
|
||||
selections.forEach { paths.add(mItems[it].path) }
|
||||
listener?.prepareForDeleting(paths)
|
||||
}
|
||||
|
||||
|
||||
private fun getSelectedMedia(): List<FileDirItem> {
|
||||
val positions = multiSelector.selectedPositions
|
||||
val selectedMedia = ArrayList<FileDirItem>(positions.size)
|
||||
|
@ -199,5 +221,7 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>,
|
|||
|
||||
interface ItemOperationsListener {
|
||||
fun refreshItems()
|
||||
|
||||
fun prepareForDeleting(paths: ArrayList<String>)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Int> {
|
||||
/*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<String>) {
|
||||
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() {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<string name="empty_name">Please enter a name</string>
|
||||
<string name="error_occurred">Ein unbekannter Fehler ist aufgetreten</string>
|
||||
<string name="delete">Löschen</string>
|
||||
<string name="deleting">Lösche</string>
|
||||
<string name="undo">Rückgängig</string>
|
||||
<string name="rename">Umbenennen</string>
|
||||
<string name="properties">Eigenschaften</string>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<string name="empty_name">Por favor, introduce un nombre</string>
|
||||
<string name="error_occurred">Se ha producido un error inesperado</string>
|
||||
<string name="delete">Eliminar</string>
|
||||
<string name="deleting">Eliminando</string>
|
||||
<string name="undo">Deshacer</string>
|
||||
<string name="rename">Renombrar</string>
|
||||
<string name="properties">Propiedades</string>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<string name="empty_name">Inserisci un nome</string>
|
||||
<string name="error_occurred">Riscontrato un errore sconosciuto</string>
|
||||
<string name="delete">Elimina</string>
|
||||
<string name="deleting">Eliminazione</string>
|
||||
<string name="undo">Annulla</string>
|
||||
<string name="rename">Rinomina</string>
|
||||
<string name="properties">Proprietà</string>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<string name="empty_name">Please enter a name</string>
|
||||
<string name="error_occurred">不明なエラーが発生しました</string>
|
||||
<string name="delete">削除</string>
|
||||
<string name="deleting">削除中</string>
|
||||
<string name="undo">元に戻す</string>
|
||||
<string name="rename">名前を変更</string>
|
||||
<string name="properties">Properties</string>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<string name="empty_name">Por favor digite o nome</string>
|
||||
<string name="error_occurred">Ocorreu um erro desconhecido</string>
|
||||
<string name="delete">Apagar</string>
|
||||
<string name="deleting">A apagar</string>
|
||||
<string name="undo">Desfazer</string>
|
||||
<string name="rename">Renomear</string>
|
||||
<string name="properties">Propriedades</string>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<string name="empty_name">Please enter a name</string>
|
||||
<string name="error_occurred">Ett okänt fel har uppstått</string>
|
||||
<string name="delete">Ta bort</string>
|
||||
<string name="deleting">Tar bort</string>
|
||||
<string name="undo">Ångra</string>
|
||||
<string name="rename">Döp om</string>
|
||||
<string name="properties">Properties</string>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<string name="empty_name">Please enter a name</string>
|
||||
<string name="error_occurred">An unknown error occurred</string>
|
||||
<string name="delete">Delete</string>
|
||||
<string name="deleting">Deleting</string>
|
||||
<string name="undo">Undo</string>
|
||||
<string name="rename">Rename</string>
|
||||
<string name="properties">Properties</string>
|
||||
|
|
Loading…
Reference in New Issue