Skip to content

Commit

Permalink
refactor: Reuse FeedOrderListItem
Browse files Browse the repository at this point in the history
  • Loading branch information
cuong-tran committed Sep 15, 2024
1 parent b0d03c7 commit 562fe6d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ fun FeedOrderScreen(
onClickMoveUp: (FeedSavedSearch) -> Unit,
onClickMoveDown: (FeedSavedSearch) -> Unit,
) {
val lazyListState = rememberLazyListState()
when {
state.isLoading -> LoadingScreen()
state.isEmpty -> EmptyScreen(
stringRes = MR.strings.empty_screen,
)

else -> {
val lazyListState = rememberLazyListState()
val feeds = state.items ?: emptyList()
LazyColumn(
state = lazyListState,
Expand All @@ -46,8 +46,7 @@ fun FeedOrderScreen(
) { index, feed ->
FeedOrderListItem(
modifier = Modifier.animateItem(),
feed = feed,
sourceFeed = null,
title = feed.title,
canMoveUp = index != 0,
canMoveDown = index != feeds.lastIndex,
onMoveUp = { onClickMoveUp(feed.feed) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ fun SourceFeedOrderScreen(
)
},
) { paddingValues ->
val lazyListState = rememberLazyListState()
when {
state.isLoading -> LoadingScreen()
state.items
Expand All @@ -66,6 +65,7 @@ fun SourceFeedOrderScreen(
)

else -> {
val lazyListState = rememberLazyListState()
val feeds = state.items
.filterIsInstance<SourceFeedUI.SourceSavedSearch>()
LazyColumn(
Expand All @@ -80,8 +80,7 @@ fun SourceFeedOrderScreen(
) { index, feed ->
FeedOrderListItem(
modifier = Modifier.animateItem(),
feed = null,
sourceFeed = feed,
title = feed.title,
canMoveUp = index != 0,
canMoveDown = index != feeds.lastIndex,
onMoveUp = { onClickMoveUp(feed.feed) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import eu.kanade.presentation.browse.FeedItemUI
import eu.kanade.presentation.browse.SourceFeedUI
import tachiyomi.domain.source.model.FeedSavedSearch
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.components.material.padding
import tachiyomi.presentation.core.i18n.stringResource

@Composable
fun FeedOrderListItem(
feed: FeedItemUI?,
sourceFeed: SourceFeedUI.SourceSavedSearch?,
title: String,
canMoveUp: Boolean,
canMoveDown: Boolean,
onMoveUp: () -> Unit,
Expand All @@ -54,7 +50,7 @@ fun FeedOrderListItem(
contentDescription = null,
)
Text(
text = feed?.title ?: sourceFeed?.title ?: "",
text = title,
modifier = Modifier
.padding(start = MaterialTheme.padding.medium),
)
Expand Down Expand Up @@ -84,21 +80,7 @@ fun FeedOrderListItem(
@Composable
private fun FeedOrderListItemPreview() {
FeedOrderListItem(
feed = FeedItemUI(
feed = FeedSavedSearch(
id = 1,
source = 1,
savedSearch = null,
global = false,
feedOrder = 0,
),
title = "Feed 1",
subtitle = "Source 1",
results = null,
savedSearch = null,
source = null,
),
sourceFeed = null,
title = "Feed 1",
canMoveUp = true,
canMoveDown = true,
onMoveUp = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fun FeedActionsDialog(

@Preview
@Composable
private fun FeedItemPreview() {
private fun FeedActionsDialogPreview() {
FeedActionsDialog(
feed = FeedSavedSearch(
id = 1,
Expand Down

0 comments on commit 562fe6d

Please sign in to comment.