fix some Favorites glitches, try treating it more like other folders
This commit is contained in:
parent
b81e1c2172
commit
8af3b1eee3
3 changed files with 17 additions and 35 deletions
|
@ -618,10 +618,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (directory in dirs) {
|
for (directory in dirs) {
|
||||||
if (directory.areFavorites()) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, favoritePaths)
|
val curMedia = mediaFetcher.getFilesFrom(directory.path, getImagesOnly, getVideosOnly, getProperDateTaken, favoritePaths)
|
||||||
val newDir = if (curMedia.isEmpty()) {
|
val newDir = if (curMedia.isEmpty()) {
|
||||||
directory
|
directory
|
||||||
|
@ -661,30 +657,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
val foldersToScan = mediaFetcher.getFoldersToScan()
|
val foldersToScan = mediaFetcher.getFoldersToScan()
|
||||||
|
foldersToScan.add(FAVORITES)
|
||||||
dirs.forEach {
|
dirs.forEach {
|
||||||
foldersToScan.remove(it.path)
|
foldersToScan.remove(it.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
val favoriteMedia = mediumDao.getFavorites() as ArrayList<Medium>
|
|
||||||
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
|
// check the remaining folders which were not cached at all yet
|
||||||
for (folder in foldersToScan) {
|
for (folder in foldersToScan) {
|
||||||
val newMedia = mediaFetcher.getFilesFrom(folder, getImagesOnly, getVideosOnly, getProperDateTaken, favoritePaths)
|
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()) {
|
if (invalidDirs.isNotEmpty()) {
|
||||||
dirs.removeAll(invalidDirs)
|
dirs.removeAll(invalidDirs)
|
||||||
showSortedDirs(dirs)
|
showSortedDirs(dirs)
|
||||||
|
|
|
@ -4,9 +4,7 @@ import android.content.Context
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
|
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.extensions.galleryDB
|
|
||||||
import com.simplemobiletools.gallery.extensions.getFavoritePaths
|
import com.simplemobiletools.gallery.extensions.getFavoritePaths
|
||||||
import com.simplemobiletools.gallery.helpers.FAVORITES
|
|
||||||
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -29,16 +27,10 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
|
||||||
|
|
||||||
MediaFetcher(context).sortMedia(media, context.config.getFileSorting(""))
|
MediaFetcher(context).sortMedia(media, context.config.getFileSorting(""))
|
||||||
media
|
media
|
||||||
} else {
|
|
||||||
if (mPath == FAVORITES) {
|
|
||||||
val media = context.galleryDB.MediumDao().getFavorites() as ArrayList<Medium>
|
|
||||||
mediaFetcher.sortMedia(media, context.config.getFileSorting(mPath))
|
|
||||||
media
|
|
||||||
} else {
|
} else {
|
||||||
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths)
|
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPostExecute(media: ArrayList<Medium>) {
|
override fun onPostExecute(media: ArrayList<Medium>) {
|
||||||
super.onPostExecute(media)
|
super.onPostExecute(media)
|
||||||
|
|
|
@ -159,7 +159,13 @@ class MediaFetcher(val context: Context) {
|
||||||
private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, getProperDateTaken: Boolean,
|
private fun getMediaInFolder(folder: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int, getProperDateTaken: Boolean,
|
||||||
favoritePaths: ArrayList<String>): ArrayList<Medium> {
|
favoritePaths: ArrayList<String>): ArrayList<Medium> {
|
||||||
val media = ArrayList<Medium>()
|
val media = ArrayList<Medium>()
|
||||||
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 doExtraCheck = context.config.doExtraCheck
|
||||||
val showHidden = context.config.shouldShowHidden
|
val showHidden = context.config.shouldShowHidden
|
||||||
val dateTakens = if (getProperDateTaken) getFolderDateTakens(folder) else HashMap()
|
val dateTakens = if (getProperDateTaken) getFolderDateTakens(folder) else HashMap()
|
||||||
|
@ -213,7 +219,7 @@ class MediaFetcher(val context: Context) {
|
||||||
|
|
||||||
val path = file.absolutePath
|
val path = file.absolutePath
|
||||||
val isFavorite = favoritePaths.contains(path)
|
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)
|
media.add(medium)
|
||||||
}
|
}
|
||||||
return media
|
return media
|
||||||
|
|
Loading…
Reference in a new issue