From 11de64f233151e5299c0710d9672bf1fe1b893ab Mon Sep 17 00:00:00 2001 From: grakovne Date: Wed, 18 Dec 2024 00:17:41 +0100 Subject: [PATCH] fix on hide items w/o tracks --- app/build.gradle.kts | 4 ++-- .../common/converter/LibraryPageResponseConverter.kt | 2 +- .../library/converter/LibrarySearchItemsConverter.kt | 2 +- .../podcast/converter/PodcastPageResponseConverter.kt | 2 +- .../podcast/converter/PodcastSearchItemsConverter.kt | 2 +- .../grakovne/lissen/common/NetworkQualityService.kt | 1 + .../lissen/ui/screens/library/LibraryScreen.kt | 10 ++++++++-- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0062f973..11cbc102 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -25,8 +25,8 @@ android { applicationId = "org.grakovne.lissen" minSdk = 28 targetSdk = 35 - versionCode = 52 - versionName = "1.1.21" + versionCode = 53 + versionName = "1.1.22" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/common/converter/LibraryPageResponseConverter.kt b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/common/converter/LibraryPageResponseConverter.kt index c9cfe31d..f05055f4 100644 --- a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/common/converter/LibraryPageResponseConverter.kt +++ b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/common/converter/LibraryPageResponseConverter.kt @@ -14,7 +14,7 @@ class LibraryPageResponseConverter @Inject constructor() { .mapNotNull { val title = it.media.metadata.title ?: return@mapNotNull null - val hasMediaItems = (it.media.numAudioFiles ?: 0) > 0 + val hasMediaItems = it.media.numAudioFiles?.let { it > 0 } ?: true if (hasMediaItems.not()) { return@mapNotNull null } diff --git a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/converter/LibrarySearchItemsConverter.kt b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/converter/LibrarySearchItemsConverter.kt index b3364393..5856cb87 100644 --- a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/converter/LibrarySearchItemsConverter.kt +++ b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/converter/LibrarySearchItemsConverter.kt @@ -11,7 +11,7 @@ class LibrarySearchItemsConverter @Inject constructor() { .mapNotNull { val title = it.media.metadata.title ?: return@mapNotNull null - val hasMediaItems = (it.media.numAudioFiles ?: 0) > 0 + val hasMediaItems = it.media.numAudioFiles?.let { it > 0 } ?: true if (hasMediaItems.not()) { return@mapNotNull null } diff --git a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastPageResponseConverter.kt b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastPageResponseConverter.kt index df58b51d..34a8e4e6 100644 --- a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastPageResponseConverter.kt +++ b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastPageResponseConverter.kt @@ -14,7 +14,7 @@ class PodcastPageResponseConverter @Inject constructor() { .mapNotNull { val title = it.media.metadata.title ?: return@mapNotNull null - val hasMediaItems = (it.media.numAudioFiles ?: 0) > 0 + val hasMediaItems = it.media.numAudioFiles?.let { it > 0 } ?: true if (hasMediaItems.not()) { return@mapNotNull null } diff --git a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastSearchItemsConverter.kt b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastSearchItemsConverter.kt index a3dc04bf..2c2770c5 100644 --- a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastSearchItemsConverter.kt +++ b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastSearchItemsConverter.kt @@ -12,7 +12,7 @@ class PodcastSearchItemsConverter @Inject constructor() { .mapNotNull { val title = it.media.metadata.title ?: return@mapNotNull null - val hasMediaItems = (it.media.numAudioFiles ?: 0) > 0 + val hasMediaItems = it.media.numAudioFiles?.let { it > 0 } ?: true if (hasMediaItems.not()) { return@mapNotNull null } diff --git a/app/src/main/java/org/grakovne/lissen/common/NetworkQualityService.kt b/app/src/main/java/org/grakovne/lissen/common/NetworkQualityService.kt index f0958f6a..818dfb0d 100644 --- a/app/src/main/java/org/grakovne/lissen/common/NetworkQualityService.kt +++ b/app/src/main/java/org/grakovne/lissen/common/NetworkQualityService.kt @@ -9,6 +9,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.distinctUntilChanged import javax.inject.Inject import javax.inject.Singleton diff --git a/app/src/main/java/org/grakovne/lissen/ui/screens/library/LibraryScreen.kt b/app/src/main/java/org/grakovne/lissen/ui/screens/library/LibraryScreen.kt index 9980428e..a7b0acae 100644 --- a/app/src/main/java/org/grakovne/lissen/ui/screens/library/LibraryScreen.kt +++ b/app/src/main/java/org/grakovne/lissen/ui/screens/library/LibraryScreen.kt @@ -38,6 +38,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext @@ -51,6 +52,7 @@ import androidx.paging.compose.collectAsLazyPagingItems import coil.ImageLoader import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.launch import org.grakovne.lissen.R import org.grakovne.lissen.channel.common.LibraryType @@ -129,8 +131,12 @@ fun LibraryScreen( } } - LaunchedEffect(networkStatus) { - refreshContent(false) + LaunchedEffect(Unit) { + snapshotFlow { networkStatus } + .distinctUntilChanged() + .collect { status -> + refreshContent(false) + } } LaunchedEffect(preparingError) {