couple improvements related to the Favorites folder

This commit is contained in:
tibbi 2018-06-20 15:44:39 +02:00
parent 556ec23a0c
commit 58877df88e
5 changed files with 22 additions and 4 deletions

View file

@ -613,6 +613,10 @@ 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
@ -656,6 +660,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
foldersToScan.remove(it.path) 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 // 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)
@ -721,7 +733,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
} }
val mediaTypes = curMedia.getDirMediaTypes() 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 firstItem = curMedia.first()
val lastItem = curMedia.last() val lastItem = curMedia.last()
@ -776,7 +788,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun checkInvalidDirectories(dirs: ArrayList<Directory>, directoryDao: DirectoryDao) { private fun checkInvalidDirectories(dirs: ArrayList<Directory>, directoryDao: DirectoryDao) {
val invalidDirs = ArrayList<Directory>() val invalidDirs = ArrayList<Directory>()
dirs.forEach { dirs.filter { !it.areFavorites() }.forEach {
if (!getDoesFilePathExist(it.path)) { if (!getDoesFilePathExist(it.path)) {
invalidDirs.add(it) invalidDirs.add(it)
} else if (it.path != config.tempFolderPath) { } else if (it.path != config.tempFolderPath) {

View file

@ -488,7 +488,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
private fun isDirEmpty(): Boolean { private fun isDirEmpty(): Boolean {
return if (mMedia.size <= 0 && config.filterMedia > 0) { return if (mPath != FAVORITES && mMedia.size <= 0 && config.filterMedia > 0) {
deleteDirectoryIfEmpty() deleteDirectoryIfEmpty()
deleteDBDirectory() deleteDBDirectory()
finish() finish()

View file

@ -356,7 +356,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
fun Context.removeInvalidDBDirectories(dirs: ArrayList<Directory>? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) { fun Context.removeInvalidDBDirectories(dirs: ArrayList<Directory>? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) {
val dirsToCheck = dirs ?: directoryDao.getAll() 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) directoryDao.deleteDirPath(it.path)
} }
} }

View file

@ -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") @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> 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") @Query("SELECT full_path FROM media WHERE is_favorite = 1")
fun getFavoritePaths(): List<String> fun getFavoritePaths(): List<String>

View file

@ -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_NAME
import com.simplemobiletools.commons.helpers.SORT_BY_PATH import com.simplemobiletools.commons.helpers.SORT_BY_PATH
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
import com.simplemobiletools.gallery.helpers.FAVORITES
import java.io.Serializable import java.io.Serializable
@Entity(tableName = "directories", indices = [Index(value = "path", unique = true)]) @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() sorting and SORT_BY_DATE_MODIFIED != 0 -> modified.formatDate()
else -> taken.formatDate() else -> taken.formatDate()
} }
fun areFavorites() = path == FAVORITES
} }