mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
couple improvements related to the Favorites folder
This commit is contained in:
parent
556ec23a0c
commit
58877df88e
5 changed files with 22 additions and 4 deletions
|
@ -613,6 +613,10 @@ 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
|
||||
|
@ -656,6 +660,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
foldersToScan.remove(it.path)
|
||||
}
|
||||
|
||||
val favoriteMedia = mediumDao.getFavorites() as ArrayList<Medium>
|
||||
if (favoriteMedia.isNotEmpty() && dirs.none { it.areFavorites() }) {
|
||||
val favorites = createDirectoryFromMedia(FAVORITES, favoriteMedia, albumCovers, hiddenString, includedFolders, isSortingAscending)
|
||||
dirs.add(favorites)
|
||||
showSortedDirs(dirs)
|
||||
directoryDao.insert(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)
|
||||
|
@ -721,7 +733,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
}
|
||||
|
||||
val mediaTypes = curMedia.getDirMediaTypes()
|
||||
val dirName = checkAppendingHidden(path, hiddenString, includedFolders)
|
||||
val dirName = if (path == FAVORITES) getString(R.string.favorites) else checkAppendingHidden(path, hiddenString, includedFolders)
|
||||
|
||||
val firstItem = curMedia.first()
|
||||
val lastItem = curMedia.last()
|
||||
|
@ -776,7 +788,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
|
||||
private fun checkInvalidDirectories(dirs: ArrayList<Directory>, directoryDao: DirectoryDao) {
|
||||
val invalidDirs = ArrayList<Directory>()
|
||||
dirs.forEach {
|
||||
dirs.filter { !it.areFavorites() }.forEach {
|
||||
if (!getDoesFilePathExist(it.path)) {
|
||||
invalidDirs.add(it)
|
||||
} else if (it.path != config.tempFolderPath) {
|
||||
|
|
|
@ -488,7 +488,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}
|
||||
|
||||
private fun isDirEmpty(): Boolean {
|
||||
return if (mMedia.size <= 0 && config.filterMedia > 0) {
|
||||
return if (mPath != FAVORITES && mMedia.size <= 0 && config.filterMedia > 0) {
|
||||
deleteDirectoryIfEmpty()
|
||||
deleteDBDirectory()
|
||||
finish()
|
||||
|
|
|
@ -356,7 +356,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
|
|||
|
||||
fun Context.removeInvalidDBDirectories(dirs: ArrayList<Directory>? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) {
|
||||
val dirsToCheck = dirs ?: directoryDao.getAll()
|
||||
dirsToCheck.filter { !getDoesFilePathExist(it.path) && it.path != config.tempFolderPath }.forEach {
|
||||
dirsToCheck.filter { !it.areFavorites() && !getDoesFilePathExist(it.path) && it.path != config.tempFolderPath }.forEach {
|
||||
directoryDao.deleteDirPath(it.path)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@ interface MediumDao {
|
|||
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite FROM media WHERE parent_path = :path")
|
||||
fun getMediaFromPath(path: String): List<Medium>
|
||||
|
||||
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, is_favorite FROM media WHERE is_favorite = 1")
|
||||
fun getFavorites(): List<Medium>
|
||||
|
||||
@Query("SELECT full_path FROM media WHERE is_favorite = 1")
|
||||
fun getFavoritePaths(): List<String>
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED
|
|||
import com.simplemobiletools.commons.helpers.SORT_BY_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_PATH
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
|
||||
import com.simplemobiletools.gallery.helpers.FAVORITES
|
||||
import java.io.Serializable
|
||||
|
||||
@Entity(tableName = "directories", indices = [Index(value = "path", unique = true)])
|
||||
|
@ -36,4 +37,6 @@ data class Directory(
|
|||
sorting and SORT_BY_DATE_MODIFIED != 0 -> modified.formatDate()
|
||||
else -> taken.formatDate()
|
||||
}
|
||||
|
||||
fun areFavorites() = path == FAVORITES
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue