Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated SwipeRefresh with recomended PullRefreshIndicator and implement pull to refresh for Feeds Page. #850

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Flow Page: replace SwipeRefresh with PullRefreshIndicator.
  • Loading branch information
Will McCall committed Oct 8, 2024
commit d5f504cc497fedc0a7f86c2339b12149dd32a4ab
31 changes: 21 additions & 10 deletions app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt
Original file line number Diff line number Diff line change
@@ -1,6 1,7 @@
package me.ash.reader.ui.page.home.flow

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -10,10 11,14 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
import androidx.compose.material.icons.rounded.DoneAll
import androidx.compose.material.icons.rounded.Search
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
Expand All @@ -24,6 29,8 @@ 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.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -55,13 62,12 @@ import me.ash.reader.ui.component.base.DisplayText
import me.ash.reader.ui.component.base.FeedbackIconButton
import me.ash.reader.ui.component.base.RYExtensibleVisibility
import me.ash.reader.ui.component.base.RYScaffold
import me.ash.reader.ui.component.base.SwipeRefresh
import me.ash.reader.ui.ext.collectAsStateValue
import me.ash.reader.ui.page.common.RouteName
import me.ash.reader.ui.page.home.HomeViewModel

@OptIn(
androidx.compose.ui.ExperimentalComposeUiApi::class,
ExperimentalMaterialApi::class,
)
@Composable
fun FlowPage(
Expand Down Expand Up @@ -94,8 100,17 @@ fun FlowPage(
var onSearch by remember { mutableStateOf(false) }

val owner = LocalLifecycleOwner.current

val syncingScope = rememberCoroutineScope()
var isSyncing by remember { mutableStateOf(false) }

fun doSync() = syncingScope.launch {
isSyncing = true
flowViewModel.sync()
}

val syncingPullRefreshState = rememberPullRefreshState(isSyncing, ::doSync)

DisposableEffect(owner) {
homeViewModel.syncWorkLiveData.observe(owner) { workInfoList ->
workInfoList.let {
Expand Down Expand Up @@ -242,13 257,7 @@ fun FlowPage(
}
},
content = {
SwipeRefresh(
onRefresh = {
if (!isSyncing) {
flowViewModel.sync()
}
}
) {
Box(Modifier.pullRefresh(syncingPullRefreshState)) {
var showMenu by remember { mutableStateOf(false) }
LazyColumn(
modifier = Modifier.fillMaxSize(),
Expand All @@ -262,7 271,7 @@ fun FlowPage(
filterUiState.feed != null -> filterUiState.feed.name
else -> filterUiState.filter.toName()
},
desc = if (isSyncing) stringResource(R.string.syncing) else "",
desc = "",
)
RYExtensibleVisibility(visible = markAsRead) {
Spacer(modifier = Modifier.height((56 24 10).dp))
Expand Down Expand Up @@ -340,6 349,8 @@ fun FlowPage(
Spacer(modifier = Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars))
}
}

PullRefreshIndicator(isSyncing, syncingPullRefreshState, Modifier.align(Alignment.TopCenter))
}
},
bottomBar = {
Expand Down