From 9b77759f2496ef98c10b7dd7cf385b7be75313ef Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 5 Mar 2023 18:41:08 -0500 Subject: [PATCH] Use stricter visibility for composables where possible --- .../presentation/browse/GlobalSearchScreen.kt | 2 +- .../browse/MigrateSearchScreen.kt | 2 +- .../browse/{ => components}/BrowseBadges.kt | 4 +- .../components/BrowseSourceComfortableGrid.kt | 3 +- .../components/BrowseSourceCompactGrid.kt | 1 - .../browse/components/BrowseSourceList.kt | 3 +- .../components/BrowseSourceLoadingItem.kt | 2 +- .../browse/components/GlobalSearchCard.kt | 33 ----- .../browse/components/GlobalSearchCardRow.kt | 29 ++++ .../presentation/category/CategoryScreen.kt | 39 ++++- .../category/ChangeCategoryDialog.kt | 134 ------------------ .../category/components/CategoryContent.kt | 45 ------ .../category/components/CategoryDialogs.kt | 123 +++++++++++++++- .../presentation/history/HistoryScreen.kt | 62 +++++++- .../history/components/HistoryContent.kt | 64 --------- .../{HistoryDialog.kt => HistoryDialogs.kt} | 0 .../library/components/GlobalSearchItem.kt | 2 +- .../library/components/LazyLibraryGrid.kt | 4 +- .../library/components/LibraryBadges.kt | 6 +- .../components/LibraryComfortableGrid.kt | 2 +- .../library/components/LibraryCompactGrid.kt | 2 +- .../library/components/LibraryList.kt | 2 +- .../library/components/LibraryTabs.kt | 2 +- .../library/components/LibraryToolbar.kt | 4 +- .../presentation/updates/UpdatesUiItem.kt | 6 +- .../source/browse/BrowseSourceScreen.kt | 2 +- .../kanade/tachiyomi/ui/library/LibraryTab.kt | 2 +- .../kanade/tachiyomi/ui/manga/MangaScreen.kt | 2 +- 28 files changed, 274 insertions(+), 308 deletions(-) rename app/src/main/java/eu/kanade/presentation/browse/{ => components}/BrowseBadges.kt (77%) delete mode 100644 app/src/main/java/eu/kanade/presentation/browse/components/GlobalSearchCard.kt delete mode 100644 app/src/main/java/eu/kanade/presentation/category/ChangeCategoryDialog.kt delete mode 100644 app/src/main/java/eu/kanade/presentation/category/components/CategoryContent.kt delete mode 100644 app/src/main/java/eu/kanade/presentation/history/components/HistoryContent.kt rename app/src/main/java/eu/kanade/presentation/history/components/{HistoryDialog.kt => HistoryDialogs.kt} (100%) diff --git a/app/src/main/java/eu/kanade/presentation/browse/GlobalSearchScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/GlobalSearchScreen.kt index f5ba91e429..8bcccfb65c 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/GlobalSearchScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/GlobalSearchScreen.kt @@ -59,7 +59,7 @@ fun GlobalSearchScreen( } @Composable -fun GlobalSearchContent( +private fun GlobalSearchContent( items: Map, contentPadding: PaddingValues, getManga: @Composable (CatalogueSource, Manga) -> State, diff --git a/app/src/main/java/eu/kanade/presentation/browse/MigrateSearchScreen.kt b/app/src/main/java/eu/kanade/presentation/browse/MigrateSearchScreen.kt index de22711a51..e33da5742d 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/MigrateSearchScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/MigrateSearchScreen.kt @@ -54,7 +54,7 @@ fun MigrateSearchScreen( } @Composable -fun MigrateSearchContent( +private fun MigrateSearchContent( sourceId: Long, items: Map, contentPadding: PaddingValues, diff --git a/app/src/main/java/eu/kanade/presentation/browse/BrowseBadges.kt b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseBadges.kt similarity index 77% rename from app/src/main/java/eu/kanade/presentation/browse/BrowseBadges.kt rename to app/src/main/java/eu/kanade/presentation/browse/components/BrowseBadges.kt index 00adfba350..19ec4b55ad 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/BrowseBadges.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseBadges.kt @@ -1,4 +1,4 @@ -package eu.kanade.presentation.browse +package eu.kanade.presentation.browse.components import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.CollectionsBookmark @@ -6,7 +6,7 @@ import androidx.compose.runtime.Composable import tachiyomi.presentation.core.components.Badge @Composable -fun InLibraryBadge(enabled: Boolean) { +internal fun InLibraryBadge(enabled: Boolean) { if (enabled) { Badge( imageVector = Icons.Outlined.CollectionsBookmark, diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceComfortableGrid.kt b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceComfortableGrid.kt index 88f4f72720..77cec7c6c0 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceComfortableGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceComfortableGrid.kt @@ -11,7 +11,6 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.unit.dp import androidx.paging.LoadState import androidx.paging.compose.LazyPagingItems -import eu.kanade.presentation.browse.InLibraryBadge import eu.kanade.presentation.library.components.CommonMangaItemDefaults import eu.kanade.presentation.library.components.MangaComfortableGridItem import kotlinx.coroutines.flow.StateFlow @@ -57,7 +56,7 @@ fun BrowseSourceComfortableGrid( } @Composable -fun BrowseSourceComfortableGridItem( +private fun BrowseSourceComfortableGridItem( manga: Manga, onClick: () -> Unit = {}, onLongClick: () -> Unit = onClick, diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceCompactGrid.kt b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceCompactGrid.kt index 7a61402aac..d5ce6fc4cf 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceCompactGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceCompactGrid.kt @@ -11,7 +11,6 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.unit.dp import androidx.paging.LoadState import androidx.paging.compose.LazyPagingItems -import eu.kanade.presentation.browse.InLibraryBadge import eu.kanade.presentation.library.components.CommonMangaItemDefaults import eu.kanade.presentation.library.components.MangaCompactGridItem import kotlinx.coroutines.flow.StateFlow diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceList.kt b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceList.kt index 64d3dd7ebd..5703386ce1 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceList.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceList.kt @@ -8,7 +8,6 @@ import androidx.compose.ui.unit.dp import androidx.paging.LoadState import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.items -import eu.kanade.presentation.browse.InLibraryBadge import eu.kanade.presentation.library.components.CommonMangaItemDefaults import eu.kanade.presentation.library.components.MangaListItem import kotlinx.coroutines.flow.StateFlow @@ -52,7 +51,7 @@ fun BrowseSourceList( } @Composable -fun BrowseSourceListItem( +private fun BrowseSourceListItem( manga: Manga, onClick: () -> Unit = {}, onLongClick: () -> Unit = onClick, diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceLoadingItem.kt b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceLoadingItem.kt index 2ecf8539ba..fc120ac769 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceLoadingItem.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/BrowseSourceLoadingItem.kt @@ -10,7 +10,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp @Composable -fun BrowseSourceLoadingItem() { +internal fun BrowseSourceLoadingItem() { Row( modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/GlobalSearchCard.kt b/app/src/main/java/eu/kanade/presentation/browse/components/GlobalSearchCard.kt deleted file mode 100644 index 0a9bd1037f..0000000000 --- a/app/src/main/java/eu/kanade/presentation/browse/components/GlobalSearchCard.kt +++ /dev/null @@ -1,33 +0,0 @@ -package eu.kanade.presentation.browse.components - -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.width -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.dp -import eu.kanade.presentation.browse.InLibraryBadge -import eu.kanade.presentation.library.components.CommonMangaItemDefaults -import eu.kanade.presentation.library.components.MangaComfortableGridItem -import tachiyomi.domain.manga.model.MangaCover - -@Composable -fun GlobalSearchCard( - title: String, - cover: MangaCover, - isFavorite: Boolean, - onClick: () -> Unit, - onLongClick: () -> Unit, -) { - Box(modifier = Modifier.width(96.dp)) { - MangaComfortableGridItem( - title = title, - coverData = cover, - coverBadgeStart = { - InLibraryBadge(enabled = isFavorite) - }, - coverAlpha = if (isFavorite) CommonMangaItemDefaults.BrowseFavoriteCoverAlpha else 1f, - onClick = onClick, - onLongClick = onLongClick, - ) - } -} diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/GlobalSearchCardRow.kt b/app/src/main/java/eu/kanade/presentation/browse/components/GlobalSearchCardRow.kt index 03d5df9e9f..f094d6b985 100644 --- a/app/src/main/java/eu/kanade/presentation/browse/components/GlobalSearchCardRow.kt +++ b/app/src/main/java/eu/kanade/presentation/browse/components/GlobalSearchCardRow.kt @@ -1,14 +1,21 @@ package eu.kanade.presentation.browse.components import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.State import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import eu.kanade.presentation.library.components.CommonMangaItemDefaults +import eu.kanade.presentation.library.components.MangaComfortableGridItem import tachiyomi.domain.manga.model.Manga +import tachiyomi.domain.manga.model.MangaCover import tachiyomi.domain.manga.model.asMangaCover import tachiyomi.presentation.core.components.material.padding @@ -35,3 +42,25 @@ fun GlobalSearchCardRow( } } } + +@Composable +private fun GlobalSearchCard( + title: String, + cover: MangaCover, + isFavorite: Boolean, + onClick: () -> Unit, + onLongClick: () -> Unit, +) { + Box(modifier = Modifier.width(96.dp)) { + MangaComfortableGridItem( + title = title, + coverData = cover, + coverBadgeStart = { + InLibraryBadge(enabled = isFavorite) + }, + coverAlpha = if (isFavorite) CommonMangaItemDefaults.BrowseFavoriteCoverAlpha else 1f, + onClick = onClick, + onLongClick = onLongClick, + ) + } +} diff --git a/app/src/main/java/eu/kanade/presentation/category/CategoryScreen.kt b/app/src/main/java/eu/kanade/presentation/category/CategoryScreen.kt index 2d712ef790..b33325deb3 100644 --- a/app/src/main/java/eu/kanade/presentation/category/CategoryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/category/CategoryScreen.kt @@ -1,18 +1,22 @@ package eu.kanade.presentation.category +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyListState +import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource -import eu.kanade.presentation.category.components.CategoryContent import eu.kanade.presentation.category.components.CategoryFloatingActionButton +import eu.kanade.presentation.category.components.CategoryListItem import eu.kanade.presentation.components.AppBar import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.category.CategoryScreenState import tachiyomi.domain.category.model.Category +import tachiyomi.presentation.core.components.LazyColumn import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.components.material.padding import tachiyomi.presentation.core.components.material.topSmallPaddingValues @@ -64,3 +68,36 @@ fun CategoryScreen( ) } } + +@Composable +private fun CategoryContent( + categories: List, + lazyListState: LazyListState, + paddingValues: PaddingValues, + onClickRename: (Category) -> Unit, + onClickDelete: (Category) -> Unit, + onMoveUp: (Category) -> Unit, + onMoveDown: (Category) -> Unit, +) { + LazyColumn( + state = lazyListState, + contentPadding = paddingValues, + verticalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small), + ) { + itemsIndexed( + items = categories, + key = { _, category -> "category-${category.id}" }, + ) { index, category -> + CategoryListItem( + modifier = Modifier.animateItemPlacement(), + category = category, + canMoveUp = index != 0, + canMoveDown = index != categories.lastIndex, + onMoveUp = onMoveUp, + onMoveDown = onMoveDown, + onRename = { onClickRename(category) }, + onDelete = { onClickDelete(category) }, + ) + } + } +} diff --git a/app/src/main/java/eu/kanade/presentation/category/ChangeCategoryDialog.kt b/app/src/main/java/eu/kanade/presentation/category/ChangeCategoryDialog.kt deleted file mode 100644 index 68f073f9e1..0000000000 --- a/app/src/main/java/eu/kanade/presentation/category/ChangeCategoryDialog.kt +++ /dev/null @@ -1,134 +0,0 @@ -package eu.kanade.presentation.category - -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.AlertDialog -import androidx.compose.material3.Checkbox -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.material3.TriStateCheckbox -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import eu.kanade.core.preference.asToggleableState -import eu.kanade.tachiyomi.R -import tachiyomi.core.preference.CheckboxState -import tachiyomi.domain.category.model.Category -import tachiyomi.presentation.core.components.material.TextButton -import tachiyomi.presentation.core.components.material.padding - -@Composable -fun ChangeCategoryDialog( - initialSelection: List>, - onDismissRequest: () -> Unit, - onEditCategories: () -> Unit, - onConfirm: (List, List) -> Unit, -) { - if (initialSelection.isEmpty()) { - AlertDialog( - onDismissRequest = onDismissRequest, - confirmButton = { - TextButton( - onClick = { - onDismissRequest() - onEditCategories() - }, - ) { - Text(text = stringResource(R.string.action_edit_categories)) - } - }, - title = { - Text(text = stringResource(R.string.action_move_category)) - }, - text = { - Text(text = stringResource(R.string.information_empty_category_dialog)) - }, - ) - return - } - var selection by remember { mutableStateOf(initialSelection) } - AlertDialog( - onDismissRequest = onDismissRequest, - confirmButton = { - Row { - TextButton(onClick = { - onDismissRequest() - onEditCategories() - },) { - Text(text = stringResource(R.string.action_edit)) - } - Spacer(modifier = Modifier.weight(1f)) - TextButton(onClick = onDismissRequest) { - Text(text = stringResource(R.string.action_cancel)) - } - TextButton( - onClick = { - onDismissRequest() - onConfirm( - selection.filter { it is CheckboxState.State.Checked || it is CheckboxState.TriState.Include }.map { it.value.id }, - selection.filter { it is CheckboxState.State.None || it is CheckboxState.TriState.None }.map { it.value.id }, - ) - }, - ) { - Text(text = stringResource(android.R.string.ok)) - } - } - }, - title = { - Text(text = stringResource(R.string.action_move_category)) - }, - text = { - Column( - modifier = Modifier.verticalScroll(rememberScrollState()), - ) { - selection.forEach { checkbox -> - val onChange: (CheckboxState) -> Unit = { - val index = selection.indexOf(it) - if (index != -1) { - val mutableList = selection.toMutableList() - mutableList[index] = it.next() - selection = mutableList.toList() - } - } - Row( - modifier = Modifier - .fillMaxWidth() - .clickable { onChange(checkbox) }, - verticalAlignment = Alignment.CenterVertically, - ) { - when (checkbox) { - is CheckboxState.TriState -> { - TriStateCheckbox( - state = checkbox.asToggleableState(), - onClick = { onChange(checkbox) }, - ) - } - is CheckboxState.State -> { - Checkbox( - checked = checkbox.isChecked, - onCheckedChange = { onChange(checkbox) }, - ) - } - } - - Text( - text = checkbox.value.visualName, - modifier = Modifier.padding(horizontal = MaterialTheme.padding.medium), - ) - } - } - } - }, - ) -} diff --git a/app/src/main/java/eu/kanade/presentation/category/components/CategoryContent.kt b/app/src/main/java/eu/kanade/presentation/category/components/CategoryContent.kt deleted file mode 100644 index b8a72c9ada..0000000000 --- a/app/src/main/java/eu/kanade/presentation/category/components/CategoryContent.kt +++ /dev/null @@ -1,45 +0,0 @@ -package eu.kanade.presentation.category.components - -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.foundation.lazy.itemsIndexed -import androidx.compose.material3.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import tachiyomi.domain.category.model.Category -import tachiyomi.presentation.core.components.LazyColumn -import tachiyomi.presentation.core.components.material.padding - -@Composable -fun CategoryContent( - categories: List, - lazyListState: LazyListState, - paddingValues: PaddingValues, - onClickRename: (Category) -> Unit, - onClickDelete: (Category) -> Unit, - onMoveUp: (Category) -> Unit, - onMoveDown: (Category) -> Unit, -) { - LazyColumn( - state = lazyListState, - contentPadding = paddingValues, - verticalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small), - ) { - itemsIndexed( - items = categories, - key = { _, category -> "category-${category.id}" }, - ) { index, category -> - CategoryListItem( - modifier = Modifier.animateItemPlacement(), - category = category, - canMoveUp = index != 0, - canMoveDown = index != categories.lastIndex, - onMoveUp = onMoveUp, - onMoveDown = onMoveDown, - onRename = { onClickRename(category) }, - onDelete = { onClickDelete(category) }, - ) - } - } -} diff --git a/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt b/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt index 3960a992e1..27779e6938 100644 --- a/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt +++ b/app/src/main/java/eu/kanade/presentation/category/components/CategoryDialogs.kt @@ -1,22 +1,38 @@ package eu.kanade.presentation.category.components +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Checkbox +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text import androidx.compose.material3.TextButton +import androidx.compose.material3.TriStateCheckbox import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.res.stringResource +import eu.kanade.core.preference.asToggleableState +import eu.kanade.presentation.category.visualName import eu.kanade.tachiyomi.R import kotlinx.coroutines.delay +import tachiyomi.core.preference.CheckboxState import tachiyomi.domain.category.model.Category +import tachiyomi.presentation.core.components.material.padding import kotlin.time.Duration.Companion.seconds @Composable @@ -164,6 +180,111 @@ fun CategoryDeleteDialog( ) } -internal fun List.anyWithName(name: String): Boolean { +@Composable +fun ChangeCategoryDialog( + initialSelection: List>, + onDismissRequest: () -> Unit, + onEditCategories: () -> Unit, + onConfirm: (List, List) -> Unit, +) { + if (initialSelection.isEmpty()) { + AlertDialog( + onDismissRequest = onDismissRequest, + confirmButton = { + tachiyomi.presentation.core.components.material.TextButton( + onClick = { + onDismissRequest() + onEditCategories() + }, + ) { + Text(text = stringResource(R.string.action_edit_categories)) + } + }, + title = { + Text(text = stringResource(R.string.action_move_category)) + }, + text = { + Text(text = stringResource(R.string.information_empty_category_dialog)) + }, + ) + return + } + var selection by remember { mutableStateOf(initialSelection) } + AlertDialog( + onDismissRequest = onDismissRequest, + confirmButton = { + Row { + tachiyomi.presentation.core.components.material.TextButton(onClick = { + onDismissRequest() + onEditCategories() + },) { + Text(text = stringResource(R.string.action_edit)) + } + Spacer(modifier = Modifier.weight(1f)) + tachiyomi.presentation.core.components.material.TextButton(onClick = onDismissRequest) { + Text(text = stringResource(R.string.action_cancel)) + } + tachiyomi.presentation.core.components.material.TextButton( + onClick = { + onDismissRequest() + onConfirm( + selection.filter { it is CheckboxState.State.Checked || it is CheckboxState.TriState.Include }.map { it.value.id }, + selection.filter { it is CheckboxState.State.None || it is CheckboxState.TriState.None }.map { it.value.id }, + ) + }, + ) { + Text(text = stringResource(android.R.string.ok)) + } + } + }, + title = { + Text(text = stringResource(R.string.action_move_category)) + }, + text = { + Column( + modifier = Modifier.verticalScroll(rememberScrollState()), + ) { + selection.forEach { checkbox -> + val onChange: (CheckboxState) -> Unit = { + val index = selection.indexOf(it) + if (index != -1) { + val mutableList = selection.toMutableList() + mutableList[index] = it.next() + selection = mutableList.toList() + } + } + Row( + modifier = Modifier + .fillMaxWidth() + .clickable { onChange(checkbox) }, + verticalAlignment = Alignment.CenterVertically, + ) { + when (checkbox) { + is CheckboxState.TriState -> { + TriStateCheckbox( + state = checkbox.asToggleableState(), + onClick = { onChange(checkbox) }, + ) + } + is CheckboxState.State -> { + Checkbox( + checked = checkbox.isChecked, + onCheckedChange = { onChange(checkbox) }, + ) + } + } + + Text( + text = checkbox.value.visualName, + modifier = Modifier.padding(horizontal = MaterialTheme.padding.medium), + ) + } + } + } + }, + ) +} + +private fun List.anyWithName(name: String): Boolean { return any { name == it.name } } diff --git a/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt b/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt index a6062543ed..44e7d2dd9c 100644 --- a/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt @@ -1,6 +1,8 @@ package eu.kanade.presentation.history +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.items import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.DeleteSweep import androidx.compose.material3.Icon @@ -8,18 +10,25 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource +import eu.kanade.domain.ui.UiPreferences import eu.kanade.presentation.components.AppBarTitle +import eu.kanade.presentation.components.RelativeDateHeader import eu.kanade.presentation.components.SearchToolbar -import eu.kanade.presentation.history.components.HistoryContent +import eu.kanade.presentation.history.components.HistoryItem import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.history.HistoryScreenModel import eu.kanade.tachiyomi.ui.history.HistoryState import tachiyomi.domain.history.model.HistoryWithRelations +import tachiyomi.presentation.core.components.FastScrollLazyColumn import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.screens.EmptyScreen import tachiyomi.presentation.core.screens.LoadingScreen +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get +import java.text.DateFormat import java.util.Date @Composable @@ -64,7 +73,7 @@ fun HistoryScreen( modifier = Modifier.padding(contentPadding), ) } else { - HistoryContent( + HistoryScreenContent( history = it, contentPadding = contentPadding, onClickCover = { history -> onClickCover(history.mangaId) }, @@ -76,6 +85,55 @@ fun HistoryScreen( } } +@Composable +private fun HistoryScreenContent( + history: List, + contentPadding: PaddingValues, + onClickCover: (HistoryWithRelations) -> Unit, + onClickResume: (HistoryWithRelations) -> Unit, + onClickDelete: (HistoryWithRelations) -> Unit, + preferences: UiPreferences = Injekt.get(), +) { + val relativeTime: Int = remember { preferences.relativeTime().get() } + val dateFormat: DateFormat = remember { UiPreferences.dateFormat(preferences.dateFormat().get()) } + + FastScrollLazyColumn( + contentPadding = contentPadding, + ) { + items( + items = history, + key = { "history-${it.hashCode()}" }, + contentType = { + when (it) { + is HistoryUiModel.Header -> "header" + is HistoryUiModel.Item -> "item" + } + }, + ) { item -> + when (item) { + is HistoryUiModel.Header -> { + RelativeDateHeader( + modifier = Modifier.animateItemPlacement(), + date = item.date, + relativeTime = relativeTime, + dateFormat = dateFormat, + ) + } + is HistoryUiModel.Item -> { + val value = item.item + HistoryItem( + modifier = Modifier.animateItemPlacement(), + history = value, + onClickCover = { onClickCover(value) }, + onClickResume = { onClickResume(value) }, + onClickDelete = { onClickDelete(value) }, + ) + } + } + } + } +} + sealed class HistoryUiModel { data class Header(val date: Date) : HistoryUiModel() data class Item(val item: HistoryWithRelations) : HistoryUiModel() diff --git a/app/src/main/java/eu/kanade/presentation/history/components/HistoryContent.kt b/app/src/main/java/eu/kanade/presentation/history/components/HistoryContent.kt deleted file mode 100644 index e9cdb789ab..0000000000 --- a/app/src/main/java/eu/kanade/presentation/history/components/HistoryContent.kt +++ /dev/null @@ -1,64 +0,0 @@ -package eu.kanade.presentation.history.components - -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.lazy.items -import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember -import androidx.compose.ui.Modifier -import eu.kanade.domain.ui.UiPreferences -import eu.kanade.presentation.components.RelativeDateHeader -import eu.kanade.presentation.history.HistoryUiModel -import tachiyomi.domain.history.model.HistoryWithRelations -import tachiyomi.presentation.core.components.FastScrollLazyColumn -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get -import java.text.DateFormat - -@Composable -fun HistoryContent( - history: List, - contentPadding: PaddingValues, - onClickCover: (HistoryWithRelations) -> Unit, - onClickResume: (HistoryWithRelations) -> Unit, - onClickDelete: (HistoryWithRelations) -> Unit, - preferences: UiPreferences = Injekt.get(), -) { - val relativeTime: Int = remember { preferences.relativeTime().get() } - val dateFormat: DateFormat = remember { UiPreferences.dateFormat(preferences.dateFormat().get()) } - - FastScrollLazyColumn( - contentPadding = contentPadding, - ) { - items( - items = history, - key = { "history-${it.hashCode()}" }, - contentType = { - when (it) { - is HistoryUiModel.Header -> "header" - is HistoryUiModel.Item -> "item" - } - }, - ) { item -> - when (item) { - is HistoryUiModel.Header -> { - RelativeDateHeader( - modifier = Modifier.animateItemPlacement(), - date = item.date, - relativeTime = relativeTime, - dateFormat = dateFormat, - ) - } - is HistoryUiModel.Item -> { - val value = item.item - HistoryItem( - modifier = Modifier.animateItemPlacement(), - history = value, - onClickCover = { onClickCover(value) }, - onClickResume = { onClickResume(value) }, - onClickDelete = { onClickDelete(value) }, - ) - } - } - } - } -} diff --git a/app/src/main/java/eu/kanade/presentation/history/components/HistoryDialog.kt b/app/src/main/java/eu/kanade/presentation/history/components/HistoryDialogs.kt similarity index 100% rename from app/src/main/java/eu/kanade/presentation/history/components/HistoryDialog.kt rename to app/src/main/java/eu/kanade/presentation/history/components/HistoryDialogs.kt diff --git a/app/src/main/java/eu/kanade/presentation/library/components/GlobalSearchItem.kt b/app/src/main/java/eu/kanade/presentation/library/components/GlobalSearchItem.kt index 6055745ea3..93b5143ff6 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/GlobalSearchItem.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/GlobalSearchItem.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.zIndex import eu.kanade.tachiyomi.R @Composable -fun GlobalSearchItem( +internal fun GlobalSearchItem( searchQuery: String, onClick: () -> Unit, modifier: Modifier = Modifier, diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LazyLibraryGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LazyLibraryGrid.kt index bb18a7b5ce..4cc5b1f4e6 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LazyLibraryGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LazyLibraryGrid.kt @@ -12,7 +12,7 @@ import tachiyomi.presentation.core.components.FastScrollLazyVerticalGrid import tachiyomi.presentation.core.util.plus @Composable -fun LazyLibraryGrid( +internal fun LazyLibraryGrid( modifier: Modifier = Modifier, columns: Int, contentPadding: PaddingValues, @@ -28,7 +28,7 @@ fun LazyLibraryGrid( ) } -fun LazyGridScope.globalSearchItem( +internal fun LazyGridScope.globalSearchItem( searchQuery: String?, onGlobalSearchClicked: () -> Unit, ) { diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt index e16d15ef12..0ab1a3c286 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryBadges.kt @@ -10,7 +10,7 @@ import tachiyomi.presentation.core.components.Badge import tachiyomi.presentation.core.util.ThemePreviews @Composable -fun DownloadsBadge(count: Long) { +internal fun DownloadsBadge(count: Long) { if (count > 0) { Badge( text = "$count", @@ -21,14 +21,14 @@ fun DownloadsBadge(count: Long) { } @Composable -fun UnreadBadge(count: Long) { +internal fun UnreadBadge(count: Long) { if (count > 0) { Badge(text = "$count") } } @Composable -fun LanguageBadge( +internal fun LanguageBadge( isLocal: Boolean, sourceLanguage: String, ) { diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt index c2e69531f0..379d4054c2 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryComfortableGrid.kt @@ -11,7 +11,7 @@ import tachiyomi.domain.library.model.LibraryManga import tachiyomi.domain.manga.model.MangaCover @Composable -fun LibraryComfortableGrid( +internal fun LibraryComfortableGrid( items: List, columns: Int, contentPadding: PaddingValues, diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt index bfe187c392..56caa99e06 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryCompactGrid.kt @@ -11,7 +11,7 @@ import tachiyomi.domain.library.model.LibraryManga import tachiyomi.domain.manga.model.MangaCover @Composable -fun LibraryCompactGrid( +internal fun LibraryCompactGrid( items: List, showTitle: Boolean, columns: Int, diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt index c3b6083498..cb57bae0ea 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryList.kt @@ -15,7 +15,7 @@ import tachiyomi.presentation.core.components.FastScrollLazyColumn import tachiyomi.presentation.core.util.plus @Composable -fun LibraryList( +internal fun LibraryList( items: List, contentPadding: PaddingValues, selection: List, diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt index 52a03e7116..8901ce7cc3 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt @@ -13,7 +13,7 @@ import tachiyomi.presentation.core.components.material.TabIndicator import tachiyomi.presentation.core.components.material.TabText @Composable -fun LibraryTabs( +internal fun LibraryTabs( categories: List, currentPageIndex: Int, getNumberOfMangaForCategory: (Category) -> Int?, diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt index 022839c0e6..90369d5cfc 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt @@ -63,7 +63,7 @@ fun LibraryToolbar( } @Composable -fun LibraryRegularToolbar( +private fun LibraryRegularToolbar( title: LibraryToolbarTitle, hasFilters: Boolean, searchQuery: String?, @@ -130,7 +130,7 @@ fun LibraryRegularToolbar( } @Composable -fun LibrarySelectionToolbar( +private fun LibrarySelectionToolbar( selectedCount: Int, onClickUnselectAll: () -> Unit, onClickSelectAll: () -> Unit, diff --git a/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt b/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt index 630d080cba..c8496ff86a 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/UpdatesUiItem.kt @@ -50,7 +50,7 @@ import tachiyomi.presentation.core.util.selectedBackground import java.util.Date import kotlin.time.Duration.Companion.minutes -fun LazyListScope.updatesLastUpdatedItem( +internal fun LazyListScope.updatesLastUpdatedItem( lastUpdated: Long, ) { item(key = "updates-lastUpdated") { @@ -80,7 +80,7 @@ fun LazyListScope.updatesLastUpdatedItem( } } -fun LazyListScope.updatesUiItems( +internal fun LazyListScope.updatesUiItems( uiModels: List, selectionMode: Boolean, onUpdateSelected: (UpdatesItem, Boolean, Boolean, Boolean) -> Unit, @@ -146,7 +146,7 @@ fun LazyListScope.updatesUiItems( } @Composable -fun UpdatesUiItem( +private fun UpdatesUiItem( modifier: Modifier, update: UpdatesWithRelations, selected: Boolean, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt index 145e12d021..b3da4642f8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreen.kt @@ -39,7 +39,7 @@ import eu.kanade.presentation.browse.BrowseSourceContent import eu.kanade.presentation.browse.MissingSourceScreen import eu.kanade.presentation.browse.components.BrowseSourceToolbar import eu.kanade.presentation.browse.components.RemoveMangaDialog -import eu.kanade.presentation.category.ChangeCategoryDialog +import eu.kanade.presentation.category.components.ChangeCategoryDialog import eu.kanade.presentation.manga.DuplicateMangaDialog import eu.kanade.presentation.util.AssistContentScreen import eu.kanade.presentation.util.Screen diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt index 635f2f04d0..83235c565d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt @@ -29,7 +29,7 @@ import cafe.adriel.voyager.navigator.currentOrThrow import cafe.adriel.voyager.navigator.tab.LocalTabNavigator import cafe.adriel.voyager.navigator.tab.TabOptions import eu.kanade.domain.manga.model.isLocal -import eu.kanade.presentation.category.ChangeCategoryDialog +import eu.kanade.presentation.category.components.ChangeCategoryDialog import eu.kanade.presentation.library.DeleteLibraryMangaDialog import eu.kanade.presentation.library.LibrarySettingsDialog import eu.kanade.presentation.library.components.LibraryContent diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt index c73bdfea4f..dcf4efccd6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt @@ -22,7 +22,7 @@ import cafe.adriel.voyager.navigator.Navigator import cafe.adriel.voyager.navigator.currentOrThrow import eu.kanade.domain.manga.model.hasCustomCover import eu.kanade.domain.manga.model.toSManga -import eu.kanade.presentation.category.ChangeCategoryDialog +import eu.kanade.presentation.category.components.ChangeCategoryDialog import eu.kanade.presentation.components.NavigatorAdaptiveSheet import eu.kanade.presentation.manga.ChapterSettingsDialog import eu.kanade.presentation.manga.DuplicateMangaDialog