From 0cfcba6c8f6da440e12690366647b32ea1ab740d Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 7 Feb 2020 20:04:45 +0100 Subject: [PATCH] avoid fetching the same folder twice, or after exiting the app --- .../gallery/pro/activities/MainActivity.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 7cad1ca04..b61f08f97 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -73,6 +73,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { private var mTempShowHiddenHandler = Handler() private var mZoomListener: MyRecyclerView.MyZoomListener? = null private var mSearchMenuItem: MenuItem? = null + private var mLastMediaFetcher: MediaFetcher? = null private var mDirs = ArrayList() private var mStoredAnimateGifs = true @@ -245,6 +246,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { unregisterFileUpdateListener() if (!config.showAll) { + mLastMediaFetcher?.shouldStop = true GalleryDatabase.destroyInstance() } } @@ -881,7 +883,8 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } // cached folders have been loaded, recheck folders one by one starting with the first displayed - val mediaFetcher = MediaFetcher(applicationContext) + mLastMediaFetcher?.shouldStop = true + mLastMediaFetcher = MediaFetcher(applicationContext) val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent val hiddenString = getString(R.string.hidden) @@ -900,7 +903,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { return } - val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperFileSize, favoritePaths, false) + val curMedia = mLastMediaFetcher!!.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperFileSize, favoritePaths, false) val newDir = if (curMedia.isEmpty()) { if (directory.path != tempFolderPath) { dirPathsToRemove.add(directory.path) @@ -955,7 +958,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } catch (ignored: Exception) { } - val foldersToScan = mediaFetcher.getFoldersToScan() + val foldersToScan = mLastMediaFetcher!!.getFoldersToScan() foldersToScan.add(FAVORITES) if (config.showRecycleBinAtFolders) { foldersToScan.add(RECYCLE_BIN) @@ -973,7 +976,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { return } - val newMedia = mediaFetcher.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperFileSize, favoritePaths, false) + val newMedia = mLastMediaFetcher!!.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, getProperFileSize, favoritePaths, false) if (newMedia.isEmpty()) { continue }