2022-05-08 11:34:55 +08:00
|
|
|
package eu.kanade.presentation.browse
|
2022-04-27 20:36:16 +08:00
|
|
|
|
2022-09-19 04:08:50 +08:00
|
|
|
import androidx.compose.foundation.background
|
2022-06-14 21:10:40 +08:00
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
import androidx.compose.foundation.layout.Column
|
2022-10-10 03:52:56 +08:00
|
|
|
import androidx.compose.foundation.layout.PaddingValues
|
2022-06-14 21:10:40 +08:00
|
|
|
import androidx.compose.foundation.layout.Row
|
2022-04-27 20:36:16 +08:00
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
import androidx.compose.foundation.lazy.items
|
2022-08-31 04:31:28 +08:00
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
import androidx.compose.material.icons.outlined.ArrowDownward
|
|
|
|
import androidx.compose.material.icons.outlined.ArrowUpward
|
|
|
|
import androidx.compose.material.icons.outlined.Numbers
|
|
|
|
import androidx.compose.material.icons.outlined.SortByAlpha
|
|
|
|
import androidx.compose.material3.Icon
|
|
|
|
import androidx.compose.material3.IconButton
|
2022-04-27 20:36:16 +08:00
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.runtime.Composable
|
2022-06-14 21:10:40 +08:00
|
|
|
import androidx.compose.ui.Alignment
|
2022-04-27 20:36:16 +08:00
|
|
|
import androidx.compose.ui.Modifier
|
2022-07-17 02:44:37 +08:00
|
|
|
import androidx.compose.ui.platform.LocalContext
|
2022-04-27 20:36:16 +08:00
|
|
|
import androidx.compose.ui.res.stringResource
|
2022-06-14 21:10:40 +08:00
|
|
|
import androidx.compose.ui.text.style.TextOverflow
|
2022-08-30 05:18:06 +08:00
|
|
|
import eu.kanade.domain.source.interactor.SetMigrateSorting
|
2022-05-08 11:34:55 +08:00
|
|
|
import eu.kanade.presentation.browse.components.BaseSourceItem
|
2022-06-14 21:10:40 +08:00
|
|
|
import eu.kanade.presentation.browse.components.SourceIcon
|
2022-04-27 20:36:16 +08:00
|
|
|
import eu.kanade.tachiyomi.R
|
2022-11-24 11:28:25 +08:00
|
|
|
import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrateSourceState
|
2022-07-17 02:44:37 +08:00
|
|
|
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
2023-01-23 00:04:50 +08:00
|
|
|
import tachiyomi.domain.source.model.Source
|
2023-02-19 04:52:52 +08:00
|
|
|
import tachiyomi.presentation.core.components.Badge
|
|
|
|
import tachiyomi.presentation.core.components.BadgeGroup
|
2023-02-19 05:33:03 +08:00
|
|
|
import tachiyomi.presentation.core.components.ScrollbarLazyColumn
|
|
|
|
import tachiyomi.presentation.core.components.Scroller.STICKY_HEADER_KEY_PREFIX
|
2023-02-19 05:03:01 +08:00
|
|
|
import tachiyomi.presentation.core.components.material.padding
|
|
|
|
import tachiyomi.presentation.core.components.material.topSmallPaddingValues
|
2023-02-20 23:12:41 +08:00
|
|
|
import tachiyomi.presentation.core.screens.EmptyScreen
|
|
|
|
import tachiyomi.presentation.core.screens.LoadingScreen
|
2023-02-19 06:04:32 +08:00
|
|
|
import tachiyomi.presentation.core.theme.header
|
2023-02-19 05:33:03 +08:00
|
|
|
import tachiyomi.presentation.core.util.plus
|
|
|
|
import tachiyomi.presentation.core.util.secondaryItemAlpha
|
2022-04-27 20:36:16 +08:00
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun MigrateSourceScreen(
|
2022-11-24 11:28:25 +08:00
|
|
|
state: MigrateSourceState,
|
2022-10-10 03:52:56 +08:00
|
|
|
contentPadding: PaddingValues,
|
2022-04-27 20:36:16 +08:00
|
|
|
onClickItem: (Source) -> Unit,
|
2022-11-24 11:28:25 +08:00
|
|
|
onToggleSortingDirection: () -> Unit,
|
|
|
|
onToggleSortingMode: () -> Unit,
|
2022-04-27 20:36:16 +08:00
|
|
|
) {
|
2022-07-17 02:44:37 +08:00
|
|
|
val context = LocalContext.current
|
|
|
|
when {
|
2022-11-24 11:28:25 +08:00
|
|
|
state.isLoading -> LoadingScreen(modifier = Modifier.padding(contentPadding))
|
|
|
|
state.isEmpty -> EmptyScreen(
|
2022-10-10 03:52:56 +08:00
|
|
|
textResource = R.string.information_empty_library,
|
|
|
|
modifier = Modifier.padding(contentPadding),
|
|
|
|
)
|
2022-07-17 02:44:37 +08:00
|
|
|
else ->
|
2022-04-27 20:36:16 +08:00
|
|
|
MigrateSourceList(
|
2022-11-24 11:28:25 +08:00
|
|
|
list = state.items,
|
2022-10-10 03:52:56 +08:00
|
|
|
contentPadding = contentPadding,
|
2022-04-27 20:36:16 +08:00
|
|
|
onClickItem = onClickItem,
|
2022-07-17 02:44:37 +08:00
|
|
|
onLongClickItem = { source ->
|
|
|
|
val sourceId = source.id.toString()
|
|
|
|
context.copyToClipboard(sourceId, sourceId)
|
|
|
|
},
|
2022-11-24 11:28:25 +08:00
|
|
|
sortingMode = state.sortingMode,
|
|
|
|
onToggleSortingMode = onToggleSortingMode,
|
|
|
|
sortingDirection = state.sortingDirection,
|
|
|
|
onToggleSortingDirection = onToggleSortingDirection,
|
2022-04-27 20:36:16 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
2022-09-19 10:38:44 +08:00
|
|
|
private fun MigrateSourceList(
|
2022-04-27 20:36:16 +08:00
|
|
|
list: List<Pair<Source, Long>>,
|
2022-10-10 03:52:56 +08:00
|
|
|
contentPadding: PaddingValues,
|
2022-04-27 20:36:16 +08:00
|
|
|
onClickItem: (Source) -> Unit,
|
|
|
|
onLongClickItem: (Source) -> Unit,
|
2022-08-30 05:18:06 +08:00
|
|
|
sortingMode: SetMigrateSorting.Mode,
|
|
|
|
onToggleSortingMode: () -> Unit,
|
|
|
|
sortingDirection: SetMigrateSorting.Direction,
|
|
|
|
onToggleSortingDirection: () -> Unit,
|
2022-04-27 20:36:16 +08:00
|
|
|
) {
|
2022-05-24 06:03:46 +08:00
|
|
|
ScrollbarLazyColumn(
|
2022-11-14 01:11:51 +08:00
|
|
|
contentPadding = contentPadding + topSmallPaddingValues,
|
2022-04-27 20:36:16 +08:00
|
|
|
) {
|
2022-10-10 23:59:01 +08:00
|
|
|
stickyHeader(key = STICKY_HEADER_KEY_PREFIX) {
|
2022-08-31 04:31:28 +08:00
|
|
|
Row(
|
|
|
|
modifier = Modifier
|
2022-09-19 04:08:50 +08:00
|
|
|
.background(MaterialTheme.colorScheme.background)
|
2022-11-14 01:11:51 +08:00
|
|
|
.padding(start = MaterialTheme.padding.medium),
|
2022-08-31 04:31:28 +08:00
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
) {
|
|
|
|
Text(
|
|
|
|
text = stringResource(R.string.migration_selection_prompt),
|
|
|
|
modifier = Modifier.weight(1f),
|
|
|
|
style = MaterialTheme.typography.header,
|
|
|
|
)
|
|
|
|
|
|
|
|
IconButton(onClick = onToggleSortingMode) {
|
|
|
|
when (sortingMode) {
|
|
|
|
SetMigrateSorting.Mode.ALPHABETICAL -> Icon(Icons.Outlined.SortByAlpha, contentDescription = stringResource(R.string.action_sort_alpha))
|
2022-10-21 05:48:13 +08:00
|
|
|
SetMigrateSorting.Mode.TOTAL -> Icon(Icons.Outlined.Numbers, contentDescription = stringResource(R.string.action_sort_count))
|
2022-08-31 04:31:28 +08:00
|
|
|
}
|
2022-08-30 05:18:06 +08:00
|
|
|
}
|
2022-08-31 04:31:28 +08:00
|
|
|
IconButton(onClick = onToggleSortingDirection) {
|
|
|
|
when (sortingDirection) {
|
|
|
|
SetMigrateSorting.Direction.ASCENDING -> Icon(Icons.Outlined.ArrowUpward, contentDescription = stringResource(R.string.action_asc))
|
|
|
|
SetMigrateSorting.Direction.DESCENDING -> Icon(Icons.Outlined.ArrowDownward, contentDescription = stringResource(R.string.action_desc))
|
|
|
|
}
|
2022-08-30 05:18:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-27 20:36:16 +08:00
|
|
|
items(
|
|
|
|
items = list,
|
2022-09-27 05:23:04 +08:00
|
|
|
key = { (source, _) -> "migrate-${source.id}" },
|
2022-04-27 20:36:16 +08:00
|
|
|
) { (source, count) ->
|
|
|
|
MigrateSourceItem(
|
|
|
|
modifier = Modifier.animateItemPlacement(),
|
|
|
|
source = source,
|
|
|
|
count = count,
|
|
|
|
onClickItem = { onClickItem(source) },
|
2022-05-11 05:54:52 +08:00
|
|
|
onLongClickItem = { onLongClickItem(source) },
|
2022-04-27 20:36:16 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
2022-09-19 10:38:44 +08:00
|
|
|
private fun MigrateSourceItem(
|
2022-04-27 20:36:16 +08:00
|
|
|
modifier: Modifier = Modifier,
|
|
|
|
source: Source,
|
|
|
|
count: Long,
|
|
|
|
onClickItem: () -> Unit,
|
|
|
|
onLongClickItem: () -> Unit,
|
|
|
|
) {
|
|
|
|
BaseSourceItem(
|
|
|
|
modifier = modifier,
|
|
|
|
source = source,
|
2022-04-30 20:33:00 +08:00
|
|
|
showLanguageInContent = source.lang != "",
|
2022-04-27 20:36:16 +08:00
|
|
|
onClickItem = onClickItem,
|
|
|
|
onLongClickItem = onLongClickItem,
|
2022-06-19 22:16:55 +08:00
|
|
|
icon = { SourceIcon(source = source) },
|
2022-07-17 05:40:40 +08:00
|
|
|
action = {
|
|
|
|
BadgeGroup {
|
|
|
|
Badge(text = "$count")
|
|
|
|
}
|
|
|
|
},
|
2022-10-04 11:05:37 +08:00
|
|
|
content = { _, sourceLangString ->
|
2022-06-14 21:10:40 +08:00
|
|
|
Column(
|
|
|
|
modifier = Modifier
|
2022-11-14 01:11:51 +08:00
|
|
|
.padding(horizontal = MaterialTheme.padding.medium)
|
2022-06-14 21:10:40 +08:00
|
|
|
.weight(1f),
|
|
|
|
) {
|
|
|
|
Text(
|
|
|
|
text = source.name.ifBlank { source.id.toString() },
|
|
|
|
maxLines = 1,
|
|
|
|
overflow = TextOverflow.Ellipsis,
|
|
|
|
style = MaterialTheme.typography.bodyMedium,
|
|
|
|
)
|
|
|
|
Row(
|
2023-01-09 04:40:43 +08:00
|
|
|
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small),
|
2022-06-14 21:10:40 +08:00
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
) {
|
2022-10-04 11:05:37 +08:00
|
|
|
if (sourceLangString != null) {
|
2022-06-14 21:10:40 +08:00
|
|
|
Text(
|
2022-10-10 03:49:32 +08:00
|
|
|
modifier = Modifier.secondaryItemAlpha(),
|
2022-10-04 11:05:37 +08:00
|
|
|
text = sourceLangString,
|
2022-06-14 21:10:40 +08:00
|
|
|
maxLines = 1,
|
|
|
|
overflow = TextOverflow.Ellipsis,
|
|
|
|
style = MaterialTheme.typography.bodySmall,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if (source.isStub) {
|
|
|
|
Text(
|
2022-10-10 03:49:32 +08:00
|
|
|
modifier = Modifier.secondaryItemAlpha(),
|
2022-06-14 21:10:40 +08:00
|
|
|
text = stringResource(R.string.not_installed),
|
|
|
|
maxLines = 1,
|
|
|
|
overflow = TextOverflow.Ellipsis,
|
|
|
|
style = MaterialTheme.typography.bodySmall,
|
|
|
|
color = MaterialTheme.colorScheme.error,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-04-27 20:36:16 +08:00
|
|
|
)
|
|
|
|
}
|