mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
add renaming
This commit is contained in:
@ -13,6 +13,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|||||||
import com.simplemobiletools.filemanager.Config
|
import com.simplemobiletools.filemanager.Config
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.filemanager.dialogs.RenameItemDialog
|
||||||
import com.simplemobiletools.filepicker.extensions.formatSize
|
import com.simplemobiletools.filepicker.extensions.formatSize
|
||||||
import com.simplemobiletools.filepicker.extensions.isGif
|
import com.simplemobiletools.filepicker.extensions.isGif
|
||||||
import com.simplemobiletools.filepicker.extensions.toast
|
import com.simplemobiletools.filepicker.extensions.toast
|
||||||
@ -22,7 +23,7 @@ import kotlinx.android.synthetic.main.list_item.view.*
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
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>() {
|
RecyclerView.Adapter<ItemsAdapter.ViewHolder>() {
|
||||||
val multiSelector = MultiSelector()
|
val multiSelector = MultiSelector()
|
||||||
val views = ArrayList<View>()
|
val views = ArrayList<View>()
|
||||||
@ -47,6 +48,10 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List<FileDirItem>,
|
|||||||
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
||||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
|
R.id.cab_rename -> {
|
||||||
|
displayRenameDialog()
|
||||||
|
true
|
||||||
|
}
|
||||||
R.id.cab_properties -> {
|
R.id.cab_properties -> {
|
||||||
showProperties()
|
showProperties()
|
||||||
true
|
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() {
|
private fun showProperties() {
|
||||||
val selections = multiSelector.selectedPositions
|
val selections = multiSelector.selectedPositions
|
||||||
if (selections.size <= 1) {
|
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 kotlinx.android.synthetic.main.rename_item.view.*
|
||||||
import java.io.File
|
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 {
|
init {
|
||||||
val view = LayoutInflater.from(context).inflate(R.layout.rename_item, null)
|
val view = LayoutInflater.from(context).inflate(R.layout.rename_item, null)
|
||||||
view.item_name.setText(item.name)
|
view.item_name.setText(item.name)
|
||||||
|
|
||||||
|
val path = File(item.path).parent
|
||||||
|
|
||||||
AlertDialog.Builder(context)
|
AlertDialog.Builder(context)
|
||||||
.setTitle(context.resources.getString(R.string.rename_item))
|
.setTitle(context.resources.getString(R.string.rename_item))
|
||||||
.setView(view)
|
.setView(view)
|
||||||
|
@ -19,7 +19,6 @@ import com.simplemobiletools.filemanager.activities.SimpleActivity
|
|||||||
import com.simplemobiletools.filemanager.adapters.ItemsAdapter
|
import com.simplemobiletools.filemanager.adapters.ItemsAdapter
|
||||||
import com.simplemobiletools.filemanager.dialogs.CopyDialog
|
import com.simplemobiletools.filemanager.dialogs.CopyDialog
|
||||||
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
|
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
|
||||||
import com.simplemobiletools.filemanager.dialogs.RenameItemDialog
|
|
||||||
import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
|
import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
|
||||||
import com.simplemobiletools.filepicker.extensions.*
|
import com.simplemobiletools.filepicker.extensions.*
|
||||||
import com.simplemobiletools.filepicker.models.FileDirItem
|
import com.simplemobiletools.filepicker.models.FileDirItem
|
||||||
@ -28,7 +27,7 @@ import kotlinx.android.synthetic.main.items_fragment.*
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
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 mListener: ItemInteractionListener? = null
|
||||||
private var mSnackbar: Snackbar? = null
|
private var mSnackbar: Snackbar? = null
|
||||||
|
|
||||||
@ -78,7 +77,7 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick
|
|||||||
|
|
||||||
mItems = newItems
|
mItems = newItems
|
||||||
|
|
||||||
val adapter = ItemsAdapter(activity as SimpleActivity, mItems) {
|
val adapter = ItemsAdapter(activity as SimpleActivity, mItems, this) {
|
||||||
|
|
||||||
}
|
}
|
||||||
items_list.adapter = adapter
|
items_list.adapter = adapter
|
||||||
@ -204,16 +203,6 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick
|
|||||||
return true
|
return true
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
private fun displayRenameDialog() {
|
|
||||||
val item = getSelectedItem() ?: return
|
|
||||||
|
|
||||||
RenameItemDialog(context, mPath, item, object : RenameItemDialog.OnRenameItemListener {
|
|
||||||
override fun onSuccess() {
|
|
||||||
fillItems()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun displayCopyDialog() {
|
private fun displayCopyDialog() {
|
||||||
val fileIndexes = getSelectedItemIndexes()
|
val fileIndexes = getSelectedItemIndexes()
|
||||||
if (fileIndexes.isEmpty())
|
if (fileIndexes.isEmpty())
|
||||||
@ -328,6 +317,10 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick
|
|||||||
fillItems()
|
fillItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun refreshItems() {
|
||||||
|
fillItems()
|
||||||
|
}
|
||||||
|
|
||||||
interface ItemInteractionListener {
|
interface ItemInteractionListener {
|
||||||
fun itemClicked(item: FileDirItem)
|
fun itemClicked(item: FileDirItem)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user