adding a simple way of renaming multiple items at once
This commit is contained in:
parent
c05cad57d5
commit
6f812bbbaa
3 changed files with 48 additions and 31 deletions
|
@ -48,7 +48,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:5.1.14'
|
implementation 'com.simplemobiletools:commons:5.1.15'
|
||||||
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
|
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
|
||||||
implementation 'androidx.multidex:multidex:2.0.0'
|
implementation 'androidx.multidex:multidex:2.0.0'
|
||||||
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||||
|
import com.simplemobiletools.commons.dialogs.RenameItemsDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.OTG_PATH
|
import com.simplemobiletools.commons.helpers.OTG_PATH
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
|
@ -68,7 +69,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
|
|
||||||
val isOneItemSelected = isOneItemSelected()
|
val isOneItemSelected = isOneItemSelected()
|
||||||
menu.apply {
|
menu.apply {
|
||||||
findItem(R.id.cab_rename).isVisible = isOneItemSelected && !selectedPaths.contains(FAVORITES) && !selectedPaths.contains(RECYCLE_BIN)
|
findItem(R.id.cab_rename).isVisible = !selectedPaths.contains(FAVORITES) && !selectedPaths.contains(RECYCLE_BIN)
|
||||||
findItem(R.id.cab_change_cover_image).isVisible = isOneItemSelected
|
findItem(R.id.cab_change_cover_image).isVisible = isOneItemSelected
|
||||||
|
|
||||||
findItem(R.id.cab_empty_recycle_bin).isVisible = isOneItemSelected && selectedPaths.first() == RECYCLE_BIN
|
findItem(R.id.cab_empty_recycle_bin).isVisible = isOneItemSelected && selectedPaths.first() == RECYCLE_BIN
|
||||||
|
@ -141,26 +142,33 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renameDir() {
|
private fun renameDir() {
|
||||||
val firstDir = getFirstSelectedItem() ?: return
|
if (selectedKeys.size == 1) {
|
||||||
val sourcePath = firstDir.path
|
val firstDir = getFirstSelectedItem() ?: return
|
||||||
val dir = File(sourcePath)
|
val sourcePath = firstDir.path
|
||||||
if (activity.isAStorageRootFolder(dir.absolutePath)) {
|
val dir = File(sourcePath)
|
||||||
activity.toast(R.string.rename_folder_root)
|
if (activity.isAStorageRootFolder(dir.absolutePath)) {
|
||||||
return
|
activity.toast(R.string.rename_folder_root)
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
RenameItemDialog(activity, dir.absolutePath) {
|
RenameItemDialog(activity, dir.absolutePath) {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
firstDir.apply {
|
firstDir.apply {
|
||||||
path = it
|
path = it
|
||||||
name = it.getFilenameFromPath()
|
name = it.getFilenameFromPath()
|
||||||
tmb = File(it, tmb.getFilenameFromPath()).absolutePath
|
tmb = File(it, tmb.getFilenameFromPath()).absolutePath
|
||||||
|
}
|
||||||
|
updateDirs(dirs)
|
||||||
|
Thread {
|
||||||
|
activity.galleryDB.DirectoryDao().updateDirectoryAfterRename(firstDir.tmb, firstDir.name, firstDir.path, sourcePath)
|
||||||
|
listener?.refreshItems()
|
||||||
|
}.start()
|
||||||
}
|
}
|
||||||
updateDirs(dirs)
|
}
|
||||||
Thread {
|
} else {
|
||||||
activity.galleryDB.DirectoryDao().updateDirectoryAfterRename(firstDir.tmb, firstDir.name, firstDir.path, sourcePath)
|
val paths = getSelectedPaths().filter { !activity.isAStorageRootFolder(it) } as ArrayList<String>
|
||||||
listener?.refreshItems()
|
RenameItemsDialog(activity, paths) {
|
||||||
}.start()
|
listener?.refreshItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||||
|
import com.simplemobiletools.commons.dialogs.RenameItemsDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.OTG_PATH
|
import com.simplemobiletools.commons.helpers.OTG_PATH
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
|
@ -111,7 +112,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
val isOneItemSelected = isOneItemSelected()
|
val isOneItemSelected = isOneItemSelected()
|
||||||
val selectedPaths = selectedItems.map { it.path } as ArrayList<String>
|
val selectedPaths = selectedItems.map { it.path } as ArrayList<String>
|
||||||
menu.apply {
|
menu.apply {
|
||||||
findItem(R.id.cab_rename).isVisible = isOneItemSelected && selectedItems.firstOrNull()?.getIsInRecycleBin() == false
|
findItem(R.id.cab_rename).isVisible = selectedItems.firstOrNull()?.getIsInRecycleBin() == false
|
||||||
findItem(R.id.cab_open_with).isVisible = isOneItemSelected
|
findItem(R.id.cab_open_with).isVisible = isOneItemSelected
|
||||||
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.isNotEmpty()
|
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.isNotEmpty()
|
||||||
findItem(R.id.cab_restore_recycle_bin_files).isVisible = selectedPaths.all { it.startsWith(activity.filesDir.absolutePath) }
|
findItem(R.id.cab_restore_recycle_bin_files).isVisible = selectedPaths.all { it.startsWith(activity.filesDir.absolutePath) }
|
||||||
|
@ -195,17 +196,25 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renameFile() {
|
private fun renameFile() {
|
||||||
val oldPath = getFirstSelectedItemPath() ?: return
|
if (selectedKeys.size == 1) {
|
||||||
RenameItemDialog(activity, oldPath) {
|
val oldPath = getFirstSelectedItemPath() ?: return
|
||||||
Thread {
|
RenameItemDialog(activity, oldPath) {
|
||||||
activity.updateDBMediaPath(oldPath, it)
|
Thread {
|
||||||
|
activity.updateDBMediaPath(oldPath, it)
|
||||||
|
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
enableInstantLoad()
|
enableInstantLoad()
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
finishActMode()
|
finishActMode()
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
RenameItemsDialog(activity, getSelectedPaths()) {
|
||||||
|
enableInstantLoad()
|
||||||
|
listener?.refreshItems()
|
||||||
|
finishActMode()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue