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,11 +559,17 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
} }
private fun deleteDirectoryIfEmpty() { private fun deleteDirectoryIfEmpty() {
if (config.deleteEmptyFolders) {
val fileDirItem = FileDirItem(mPath, mPath.getFilenameFromPath(), true) val fileDirItem = FileDirItem(mPath, mPath.getFilenameFromPath(), true)
if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory && fileDirItem.getProperFileCount(this, true) == 0) { if (!fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory) {
ensureBackgroundThread {
if (fileDirItem.getProperFileCount(this, true) == 0) {
tryDeleteFileDirItem(fileDirItem, true, true) tryDeleteFileDirItem(fileDirItem, true, true)
} }
} }
}
}
}
private fun getMedia() { private fun getMedia() {
if (mIsGettingMedia) { if (mIsGettingMedia) {

View file

@ -1163,8 +1163,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
private fun deleteDirectoryIfEmpty() { private fun deleteDirectoryIfEmpty() {
if (config.deleteEmptyFolders) {
val fileDirItem = FileDirItem(mDirectory, mDirectory.getFilenameFromPath(), File(mDirectory).isDirectory) val fileDirItem = FileDirItem(mDirectory, mDirectory.getFilenameFromPath(), File(mDirectory).isDirectory)
if (config.deleteEmptyFolders && !fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory) { if (!fileDirItem.isDownloadsFolder() && fileDirItem.isDirectory) {
ensureBackgroundThread { ensureBackgroundThread {
if (fileDirItem.getProperFileCount(this, true) == 0) { if (fileDirItem.getProperFileCount(this, true) == 0) {
tryDeleteFileDirItem(fileDirItem, true, true) tryDeleteFileDirItem(fileDirItem, true, true)
@ -1173,6 +1174,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
} }
} }
}
@SuppressLint("SourceLockedOrientationActivity") @SuppressLint("SourceLockedOrientationActivity")
private fun checkOrientation() { private fun checkOrientation() {

View file

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