fix #2080, make sure Favorites and Recycle bin has priority at refreshing

This commit is contained in:
tibbi 2021-10-21 14:23:57 +02:00
parent 811d5e88c5
commit ff6de731c9
2 changed files with 28 additions and 7 deletions

View file

@ -943,13 +943,27 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
val dateTakens = mLastMediaFetcher!!.getDateTakens() val dateTakens = mLastMediaFetcher!!.getDateTakens()
if (config.showRecycleBinAtFolders && !config.showRecycleBinLast && !dirs.map { it.path }.contains(RECYCLE_BIN)) { if (config.showRecycleBinAtFolders && !config.showRecycleBinLast && !dirs.map { it.path }.contains(RECYCLE_BIN)) {
val recycleBin = Directory().apply { if (mediaDB.getDeletedMediaCount() > 0) {
path = RECYCLE_BIN val recycleBin = Directory().apply {
name = getString(R.string.recycle_bin) path = RECYCLE_BIN
location = LOCATION_INTERNAL name = getString(R.string.recycle_bin)
} location = LOCATION_INTERNAL
}
dirs.add(0, recycleBin) dirs.add(0, recycleBin)
}
}
if (dirs.map { it.path }.contains(FAVORITES)) {
if (mediaDB.getFavoritesCount() > 0) {
val favorites = Directory().apply {
path = FAVORITES
name = getString(R.string.favorites)
location = LOCATION_INTERNAL
}
dirs.add(0, favorites)
}
} }
try { try {
@ -1042,6 +1056,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
} }
val foldersToScan = mLastMediaFetcher!!.getFoldersToScan() val foldersToScan = mLastMediaFetcher!!.getFoldersToScan()
foldersToScan.remove(FAVORITES)
foldersToScan.add(0, FAVORITES) foldersToScan.add(0, FAVORITES)
if (config.showRecycleBinAtFolders) { if (config.showRecycleBinAtFolders) {
if (foldersToScan.contains(RECYCLE_BIN)) { if (foldersToScan.contains(RECYCLE_BIN)) {
@ -1054,7 +1069,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
foldersToScan.remove(RECYCLE_BIN) foldersToScan.remove(RECYCLE_BIN)
} }
dirs.filterNot { it.path == RECYCLE_BIN }.forEach { dirs.filterNot { it.path == RECYCLE_BIN || it.path == FAVORITES }.forEach {
foldersToScan.remove(it.path) foldersToScan.remove(it.path)
} }

View file

@ -15,9 +15,15 @@ interface MediumDao {
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts FROM media WHERE deleted_ts = 0 AND is_favorite = 1") @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts FROM media WHERE deleted_ts = 0 AND is_favorite = 1")
fun getFavorites(): List<Medium> fun getFavorites(): List<Medium>
@Query("SELECT COUNT(filename) FROM media WHERE deleted_ts = 0 AND is_favorite = 1")
fun getFavoritesCount(): Long
@Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts FROM media WHERE deleted_ts != 0") @Query("SELECT filename, full_path, parent_path, last_modified, date_taken, size, type, video_duration, is_favorite, deleted_ts FROM media WHERE deleted_ts != 0")
fun getDeletedMedia(): List<Medium> fun getDeletedMedia(): List<Medium>
@Query("SELECT COUNT(filename) FROM media WHERE deleted_ts != 0")
fun getDeletedMediaCount(): Long
@Insert(onConflict = REPLACE) @Insert(onConflict = REPLACE)
fun insert(medium: Medium) fun insert(medium: Medium)