Yokan / rebuild
Course 1 8624561

LocalEntryManagement.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/screens/local/LocalEntryManagement.kt

implementation116 lines
1package eu.friedcutlet.yokan.ui.screens.local23import androidx.compose.foundation.layout.Column4import androidx.compose.foundation.layout.padding5import androidx.compose.material3.AlertDialog6import androidx.compose.material3.MaterialTheme7import androidx.compose.material3.Text8import androidx.compose.material3.TextButton9import androidx.compose.runtime.Composable10import androidx.compose.ui.Modifier11import androidx.compose.ui.unit.dp12import eu.friedcutlet.yokan.domain.Chapter13import eu.friedcutlet.yokan.domain.Manga14import eu.friedcutlet.yokan.services.library.LocalEntryManagementOperation15import eu.friedcutlet.yokan.services.library.LocalEntryManagementPreview16import eu.friedcutlet.yokan.services.library.LocalLibraryDuplicateGroup17import org.jetbrains.compose.resources.stringResource18import yokan.composeapp.generated.resources.Res19import yokan.composeapp.generated.resources.action_cancel2021/** Read-only detail of one indexed local entry: source path, metadata link, reconciliation state and chapters. */22@Composable23internal fun LocalEntryDetailContent(24    manga: Manga,25    stale: Boolean,26    chapters: List<Chapter>,27    modifier: Modifier,28    onReviewMetadata: () -> Unit,29    canColorize: Boolean = false,30    onColorize: () -> Unit = {},31) {32    Column(modifier) {33        Text(manga.name, style = MaterialTheme.typography.titleLarge)34        Text("Source path", style = MaterialTheme.typography.titleSmall)35        Text(manga.link.ifBlank { "Unavailable" })36        Text("Media type: ${manga.itemType}")37        Text("Metadata: ${if (manga.metadataServerId == null) "unmatched" else "linked (${manga.metadataSource})"}")38        TextButton(onClick = onReviewMetadata) { Text("Review metadata") }39        if (canColorize) TextButton(onClick = onColorize) { Text("Create colorized copy") }40        Text("Reconciliation: ${if (stale) "stale" else "no title issue reported"}")41        Text("Chapters", style = MaterialTheme.typography.titleSmall, modifier = Modifier.padding(top = 12.dp))42        chapters.forEach { chapter -> Text("${chapter.name} · ${chapter.url}", modifier = Modifier.padding(vertical = 4.dp)) }43    }44}4546/** Picks the canonical database entry of an exact-identity duplicate group; [onChoose] receives its id. */47@Composable48internal fun LocalDuplicateGroupDialog(49    group: LocalLibraryDuplicateGroup,50    titleName: (Long) -> String?,51    onChoose: (Long) -> Unit,52    onDismiss: () -> Unit,53) {54    AlertDialog(55        onDismissRequest = onDismiss,56        title = { Text("Choose canonical entry") },57        text = {58            Column {59                Text("Only exact local identities can be merged. Source files affected: 0.")60                group.ids.forEach { id ->61                    TextButton(onClick = { onChoose(id) }) { Text(titleName(id) ?: "Entry $id") }62                }63            }64        },65        confirmButton = {},66    )67}6869/** Confirms a previewed forget/merge operation, showing its database impact and any blockers. */70@Composable71internal fun LocalEntryOperationDialog(72    preview: LocalEntryManagementPreview,73    onConfirm: () -> Unit,74    onDismiss: () -> Unit,75) {76    val isMerge = preview.command.operation is LocalEntryManagementOperation.MergeDuplicateTitles77    AlertDialog(78        onDismissRequest = onDismiss,79        title = { Text(if (isMerge) "Review merge" else "Review forgetting entry") },80        text = {81            Column {82                Text("Database rows removed: ${preview.databaseRowsRemoved}")83                Text("Database rows updated: ${preview.databaseRowsUpdated}")84                Text("Source files affected: ${preview.sourceFilesAffected}")85                if (preview.blockers.isNotEmpty()) {86                    Text("Blocked: ${preview.blockers.joinToString { localBlockerLabel(it) }}", color = MaterialTheme.colorScheme.error)87                } else if (!isMerge) {88                    Text("Forget from database only. Source files remain unchanged.")89                }90            }91        },92        confirmButton = {93            TextButton(94                enabled = preview.blockers.isEmpty(),95                onClick = onConfirm,96            ) { Text(if (isMerge) "Merge entries" else "Forget from database") }97        },98        dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(Res.string.action_cancel)) } },99    )100}101102private fun localBlockerLabel(blocker: String): String = when (blocker) {103    "STATE_CHANGED" -> "the entry changed; review again"104    "FRESH_RECONCILIATION_CHANGED" -> "fresh reconciliation is required"105    "STALE_EVIDENCE_REQUIRED" -> "stale evidence is required"106    "CANDIDATE_CHANGED" -> "the stale candidate changed"107    "ACTIVE_DOWNLOAD" -> "an active download is using this entry"108    "INVALID_DUPLICATE_GROUP" -> "this is not an exact duplicate group"109    "TORRENT_ENTRY" -> "torrent entries cannot be merged"110    "ITEM_TYPE_MISMATCH" -> "media types do not match"111    "REMOTE_METADATA_CONFLICT" -> "metadata sources conflict"112    "TRACKER_BINDING_CONFLICT" -> "tracker links conflict"113    "ATOMIC_SNAPSHOT_PERSISTENCE_UNAVAILABLE" -> "atomic database updates are unavailable"114    "ATOMIC_SNAPSHOT_PERSISTENCE_FAILED" -> "the database update failed safely"115    else -> blocker116}117

Search chapters, reference and source filenames.