add the file renaming functionality itself

This commit is contained in:
tibbi 2017-04-26 20:54:47 +02:00
parent 40c4a9aec1
commit 2e8da56e2d
2 changed files with 25 additions and 6 deletions

View file

@ -174,19 +174,18 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
}
private fun toggleFoldersVisibility(hide: Boolean) {
val paths = getSelectedPaths()
for (path in paths) {
getSelectedPaths().forEach {
if (hide) {
if (config.wasHideFolderTooltipShown) {
hideFolder(path)
hideFolder(it)
} else {
config.wasHideFolderTooltipShown = true
ConfirmationDialog(activity, activity.getString(R.string.hide_folder_description)) {
hideFolder(path)
hideFolder(it)
}
}
} else {
activity.removeNoMedia(path) {
activity.removeNoMedia(it) {
noMediaHandled()
}
}

View file

@ -13,6 +13,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.PropertiesDialog
import com.simplemobiletools.commons.dialogs.RenameItemDialog
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.renameFile
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.extensions.*
@ -149,7 +150,26 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
}
private fun toggleFileVisibility(hide: Boolean) {
Thread({
getSelectedMedia().forEach {
val oldFile = File(it.path)
val path = oldFile.parent
var filename = it.name
if (hide) {
filename = ".${filename.trimStart('.')}"
} else {
filename = filename.substring(1, filename.length)
}
val newFile = File(path, filename)
activity.renameFile(oldFile, newFile) {
newFile.setLastModified(System.currentTimeMillis())
}
}
activity.runOnUiThread {
listener?.refreshItems()
actMode?.finish()
}
}).start()
}
private fun shareMedia() {