show duplicating manga cover on Duplicate dialog

This commit is contained in:
Cuong-Tran 2024-10-22 18:42:19 +07:00
parent 3a48f424f8
commit e874092d3e
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
5 changed files with 106 additions and 20 deletions

View file

@ -2,6 +2,7 @@ package eu.kanade.presentation.manga
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.FlowColumn
import androidx.compose.foundation.layout.FlowRow
@ -10,8 +11,10 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Add
import androidx.compose.material.icons.outlined.Book
@ -23,18 +26,27 @@ import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import eu.kanade.domain.ui.UiPreferences
import eu.kanade.presentation.components.AdaptiveSheet
import eu.kanade.presentation.components.TabbedDialogPaddings
import eu.kanade.presentation.manga.components.MangaCover
import eu.kanade.presentation.manga.components.RatioSwitchToPanorama
import eu.kanade.presentation.more.settings.LocalPreferenceMinHeight
import eu.kanade.presentation.more.settings.widget.TextPreferenceWidget
import tachiyomi.domain.manga.model.Manga
import tachiyomi.i18n.MR
import tachiyomi.i18n.kmk.KMR
import tachiyomi.presentation.core.i18n.stringResource
import tachiyomi.presentation.core.util.collectAsState
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@Composable
fun DuplicateMangaDialog(
@ -42,10 +54,19 @@ fun DuplicateMangaDialog(
onConfirm: () -> Unit,
onOpenManga: () -> Unit,
onMigrate: () -> Unit,
// KMK -->
duplicate: Manga,
// KMK <--
modifier: Modifier = Modifier,
) {
val minHeight = LocalPreferenceMinHeight.current
// KMK -->
val usePanoramaCover by Injekt.get<UiPreferences>().usePanoramaCover().collectAsState()
val coverRatio = remember { mutableFloatStateOf(1f) }
val coverIsWide = coverRatio.floatValue <= RatioSwitchToPanorama
// KMK <--
AdaptiveSheet(
modifier = modifier,
onDismissRequest = onDismissRequest,
@ -71,6 +92,37 @@ fun DuplicateMangaDialog(
Spacer(Modifier.height(PaddingSize))
// KMK -->
Box(
modifier = Modifier
.fillMaxWidth(),
) {
if (usePanoramaCover && coverIsWide) {
MangaCover.Panorama(
modifier = Modifier
.align(Alignment.Center)
.heightIn(max = 150.dp),
data = duplicate,
onCoverLoaded = { _, result ->
val image = result.result.image
coverRatio.floatValue = image.height.toFloat() / image.width
},
)
} else {
MangaCover.Book(
modifier = Modifier
.align(Alignment.Center)
.widthIn(max = 150.dp),
data = duplicate,
onCoverLoaded = { _, result ->
val image = result.result.image
coverRatio.floatValue = image.height.toFloat() / image.width
},
)
}
}
// KMK <--
TextPreferenceWidget(
title = stringResource(MR.strings.action_show_manga),
icon = Icons.Outlined.Book,
@ -141,18 +193,56 @@ fun DuplicateMangasDialog(
onAllowDuplicate: () -> Unit,
onSkipDuplicate: () -> Unit,
stopRunning: () -> Unit,
duplicatedName: String,
mangaName: String,
duplicate: Manga,
) {
val usePanoramaCover by Injekt.get<UiPreferences>().usePanoramaCover().collectAsState()
val coverRatio = remember { mutableFloatStateOf(1f) }
val coverIsWide = coverRatio.floatValue <= RatioSwitchToPanorama
AlertDialog(
onDismissRequest = {
stopRunning()
onDismissRequest()
},
title = {
Text(text = duplicatedName)
Text(text = mangaName)
},
text = {
Text(text = stringResource(MR.strings.confirm_add_duplicate_manga))
Column {
Text(text = stringResource(MR.strings.confirm_add_duplicate_manga))
Spacer(Modifier.height(PaddingSize))
Box(
modifier = Modifier
.fillMaxWidth(),
) {
if (usePanoramaCover && coverIsWide) {
MangaCover.Panorama(
modifier = Modifier
.align(Alignment.Center)
.heightIn(max = 150.dp),
data = duplicate,
onCoverLoaded = { _, result ->
val image = result.result.image
coverRatio.floatValue = image.height.toFloat() / image.width
},
)
} else {
MangaCover.Book(
modifier = Modifier
.align(Alignment.Center)
.widthIn(max = 150.dp),
data = duplicate,
onCoverLoaded = { _, result ->
val image = result.result.image
coverRatio.floatValue = image.height.toFloat() / image.width
},
)
}
}
}
},
confirmButton = {
FlowRow(
@ -229,19 +319,4 @@ fun DuplicateMangasDialog(
},
)
}
@Preview
@Composable
fun DuplicateMangasDialogPreview() {
DuplicateMangasDialog(
onDismissRequest = { },
onAllowAllDuplicate = { },
onSkipAllDuplicate = { },
onOpenManga = { },
onAllowDuplicate = { },
onSkipDuplicate = { },
duplicatedName = "Berserk",
stopRunning = { },
)
}
// KMK <--

View file

@ -453,6 +453,7 @@ fun AddDuplicateMangaDialog(bulkFavoriteScreenModel: BulkFavoriteScreenModel) {
dialog.manga.id,
)
},
duplicate = dialog.duplicate,
)
}
@ -525,8 +526,9 @@ fun AllowDuplicateDialog(bulkFavoriteScreenModel: BulkFavoriteScreenModel) {
bulkFavoriteScreenModel.removeDuplicateSelectedManga(index = dialog.duplicatedManga.first)
bulkFavoriteScreenModel.addFavorite(startIdx = dialog.duplicatedManga.first)
},
duplicatedName = dialog.duplicatedManga.second.title,
mangaName = dialog.duplicatedManga.second.title,
stopRunning = bulkFavoriteScreenModel::stopRunning,
duplicate = dialog.duplicatedManga.second,
)
}

View file

@ -438,6 +438,9 @@ data class BrowseSourceScreen(
)
// SY <--
},
// KMK -->
duplicate = dialog.duplicate,
// KMK <--
)
}
is BrowseSourceScreenModel.Dialog.RemoveManga -> {

View file

@ -440,6 +440,9 @@ class MangaScreen(
migrateManga(navigator, dialog.duplicate, screenModel.manga!!.id)
// SY <--
},
// KMK -->
duplicate = dialog.duplicate,
// KMK <--
)
}

View file

@ -173,6 +173,9 @@ class MangaDexFollowsScreen(private val sourceId: Long) : Screen() {
dialog.manga.id,
)
},
// KMK -->
duplicate = dialog.duplicate,
// KMK <--
)
}
is BrowseSourceScreenModel.Dialog.RemoveManga -> {