Skip to content

Commit

Permalink
minor UI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GrakovNe committed Dec 21, 2024
1 parent 708ec44 commit 121d899
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,7 +11,7 @@ suspend fun <T> CoroutineScope.withMinimumTime(
): T {
var result: T
val elapsedTime = measureTimeMillis {
result = block()
result = coroutineScope { block() }
}
val remainingTime = minimumTimeMillis - elapsedTime
if (remainingTime > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() },
Expand Down Expand Up @@ -140,7 +145,7 @@ fun LibraryScreen(
val pullRefreshState = rememberPullRefreshState(
refreshing = pullRefreshing,
onRefresh = {
refreshContent(showRefreshing = true)
refreshContent(showPullRefreshing = true)
},
)

Expand Down Expand Up @@ -216,7 +221,7 @@ fun LibraryScreen(
navController = navController,
contentCachingModelView = contentCachingModelView,
playerViewModel = playerViewModel,
onContentRefreshing = { refreshContent(showRefreshing = false) },
onContentRefreshing = { refreshContent(showPullRefreshing = false) },
onSearchRequested = { libraryViewModel.requestSearch() },
)
}
Expand Down

0 comments on commit 121d899

Please sign in to comment.