moving some functions into background thread

This commit is contained in:
tibbi 2021-02-19 18:47:38 +01:00
parent 8fc4fc2f88
commit 2cf4735767
3 changed files with 20 additions and 10 deletions

View File

@ -559,9 +559,15 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
}
private fun deleteDirectoryIfEmpty() {
val fileDirItem = FileDirItem(mPath, mPath.getFilenameFromPath(), true)
if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory && fileDirItem.getProperFileCount(this, true) == 0) {
tryDeleteFileDirItem(fileDirItem, true, true)
if (config.deleteEmptyFolders) {
val fileDirItem = FileDirItem(mPath, mPath.getFilenameFromPath(), true)
if (!fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory) {
ensureBackgroundThread {
if (fileDirItem.getProperFileCount(this, true) == 0) {
tryDeleteFileDirItem(fileDirItem, true, true)
}
}
}
}
}

View File

@ -1163,12 +1163,14 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
private fun deleteDirectoryIfEmpty() {
val fileDirItem = FileDirItem(mDirectory, mDirectory.getFilenameFromPath(), File(mDirectory).isDirectory)
if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory) {
ensureBackgroundThread {
if (fileDirItem.getProperFileCount(this, true) == 0) {
tryDeleteFileDirItem(fileDirItem, true, true)
scanPathRecursively(mDirectory)
if (config.deleteEmptyFolders) {
val fileDirItem = FileDirItem(mDirectory, mDirectory.getFilenameFromPath(), File(mDirectory).isDirectory)
if (!fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory) {
ensureBackgroundThread {
if (fileDirItem.getProperFileCount(this, true) == 0) {
tryDeleteFileDirItem(fileDirItem, true, true)
scanPathRecursively(mDirectory)
}
}
}
}

View File

@ -158,7 +158,9 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
} else {
try {
if (file.createNewFile()) {
addNoMediaIntoMediaStore(file.absolutePath)
ensureBackgroundThread {
addNoMediaIntoMediaStore(file.absolutePath)
}
} else {
toast(R.string.unknown_error_occurred)
}