diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 550e97aa4..a1fa7534a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -618,10 +618,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { try { for (directory in dirs) { - if (directory.areFavorites()) { - continue - } - val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, favoritePaths) val newDir = if (curMedia.isEmpty()) { directory @@ -661,30 +657,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } val foldersToScan = mediaFetcher.getFoldersToScan() + foldersToScan.add(FAVORITES) dirs.forEach { foldersToScan.remove(it.path) } - val favoriteMedia = mediumDao.getFavorites() as ArrayList - if (favoriteMedia.isNotEmpty()) { - // avoid adding Favorites twice - val currentFavoriteDir = dirs.firstOrNull { it.areFavorites() } - if (currentFavoriteDir != null) { - dirs.remove(currentFavoriteDir) - } - val favorites = createDirectoryFromMedia(FAVORITES, favoriteMedia, albumCovers, hiddenString, includedFolders, isSortingAscending) - dirs.add(favorites) - showSortedDirs(dirs) - directoryDao.insert(favorites) - } else if (dirs.any { it.areFavorites() }) { - val currentFavoriteDir = dirs.firstOrNull { it.areFavorites() } - if (currentFavoriteDir != null) { - dirs.remove(currentFavoriteDir) - showSortedDirs(dirs) - directoryDao.deleteDirPath(FAVORITES) - } - } - // check the remaining folders which were not cached at all yet for (folder in foldersToScan) { val newMedia = mediaFetcher.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, favoritePaths) @@ -818,6 +795,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } + if (getFavoritePaths().isEmpty()) { + val dirsFolder = dirs.firstOrNull { it.areFavorites() } + if (dirsFolder != null) { + invalidDirs.add(dirsFolder) + } + } + if (invalidDirs.isNotEmpty()) { dirs.removeAll(invalidDirs) showSortedDirs(dirs) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index 9d5ff6a15..07b9bb630 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -4,9 +4,7 @@ import android.content.Context import android.os.AsyncTask import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.extensions.galleryDB import com.simplemobiletools.gallery.extensions.getFavoritePaths -import com.simplemobiletools.gallery.helpers.FAVORITES import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.models.Medium import java.util.* @@ -30,13 +28,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage MediaFetcher(context).sortMedia(media, context.config.getFileSorting("")) media } else { - if (mPath == FAVORITES) { - val media = context.galleryDB.MediumDao().getFavorites() as ArrayList - mediaFetcher.sortMedia(media, context.config.getFileSorting(mPath)) - media - } else { - mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) - } + mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 9afb95ccf..670523e2e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -159,7 +159,13 @@ class MediaFetcher(val context: Context) { private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, getProperDateTaken: Boolean, favoritePaths: ArrayList): ArrayList { val media = ArrayList() - val files = File(folder).listFiles() ?: return media + + val files = if (folder == FAVORITES) { + favoritePaths.map { File(it) }.toTypedArray() + } else { + File(folder).listFiles() ?: return media + } + val doExtraCheck = context.config.doExtraCheck val showHidden = context.config.shouldShowHidden val dateTakens = if (getProperDateTaken) getFolderDateTakens(folder) else HashMap() @@ -213,7 +219,7 @@ class MediaFetcher(val context: Context) { val path = file.absolutePath val isFavorite = favoritePaths.contains(path) - val medium = Medium(null, filename, path, folder, lastModified, dateTaken, size, type, isFavorite) + val medium = Medium(null, filename, path, file.parent, lastModified, dateTaken, size, type, isFavorite) media.add(medium) } return media