mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
update directories if one is renamed
This commit is contained in:
parent
f08fd48d1f
commit
e237afe916
3 changed files with 17 additions and 11 deletions
|
@ -681,8 +681,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
gotDirectories(directories, true)
|
||||
} else {
|
||||
mDirs = directories
|
||||
storeDirectories()
|
||||
}
|
||||
|
||||
Thread {
|
||||
storeDirectoryItems(directories)
|
||||
removeInvalidDirectories()
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun checkWhatsNewDialog() {
|
||||
|
|
|
@ -155,7 +155,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
}
|
||||
|
||||
private fun renameDir() {
|
||||
val sourcePath = dirs[selectedPositions.first()].path
|
||||
val firstDir = dirs[selectedPositions.first()]
|
||||
val sourcePath = firstDir.path
|
||||
val dir = File(sourcePath)
|
||||
if (activity.isAStorageRootFolder(dir.absolutePath)) {
|
||||
activity.toast(R.string.rename_folder_root)
|
||||
|
@ -164,11 +165,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
|
||||
RenameItemDialog(activity, dir.absolutePath) {
|
||||
activity.runOnUiThread {
|
||||
if (selectedPositions.isEmpty()) {
|
||||
return@runOnUiThread
|
||||
}
|
||||
|
||||
dirs[selectedPositions.first()].apply {
|
||||
firstDir.apply {
|
||||
path = it
|
||||
name = it.getFilenameFromPath()
|
||||
tmb = File(it, tmb.getFilenameFromPath()).absolutePath
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
|||
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
||||
import com.simplemobiletools.gallery.databases.GalleryDataBase
|
||||
import com.simplemobiletools.gallery.helpers.*
|
||||
import com.simplemobiletools.gallery.interfaces.DirectoryDao
|
||||
import com.simplemobiletools.gallery.models.Directory
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import com.simplemobiletools.gallery.views.MySquareImageView
|
||||
|
@ -249,10 +250,7 @@ fun Context.getCachedDirectories(callback: (ArrayList<Directory>) -> Unit) {
|
|||
val directoryDao = galleryDB.DirectoryDao()
|
||||
val directories = directoryDao.getAll() as ArrayList<Directory>
|
||||
callback(directories)
|
||||
|
||||
directories.filter { !File(it.path).exists() }.forEach {
|
||||
directoryDao.deleteDirPath(it.path)
|
||||
}
|
||||
removeInvalidDirectories(directories, directoryDao)
|
||||
}.start()
|
||||
}
|
||||
|
||||
|
@ -268,6 +266,13 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList<Medium>) -> Unit)
|
|||
}.start()
|
||||
}
|
||||
|
||||
fun Context.removeInvalidDirectories(dirs: ArrayList<Directory>? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) {
|
||||
val dirsToCheck = dirs ?: directoryDao.getAll()
|
||||
dirsToCheck.filter { !File(it.path).exists() }.forEach {
|
||||
directoryDao.deleteDirPath(it.path)
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.updateMediaPath(oldPath: String, newPath: String) {
|
||||
val newFilename = newPath.getFilenameFromPath()
|
||||
val newParentPath = newPath.getParentPath()
|
||||
|
|
Loading…
Reference in a new issue