From 2534a14c4b47eb09a41e8514d6d81be2c3db29f5 Mon Sep 17 00:00:00 2001 From: sanao1006 Date: Thu, 5 Oct 2023 20:54:36 +0900 Subject: [PATCH] =?UTF-8?q?WIP:=20=E3=83=81=E3=83=A3=E3=83=B3=E3=83=8D?= =?UTF-8?q?=E3=83=AB=E4=B8=80=E8=A6=A7=E7=94=BB=E9=9D=A2=E3=82=92=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=83=8D=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../milktea/channel/ChannelListStatePage.kt | 31 +++++++++++++++++-- .../milktea/channel/ChannelViewModel.kt | 17 ++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/modules/features/channel/src/main/java/net/pantasystem/milktea/channel/ChannelListStatePage.kt b/modules/features/channel/src/main/java/net/pantasystem/milktea/channel/ChannelListStatePage.kt index b57d2faf1c..9f6922edc1 100644 --- a/modules/features/channel/src/main/java/net/pantasystem/milktea/channel/ChannelListStatePage.kt +++ b/modules/features/channel/src/main/java/net/pantasystem/milktea/channel/ChannelListStatePage.kt @@ -4,20 +4,28 @@ import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells +import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan +import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState import androidx.compose.material.CircularProgressIndicator import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.google.accompanist.swiperefresh.SwipeRefresh import com.google.accompanist.swiperefresh.rememberSwipeRefreshState +import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import net.pantasystem.milktea.common.PageableState import net.pantasystem.milktea.common.StateContent +import net.pantasystem.milktea.common.ui.isScrollToTheEnd import net.pantasystem.milktea.data.infrastructure.channel.ChannelListType import net.pantasystem.milktea.model.channel.Channel + @OptIn(ExperimentalFoundationApi::class) @Composable fun ChannelListStateScreen( @@ -27,7 +35,7 @@ fun ChannelListStateScreen( navigateToDetailView: (Channel.Id) -> Unit = {} ) { - + val scrollController = rememberLazyStaggeredGridState() val pagingState = uiState.getByType(listType) val swipeRefreshState = rememberSwipeRefreshState(isRefreshing = false) @@ -36,6 +44,16 @@ fun ChannelListStateScreen( viewModel.clearAndLoad(listType) } + LaunchedEffect(null) { + snapshotFlow { + scrollController.isScrollToTheEnd() + }.distinctUntilChanged().onEach { + if(it) { + viewModel.loadOld(listType) + } + }.launchIn(this) + } + SwipeRefresh( state = swipeRefreshState, onRefresh = { @@ -47,6 +65,7 @@ fun ChannelListStateScreen( LazyVerticalStaggeredGrid( columns = StaggeredGridCells.Adaptive(350.dp), modifier = Modifier.fillMaxSize(), + state = scrollController ) { when (val content = pagingState.content) { is StateContent.Exist -> { @@ -73,6 +92,14 @@ fun ChannelListStateScreen( } ) } + item(span = StaggeredGridItemSpan.FullLine){ + Row( + Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.Center + ) { + CircularProgressIndicator() + } + } } is StateContent.NotExist -> { item { @@ -113,4 +140,4 @@ fun ReachedElement() { ) { CircularProgressIndicator() } -} \ No newline at end of file +} diff --git a/modules/features/channel/src/main/java/net/pantasystem/milktea/channel/ChannelViewModel.kt b/modules/features/channel/src/main/java/net/pantasystem/milktea/channel/ChannelViewModel.kt index 13311f0251..9f2286f823 100644 --- a/modules/features/channel/src/main/java/net/pantasystem/milktea/channel/ChannelViewModel.kt +++ b/modules/features/channel/src/main/java/net/pantasystem/milktea/channel/ChannelViewModel.kt @@ -110,6 +110,23 @@ class ChannelViewModel @Inject constructor( } } + fun loadOld(type: ChannelListType) { + viewModelScope.launch { + val model = when (type) { + ChannelListType.OWNED -> ownedChannelPagingModel + ChannelListType.FOLLOWED -> followedChannelPagingModel + ChannelListType.FEATURED -> featuredChannelPagingModel + } + + PreviousPagingController( + model, + model, + model, + model, + ).loadPrevious() + } + } + fun follow(channelId: Channel.Id) { viewModelScope.launch { runCancellableCatching {