2022-05-08 11:34:55 +08:00
|
|
|
package eu.kanade.presentation.browse
|
2022-04-27 20:36:16 +08:00
|
|
|
|
2022-06-14 21:10:40 +08:00
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
import androidx.compose.foundation.layout.Row
|
2022-04-27 20:36:16 +08:00
|
|
|
import androidx.compose.foundation.layout.WindowInsets
|
|
|
|
import androidx.compose.foundation.layout.asPaddingValues
|
|
|
|
import androidx.compose.foundation.layout.navigationBars
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
import androidx.compose.foundation.lazy.items
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.getValue
|
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
|
|
|
|
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
|
|
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
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-04-27 20:36:16 +08:00
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import eu.kanade.domain.source.model.Source
|
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.presentation.components.EmptyScreen
|
2022-05-01 23:36:55 +08:00
|
|
|
import eu.kanade.presentation.components.ItemBadges
|
2022-04-27 20:36:16 +08:00
|
|
|
import eu.kanade.presentation.components.LoadingScreen
|
2022-05-24 06:03:46 +08:00
|
|
|
import eu.kanade.presentation.components.ScrollbarLazyColumn
|
2022-04-27 20:36:16 +08:00
|
|
|
import eu.kanade.presentation.theme.header
|
|
|
|
import eu.kanade.presentation.util.horizontalPadding
|
2022-05-16 02:00:35 +08:00
|
|
|
import eu.kanade.presentation.util.plus
|
2022-05-16 04:19:55 +08:00
|
|
|
import eu.kanade.presentation.util.topPaddingValues
|
2022-04-27 20:36:16 +08:00
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
|
import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesPresenter
|
2022-06-14 21:10:40 +08:00
|
|
|
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
2022-07-17 02:44:37 +08:00
|
|
|
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
2022-04-27 20:36:16 +08:00
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun MigrateSourceScreen(
|
|
|
|
nestedScrollInterop: NestedScrollConnection,
|
|
|
|
presenter: MigrationSourcesPresenter,
|
|
|
|
onClickItem: (Source) -> Unit,
|
|
|
|
) {
|
2022-07-17 02:44:37 +08:00
|
|
|
val context = LocalContext.current
|
|
|
|
when {
|
|
|
|
presenter.isLoading -> LoadingScreen()
|
|
|
|
presenter.isEmpty -> EmptyScreen(textResource = R.string.information_empty_library)
|
|
|
|
else ->
|
2022-04-27 20:36:16 +08:00
|
|
|
MigrateSourceList(
|
|
|
|
nestedScrollInterop = nestedScrollInterop,
|
2022-07-17 02:44:37 +08:00
|
|
|
list = presenter.items,
|
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-04-27 20:36:16 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun MigrateSourceList(
|
|
|
|
nestedScrollInterop: NestedScrollConnection,
|
|
|
|
list: List<Pair<Source, Long>>,
|
|
|
|
onClickItem: (Source) -> Unit,
|
|
|
|
onLongClickItem: (Source) -> Unit,
|
|
|
|
) {
|
2022-05-24 06:03:46 +08:00
|
|
|
ScrollbarLazyColumn(
|
2022-04-27 20:36:16 +08:00
|
|
|
modifier = Modifier.nestedScroll(nestedScrollInterop),
|
2022-05-16 02:00:35 +08:00
|
|
|
contentPadding = WindowInsets.navigationBars.asPaddingValues() + topPaddingValues,
|
2022-04-27 20:36:16 +08:00
|
|
|
) {
|
|
|
|
item(key = "title") {
|
|
|
|
Text(
|
2022-05-20 05:43:27 +08:00
|
|
|
text = stringResource(R.string.migration_selection_prompt),
|
2022-04-27 20:36:16 +08:00
|
|
|
modifier = Modifier
|
|
|
|
.animateItemPlacement()
|
|
|
|
.padding(horizontal = horizontalPadding, vertical = 8.dp),
|
2022-05-11 05:54:52 +08:00
|
|
|
style = MaterialTheme.typography.header,
|
2022-04-27 20:36:16 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
items(
|
|
|
|
items = list,
|
|
|
|
key = { (source, _) ->
|
|
|
|
source.id
|
2022-05-11 05:54:52 +08:00
|
|
|
},
|
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
|
|
|
|
fun MigrateSourceItem(
|
|
|
|
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-05-01 23:36:55 +08:00
|
|
|
action = { ItemBadges(primaryText = "$count") },
|
2022-06-14 21:10:40 +08:00
|
|
|
content = { source, showLanguageInContent ->
|
|
|
|
Column(
|
|
|
|
modifier = Modifier
|
|
|
|
.padding(horizontal = horizontalPadding)
|
|
|
|
.weight(1f),
|
|
|
|
) {
|
|
|
|
Text(
|
|
|
|
text = source.name.ifBlank { source.id.toString() },
|
|
|
|
maxLines = 1,
|
|
|
|
overflow = TextOverflow.Ellipsis,
|
|
|
|
style = MaterialTheme.typography.bodyMedium,
|
|
|
|
)
|
|
|
|
Row(
|
|
|
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
) {
|
|
|
|
if (showLanguageInContent) {
|
|
|
|
Text(
|
|
|
|
text = LocaleHelper.getDisplayName(source.lang),
|
|
|
|
maxLines = 1,
|
|
|
|
overflow = TextOverflow.Ellipsis,
|
|
|
|
style = MaterialTheme.typography.bodySmall,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if (source.isStub) {
|
|
|
|
Text(
|
|
|
|
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
|
|
|
)
|
|
|
|
}
|