add renaming
This commit is contained in:
parent
5848c68dbe
commit
037d0108d4
3 changed files with 28 additions and 15 deletions
|
@ -13,6 +13,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|||
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.extensions.formatSize
|
||||
import com.simplemobiletools.filepicker.extensions.isGif
|
||||
import com.simplemobiletools.filepicker.extensions.toast
|
||||
|
@ -22,7 +23,7 @@ import kotlinx.android.synthetic.main.list_item.view.*
|
|||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>, val itemClick: (FileDirItem) -> Unit) :
|
||||
class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>, val listener: ItemOperationsListener?, val itemClick: (FileDirItem) -> Unit) :
|
||||
RecyclerView.Adapter<ItemsAdapter.ViewHolder>() {
|
||||
val multiSelector = MultiSelector()
|
||||
val views = ArrayList<View>()
|
||||
|
@ -47,6 +48,10 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>,
|
|||
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.cab_rename -> {
|
||||
displayRenameDialog()
|
||||
true
|
||||
}
|
||||
R.id.cab_properties -> {
|
||||
showProperties()
|
||||
true
|
||||
|
@ -80,6 +85,15 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>,
|
|||
}
|
||||
}
|
||||
|
||||
private fun displayRenameDialog() {
|
||||
RenameItemDialog(activity, getSelectedMedia()[0], object : RenameItemDialog.OnRenameItemListener {
|
||||
override fun onSuccess() {
|
||||
actMode?.finish()
|
||||
listener?.refreshItems()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun showProperties() {
|
||||
val selections = multiSelector.selectedPositions
|
||||
if (selections.size <= 1) {
|
||||
|
@ -182,4 +196,8 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface ItemOperationsListener {
|
||||
fun refreshItems()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,14 @@ import com.simplemobiletools.filepicker.models.FileDirItem
|
|||
import kotlinx.android.synthetic.main.rename_item.view.*
|
||||
import java.io.File
|
||||
|
||||
class RenameItemDialog(val context: Context, val path: String, val item: FileDirItem, val listener: OnRenameItemListener) {
|
||||
class RenameItemDialog(val context: Context, val item: FileDirItem, val listener: OnRenameItemListener) {
|
||||
|
||||
init {
|
||||
val view = LayoutInflater.from(context).inflate(R.layout.rename_item, null)
|
||||
view.item_name.setText(item.name)
|
||||
|
||||
val path = File(item.path).parent
|
||||
|
||||
AlertDialog.Builder(context)
|
||||
.setTitle(context.resources.getString(R.string.rename_item))
|
||||
.setView(view)
|
||||
|
|
|
@ -19,7 +19,6 @@ import com.simplemobiletools.filemanager.activities.SimpleActivity
|
|||
import com.simplemobiletools.filemanager.adapters.ItemsAdapter
|
||||
import com.simplemobiletools.filemanager.dialogs.CopyDialog
|
||||
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
|
||||
import com.simplemobiletools.filemanager.dialogs.RenameItemDialog
|
||||
import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
|
||||
import com.simplemobiletools.filepicker.extensions.*
|
||||
import com.simplemobiletools.filepicker.models.FileDirItem
|
||||
|
@ -28,7 +27,7 @@ import kotlinx.android.synthetic.main.items_fragment.*
|
|||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClickListener, /*ListView.MultiChoiceModeListener, */View.OnTouchListener {
|
||||
class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClickListener, ItemsAdapter.ItemOperationsListener, View.OnTouchListener {
|
||||
private var mListener: ItemInteractionListener? = null
|
||||
private var mSnackbar: Snackbar? = null
|
||||
|
||||
|
@ -78,7 +77,7 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick
|
|||
|
||||
mItems = newItems
|
||||
|
||||
val adapter = ItemsAdapter(activity as SimpleActivity, mItems) {
|
||||
val adapter = ItemsAdapter(activity as SimpleActivity, mItems, this) {
|
||||
|
||||
}
|
||||
items_list.adapter = adapter
|
||||
|
@ -204,16 +203,6 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick
|
|||
return true
|
||||
}*/
|
||||
|
||||
private fun displayRenameDialog() {
|
||||
val item = getSelectedItem() ?: return
|
||||
|
||||
RenameItemDialog(context, mPath, item, object : RenameItemDialog.OnRenameItemListener {
|
||||
override fun onSuccess() {
|
||||
fillItems()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun displayCopyDialog() {
|
||||
val fileIndexes = getSelectedItemIndexes()
|
||||
if (fileIndexes.isEmpty())
|
||||
|
@ -328,6 +317,10 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick
|
|||
fillItems()
|
||||
}
|
||||
|
||||
override fun refreshItems() {
|
||||
fillItems()
|
||||
}
|
||||
|
||||
interface ItemInteractionListener {
|
||||
fun itemClicked(item: FileDirItem)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue