From 121d899edddb01203dc2f305d413c7daa414619e Mon Sep 17 00:00:00 2001 From: grakovne Date: Sat, 21 Dec 2024 14:53:58 +0100 Subject: [PATCH] minor UI fixes --- .../lissen/ui/extensions/AsyncExtensions.kt | 3 ++- .../grakovne/lissen/ui/navigation/AppNavHost.kt | 2 +- .../lissen/ui/screens/library/LibraryScreen.kt | 15 ++++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/grakovne/lissen/ui/extensions/AsyncExtensions.kt b/app/src/main/java/org/grakovne/lissen/ui/extensions/AsyncExtensions.kt index 38d5f2e6..0a013335 100644 --- a/app/src/main/java/org/grakovne/lissen/ui/extensions/AsyncExtensions.kt +++ b/app/src/main/java/org/grakovne/lissen/ui/extensions/AsyncExtensions.kt @@ -1,6 +1,7 @@ package org.grakovne.lissen.ui.extensions import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlin.system.measureTimeMillis @@ -10,7 +11,7 @@ suspend fun CoroutineScope.withMinimumTime( ): T { var result: T val elapsedTime = measureTimeMillis { - result = block() + result = coroutineScope { block() } } val remainingTime = minimumTimeMillis - elapsedTime if (remainingTime > 0) { diff --git a/app/src/main/java/org/grakovne/lissen/ui/navigation/AppNavHost.kt b/app/src/main/java/org/grakovne/lissen/ui/navigation/AppNavHost.kt index fe04f795..71c271bf 100644 --- a/app/src/main/java/org/grakovne/lissen/ui/navigation/AppNavHost.kt +++ b/app/src/main/java/org/grakovne/lissen/ui/navigation/AppNavHost.kt @@ -29,8 +29,8 @@ import org.grakovne.lissen.ui.screens.player.PlayerScreen import org.grakovne.lissen.ui.screens.settings.SettingsScreen import org.grakovne.lissen.ui.screens.settings.advanced.CustomHeadersSettingsScreen -@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") @Composable +@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") fun AppNavHost( navController: NavHostController, preferences: LissenSharedPreferences, 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 e43789b0..a736058b 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 @@ -104,13 +104,18 @@ fun LibraryScreen( libraryViewModel.dismissSearch() } - fun refreshContent(showRefreshing: Boolean) { + fun refreshContent(showPullRefreshing: Boolean) { coroutineScope.launch { - if (showRefreshing) { + if (showPullRefreshing) { pullRefreshing = true } - withMinimumTime(500) { + val minimumTime = when (showPullRefreshing) { + true -> 500L + false -> 0L + } + + withMinimumTime(minimumTime) { listOf( async { libraryViewModel.refreshLibrary() }, async { libraryViewModel.fetchRecentListening() }, @@ -140,7 +145,7 @@ fun LibraryScreen( val pullRefreshState = rememberPullRefreshState( refreshing = pullRefreshing, onRefresh = { - refreshContent(showRefreshing = true) + refreshContent(showPullRefreshing = true) }, ) @@ -216,7 +221,7 @@ fun LibraryScreen( navController = navController, contentCachingModelView = contentCachingModelView, playerViewModel = playerViewModel, - onContentRefreshing = { refreshContent(showRefreshing = false) }, + onContentRefreshing = { refreshContent(showPullRefreshing = false) }, onSearchRequested = { libraryViewModel.requestSearch() }, ) }