Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update folders on copy and move operations #11

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,12 @@ fun BaseSimpleActivity.tryCopyMoveFilesTo(fileDirItems: ArrayList<FileDirItem>,
val destination = it
handleSAFDialog(source) {
if (it) {
copyMoveFilesTo(fileDirItems, source.trimEnd('/'), destination, isCopyOperation, true, config.shouldShowHidden, callback)
val updatingDirectoryCallback: (String) -> Unit = { destinationPath: String ->
forceUpdateDirectory(destination)
forceUpdateDirectory(source)
callback?.invoke(destinationPath)
}
copyMoveFilesTo(fileDirItems, source.trimEnd('/'), destination, isCopyOperation, true, config.shouldShowHidden, updatingDirectoryCallback)
}
}
}
Expand Down
54 changes: 54 additions & 0 deletions app/src/main/kotlin/org/fossify/gallery/extensions/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,60 @@ fun Context.updateDBMediaPath(oldPath: String, newPath: String) {
}
}

fun Context.forceUpdateDirectory(folder: String) {
ensureBackgroundThread {
applicationContext.rescanPath(folder) {
val sorting = config.getFolderSorting(folder)
val grouping = config.getFolderGrouping(folder)
val getProperDateTaken = config.directorySorting and SORT_BY_DATE_TAKEN != 0 ||
sorting and SORT_BY_DATE_TAKEN != 0 ||
grouping and GROUP_BY_DATE_TAKEN_DAILY != 0 ||
grouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0

val getProperLastModified = config.directorySorting and SORT_BY_DATE_MODIFIED != 0 ||
sorting and SORT_BY_DATE_MODIFIED != 0 ||
grouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 ||
grouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0

val mediaFetcher = MediaFetcher(applicationContext)
val getImagesOnly = false
val getVideosOnly = false
val favoritePaths = getFavoritePaths()
val getProperFileSize = false
val lastModifieds = mediaFetcher.getLastModifieds()
val dateTakens = mediaFetcher.getDateTakens()
val android11Files = mediaFetcher?.getAndroid11FolderMedia(getImagesOnly, getVideosOnly, favoritePaths, false, true, dateTakens)
val albumCovers = config.parseAlbumCovers()
val hiddenString = getString(R.string.hidden)
val includedFolders = config.includedFolders
val noMediaFolders = getNoMediaFoldersSync()

val newMedia = mediaFetcher.getFilesFrom(
folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified,
getProperFileSize, favoritePaths, false, lastModifieds, dateTakens, android11Files
)

mediaFetcher.shouldStop = true

if (newMedia.isEmpty()) {
return@rescanPath
}

val newDir = createDirectoryFromMedia(folder, newMedia, albumCovers, hiddenString, includedFolders, getProperFileSize, noMediaFolders)

Thread {
try {
directoryDB.insert(newDir)
if (folder != RECYCLE_BIN && folder != FAVORITES) {
mediaDB.insertAll(newMedia)
}
} catch (ignored: Exception) {
}
}.start()
}
}
}

fun Context.updateDBDirectory(directory: Directory) {
try {
directoryDB.updateDirectory(
Expand Down