diff --git a/app/src/main/java/me/ash/reader/ui/page/home/flow/ArticleList.kt b/app/src/main/java/me/ash/reader/ui/page/home/flow/ArticleList.kt index 2fa9e97..c1cd135 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/flow/ArticleList.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/flow/ArticleList.kt @@ -15,21 +15,22 @@ fun LazyListScope.ArticleList( pagingItems: LazyPagingItems, onClick: (ArticleWithFeed) -> Unit = {}, ) { - for (itemIndex in 0 until pagingItems.itemCount) { - when (val item = pagingItems[itemIndex]) { + for (index in 0 until pagingItems.itemCount) { + when (val item = pagingItems.peek(index)) { is FlowItemView.Article -> { - item { + item(key = item.articleWithFeed.article.id) { ArticleItem( - articleWithFeed = item.articleWithFeed, + articleWithFeed = (pagingItems[index] as FlowItemView.Article).articleWithFeed, ) { onClick(it) } } } is FlowItemView.Date -> { - if (itemIndex != 0) item { Spacer(modifier = Modifier.height(40.dp)) } + val separator = pagingItems[index] as FlowItemView.Date + if (separator.showSpacer) item { Spacer(modifier = Modifier.height(40.dp)) } stickyHeader { - StickyHeader(item.date) + StickyHeader(separator.date) } } else -> {} diff --git a/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt b/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt index 7d869c2..990c17d 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt @@ -6,6 +6,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.icons.Icons import androidx.compose.material.icons.rounded.ArrowBack import androidx.compose.material.icons.rounded.DoneAll @@ -63,6 +64,7 @@ fun FlowPage( var onSearch by remember { mutableStateOf(false) } val viewState = flowViewModel.viewState.collectAsStateValue() val pagingItems = viewState.pagingData.collectAsLazyPagingItems() + val listState = if (pagingItems.itemCount > 0) viewState.listState else rememberLazyListState() val owner = LocalLifecycleOwner.current var isSyncing by remember { mutableStateOf(false) } @@ -176,7 +178,7 @@ fun FlowPage( ) { LazyColumn( modifier = Modifier.fillMaxSize(), - state = viewState.listState, + state = listState, ) { item { DisplayTextHeader(filterState, isSyncing) diff --git a/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowViewModel.kt index 5b8d7ac..2b0d893 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowViewModel.kt @@ -74,7 +74,7 @@ class FlowViewModel @Inject constructor( val afterDate = stringsRepository.formatAsString(after?.articleWithFeed?.article?.date) if (beforeDate != afterDate) { - afterDate?.let { FlowItemView.Date(it) } + afterDate?.let { FlowItemView.Date(it, beforeDate != null) } } else { null } @@ -102,7 +102,7 @@ class FlowViewModel @Inject constructor( val afterDate = stringsRepository.formatAsString(after?.articleWithFeed?.article?.date) if (beforeDate != afterDate) { - afterDate?.let { FlowItemView.Date(it) } + afterDate?.let { FlowItemView.Date(it, beforeDate != null) } } else { null } @@ -212,5 +212,5 @@ enum class MarkAsReadBefore { sealed class FlowItemView { class Article(val articleWithFeed: ArticleWithFeed) : FlowItemView() - class Date(val date: String) : FlowItemView() + class Date(val date: String, val showSpacer: Boolean) : FlowItemView() } \ No newline at end of file