avoid fetching the same folder twice, or after exiting the app

This commit is contained in:
tibbi 2020-02-07 20:04:45 +01:00
parent e465f73f9b
commit 0cfcba6c8f

View file

@ -73,6 +73,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
private var mTempShowHiddenHandler = Handler() private var mTempShowHiddenHandler = Handler()
private var mZoomListener: MyRecyclerView.MyZoomListener? = null private var mZoomListener: MyRecyclerView.MyZoomListener? = null
private var mSearchMenuItem: MenuItem? = null private var mSearchMenuItem: MenuItem? = null
private var mLastMediaFetcher: MediaFetcher? = null
private var mDirs = ArrayList<Directory>() private var mDirs = ArrayList<Directory>()
private var mStoredAnimateGifs = true private var mStoredAnimateGifs = true
@ -245,6 +246,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
unregisterFileUpdateListener() unregisterFileUpdateListener()
if (!config.showAll) { if (!config.showAll) {
mLastMediaFetcher?.shouldStop = true
GalleryDatabase.destroyInstance() 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 // 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 getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent
val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent
val hiddenString = getString(R.string.hidden) val hiddenString = getString(R.string.hidden)
@ -900,7 +903,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
return 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()) { val newDir = if (curMedia.isEmpty()) {
if (directory.path != tempFolderPath) { if (directory.path != tempFolderPath) {
dirPathsToRemove.add(directory.path) dirPathsToRemove.add(directory.path)
@ -955,7 +958,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
} catch (ignored: Exception) { } catch (ignored: Exception) {
} }
val foldersToScan = mediaFetcher.getFoldersToScan() val foldersToScan = mLastMediaFetcher!!.getFoldersToScan()
foldersToScan.add(FAVORITES) foldersToScan.add(FAVORITES)
if (config.showRecycleBinAtFolders) { if (config.showRecycleBinAtFolders) {
foldersToScan.add(RECYCLE_BIN) foldersToScan.add(RECYCLE_BIN)
@ -973,7 +976,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
return 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()) { if (newMedia.isEmpty()) {
continue continue
} }