From 037d0108d4655f82d03160dff2289d3ce571b7fe Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 20 Nov 2016 22:20:49 +0100 Subject: [PATCH] add renaming --- .../filemanager/adapters/ItemsAdapter.kt | 20 ++++++++++++++++++- .../filemanager/dialogs/RenameItemDialog.kt | 4 +++- .../filemanager/fragments/ItemsFragment.kt | 19 ++++++------------ 3 files changed, 28 insertions(+), 15 deletions(-) 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 1eb3eac4..14d54554 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -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, val itemClick: (FileDirItem) -> Unit) : +class ItemsAdapter(val activity: SimpleActivity, val mItems: List, val listener: ItemOperationsListener?, val itemClick: (FileDirItem) -> Unit) : RecyclerView.Adapter() { val multiSelector = MultiSelector() val views = ArrayList() @@ -47,6 +48,10 @@ class ItemsAdapter(val activity: SimpleActivity, val mItems: List, 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, } } + 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, } } } + + interface ItemOperationsListener { + fun refreshItems() + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/RenameItemDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/RenameItemDialog.kt index 9d6be9e1..7b5930dc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/RenameItemDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/RenameItemDialog.kt @@ -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) 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 5a5e953c..ea0698cc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt @@ -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) }