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 a33b95156c..6fd136a321 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 @@ -107,6 +107,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 {