Fix crash on random button click with empty list

This commit is contained in:
FooIbar committed 2024-09-05 20:53:00 +08:00
1 parent 154c7f3710
commit 9c9b8b74cd
3 files changed
+7 -4

No files matched your search

@@ -27,7 +27,7 @@ interface LocalFavoritesDao {
fun joinListLazy(title: String): PagingSource<Int, BaseGalleryInfo>
@Query("SELECT GALLERIES.* FROM LOCAL_FAVORITES JOIN GALLERIES USING(GID) ORDER BY RANDOM() LIMIT 1")
suspend fun random(): BaseGalleryInfo
suspend fun random(): BaseGalleryInfo?
@Query("SELECT EXISTS(SELECT * FROM LOCAL_FAVORITES WHERE GID = :gid)")
suspend fun contains(gid: Long): Boolean
@@ -648,7 +648,9 @@ fun AnimatedVisibilityScope.DownloadsScreen(navigator: DestinationsNavigator) =
) {
if (!selectMode) {
onClick(Icons.Default.Shuffle) {
withUIContext { navToReader(list.random().galleryInfo) }
if (list.isNotEmpty()) {
withUIContext { navToReader(list.random().galleryInfo) }
}
}
onClick(Icons.AutoMirrored.Default.Sort) {
val oldMode = SortMode.from(sortMode)
@@ -356,8 +356,9 @@ fun AnimatedVisibilityScope.FavouritesScreen(navigator: DestinationsNavigator) =
if (!selectMode) {
if (isLocalFav) {
onClick(Icons.Default.Shuffle) {
val random = EhDB.randomLocalFav()
withUIContext { navigate(random.asDst()) }
EhDB.randomLocalFav()?.let { info ->
withUIContext { navigate(info.asDst()) }
}
}
}
onClick(EhIcons.Default.GoTo) {