add a Rename action button to the media screen

This commit is contained in:
tibbi 2016-12-06 22:53:11 +01:00
parent 4abc2d4b59
commit ade06101a5
3 changed files with 27 additions and 5 deletions

View file

@ -65,7 +65,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
true
}
R.id.cab_rename -> {
editDir()
renameDir()
true
}
R.id.cab_pin -> {
@ -109,8 +109,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean {
val positions = multiSelector.selectedPositions
val menuItem = menu.findItem(R.id.cab_rename)
menuItem.isVisible = positions.size <= 1
menu.findItem(R.id.cab_rename).isVisible = positions.size <= 1
checkHideBtnVisibility(menu, positions)
checkPinBtnVisibility(menu, positions)
@ -165,7 +164,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
}
}
private fun editDir() {
private fun renameDir() {
val path = dirs[multiSelector.selectedPositions[0]].path
val dir = File(path)
if (activity.isAStorageRootFolder(dir.absolutePath)) {

View file

@ -18,6 +18,7 @@ import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.dialogs.CopyDialog
import com.simplemobiletools.gallery.dialogs.RenameFileDialog
import com.simplemobiletools.gallery.extensions.beVisibleIf
import com.simplemobiletools.gallery.extensions.shareMedia
import com.simplemobiletools.gallery.extensions.shareMedium
@ -62,6 +63,10 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
showProperties()
true
}
R.id.cab_rename -> {
renameFile()
true
}
R.id.cab_share -> {
shareMedia()
return true
@ -85,7 +90,11 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
return true
}
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu) = true
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean {
menu.findItem(R.id.cab_rename).isVisible = multiSelector.selectedPositions.size <= 1
return true
}
override fun onDestroyActionMode(actionMode: ActionMode?) {
super.onDestroyActionMode(actionMode)
@ -105,6 +114,15 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
}
}
private fun renameFile() {
RenameFileDialog(activity, File(media[multiSelector.selectedPositions[0]].path)) {
listener?.refreshItems()
activity.runOnUiThread {
actMode?.finish()
}
}
}
private fun shareMedia() {
val selections = multiSelector.selectedPositions
if (selections.size <= 1) {

View file

@ -16,6 +16,11 @@
android:icon="@mipmap/copy"
android:title="@string/copy_move"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_rename"
android:icon="@mipmap/rename"
android:title="@string/rename"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_delete"
android:icon="@mipmap/delete"