Skip to content

Commit

Permalink
Reduce timing between page nav
Browse files Browse the repository at this point in the history
  • Loading branch information
jocmp committed Dec 15, 2024
1 parent 5d4f040 commit 368a642
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
46 changes: 27 additions & 19 deletions app/src/main/java/com/capyreader/app/ui/articles/ArticleLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fun ArticleLayout(
feeds: List<Feed>,
allFeeds: List<Feed>,
allFolders: List<Folder>,
pagingArticles: LazyPagingItems<Article>,
articles: LazyPagingItems<Article>,
article: Article?,
search: ArticleSearch,
statusCount: Long,
Expand Down Expand Up @@ -126,9 +126,7 @@ fun ArticleLayout(
}

val webViewState = rememberWebViewState(
onNavigateToMedia = {
media = it
},
onNavigateToMedia = { media = it },
)

fun scrollToArticle(index: Int) {
Expand All @@ -152,12 +150,12 @@ fun ArticleLayout(

suspend fun openNextStatus(action: suspend () -> Unit) {
listVisible = false
delay(200)
delay(150)
action()
scaffoldNavigator.navigateTo(ListDetailPaneScaffoldRole.List)

coroutineScope.launch {
delay(500)
delay(300)
if (!listVisible) {
resetListVisibility()
}
Expand Down Expand Up @@ -201,7 +199,7 @@ fun ArticleLayout(
}
}

val refreshFeeds = {
fun refreshFeeds() {
isRefreshing = true
onFeedRefresh {
isRefreshing = false
Expand All @@ -215,8 +213,9 @@ fun ArticleLayout(

fun openNextList(action: suspend () -> Unit) {
coroutineScope.launchUI {
openNextStatus(action)
listVisible = false
drawerState.close()
openNextStatus(action)
}
}

Expand All @@ -230,12 +229,18 @@ fun ArticleLayout(
}
}

val closeDrawer = {
coroutineScope.launch {
fun closeDrawer() {
coroutineScope.launchUI {
drawerState.close()
}
}

fun openDrawer() {
coroutineScope.launchUI {
drawerState.open()
}
}

val showSnackbar = { message: String ->
coroutineScope.launch {
snackbarHost.showSnackbar(
Expand All @@ -254,7 +259,7 @@ fun ArticleLayout(
}
}

val selectArticle = { articleID: String ->
fun selectArticle(articleID: String) {
onSelectArticle(articleID)
if (search.isActive) {
focusManager.clearFocus()
Expand Down Expand Up @@ -334,9 +339,7 @@ fun ArticleLayout(
scrollToTop()
},
onNavigateToDrawer = {
coroutineScope.launch {
drawerState.open()
}
openDrawer()
},
onRequestSnackbar = { showSnackbar(it) },
onRemoveFeed = onRemoveFeed,
Expand All @@ -360,8 +363,12 @@ fun ArticleLayout(
) { innerPadding ->
PullToRefreshBox(
isRefreshing = isRefreshing,
onRefresh = refreshFeeds,
modifier = Modifier.padding(innerPadding)
onRefresh = {
refreshFeeds()
},
modifier = Modifier
.fillMaxSize()
.padding(innerPadding)
) {
if (isInitialized && !isRefreshing && allFeeds.isEmpty()) {
EmptyOnboardingView {
Expand All @@ -373,6 +380,7 @@ fun ArticleLayout(
}
} else {
PullToNextFeedBox(
modifier = Modifier.fillMaxSize(),
enabled = canSwipeToNextFeed,
onRequestNext = {
requestNextFeed()
Expand All @@ -385,7 +393,7 @@ fun ArticleLayout(
modifier = Modifier.fillMaxSize(),
) {
ArticleList(
articles = pagingArticles,
articles = articles,
selectedArticleKey = article?.id,
listState = listState,
onMarkAllRead = { range ->
Expand All @@ -410,7 +418,7 @@ fun ArticleLayout(
}
} else if (article != null) {
val indexedArticles =
rememberIndexedArticles(article = article, articles = pagingArticles)
rememberIndexedArticles(article = article, articles = articles)

ArticleView(
article = article,
Expand Down Expand Up @@ -493,7 +501,7 @@ fun ArticleLayout(
toggleDrawer()
}

LaunchedEffect(pagingArticles.itemCount) {
LaunchedEffect(articles.itemCount) {
if (!listVisible) {
resetListVisibility()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun ArticleScreen(
feeds = feeds,
allFolders = allFolders,
allFeeds = allFeeds,
pagingArticles = articles,
articles = articles,
article = viewModel.article,
statusCount = statusCount,
refreshInterval = appPreferences.refreshInterval.get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.capyreader.app.ui.articles.list

import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import com.capyreader.app.ui.components.pullrefresh.SwipeRefresh

@Composable
fun PullToNextFeedBox(
modifier: Modifier = Modifier,
enabled: Boolean = true,
onRequestNext: () -> Unit,
content: @Composable () -> Unit,
Expand All @@ -23,6 +25,7 @@ fun PullToNextFeedBox(
swipeEnabled = enabled,
onTriggerThreshold = { triggerThreshold() },
indicatorAlignment = Alignment.BottomCenter,
modifier = modifier,
) {
content()
}
Expand Down

0 comments on commit 368a642

Please sign in to comment.