Add option to reset custom manga info (#1118)

* Add option to reset custom manga info

* Remove extra line

* Update app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt

---------

Co-authored-by: jobobby04 <jobobby04@users.noreply.github.com>
This commit is contained in:
Fermín Cirella 2024-03-17 00:59:19 -03:00 committed by GitHub
parent a425cae73b
commit 911e959fcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 60 additions and 1 deletions

View File

@ -239,6 +239,7 @@ fun LibraryBottomActionMenu(
onClickCleanTitles: (() -> Unit)?,
onClickMigrate: (() -> Unit)?,
onClickAddToMangaDex: (() -> Unit)?,
onClickResetInfo: (() -> Unit)?,
// SY <--
modifier: Modifier = Modifier,
) {
@ -267,7 +268,7 @@ fun LibraryBottomActionMenu(
}
}
// SY -->
val showOverflow = onClickCleanTitles != null || onClickAddToMangaDex != null
val showOverflow = onClickCleanTitles != null || onClickAddToMangaDex != null || onClickResetInfo != null
val configuration = LocalConfiguration.current
val moveMarkPrev = remember { !configuration.isTabletUi() }
var overFlowOpen by remember { mutableStateOf(false) }
@ -364,6 +365,12 @@ fun LibraryBottomActionMenu(
onClick = onClickAddToMangaDex,
)
}
if (onClickResetInfo != null) {
DropdownMenuItem(
text = { Text(text = stringResource(SYMR.strings.reset_info)) },
onClick = onClickResetInfo,
)
}
}
} else {
Button(

View File

@ -750,6 +750,24 @@ class LibraryScreenModel(
clearSelection()
}
}
fun resetInfo() {
state.value.selection.fastForEach { (manga) ->
val mangaInfo = CustomMangaInfo(
id = manga.id,
title = null,
author = null,
artist = null,
thumbnailUrl = null,
description = null,
genre = null,
status = null,
)
setCustomMangaInfo.set(mangaInfo)
}
clearSelection()
}
// SY <--
/**
@ -1336,6 +1354,18 @@ class LibraryScreenModel(
val showAddToMangadex: Boolean by lazy {
selection.any { it.manga.source in mangaDexSourceIds }
}
val showResetInfo: Boolean by lazy {
selection.fastAny { (manga) ->
manga.title != manga.ogTitle ||
manga.author != manga.ogAuthor ||
manga.artist != manga.ogArtist ||
manga.thumbnailUrl != manga.ogThumbnailUrl ||
manga.description != manga.ogDescription ||
manga.genre != manga.ogGenre ||
manga.status != manga.ogStatus
}
}
// SY <--
fun getLibraryItemsByCategoryId(categoryId: Long): List<LibraryItem>? {

View File

@ -205,6 +205,7 @@ object LibraryTab : Tab {
}
},
onClickAddToMangaDex = screenModel::syncMangaToDex.takeIf { state.showAddToMangadex },
onClickResetInfo = screenModel::resetInfo.takeIf { state.showResetInfo },
// SY <--
)
},

View File

@ -201,6 +201,7 @@ private fun onViewCreated(manga: Manga, context: Context, binding: EditMangaDial
binding.mangaGenresTags.clearFocus()
binding.resetTags.setOnClickListener { resetTags(manga, binding, scope) }
binding.resetInfo.setOnClickListener { resetInfo(manga, binding, scope) }
}
private fun resetTags(manga: Manga, binding: EditMangaDialogBinding, scope: CoroutineScope) {
@ -217,6 +218,15 @@ private fun loadCover(manga: Manga, context: Context, binding: EditMangaDialogBi
}
}
private fun resetInfo(manga: Manga, binding: EditMangaDialogBinding, scope: CoroutineScope) {
binding.title.setText("")
binding.mangaAuthor.setText("")
binding.mangaArtist.setText("")
binding.thumbnailUrl.setText("")
binding.mangaDescription.setText("")
resetTags(manga, binding, scope)
}
private fun ChipGroup.setChips(items: List<String>, scope: CoroutineScope) {
removeAllViews()

View File

@ -139,6 +139,16 @@
android:text="@string/reset_tags"
android:textAllCaps="false" />
<Button
android:id="@+id/reset_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:text="@string/reset_info"
android:textAllCaps="false" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"

View File

@ -350,6 +350,7 @@
<!-- Entry Info Edit -->
<string name="reset_tags">Reset Tags</string>
<string name="add_tag">Add Tag</string>
<string name="reset_info">Reset Info</string>
<string name="title_hint">Title: %1$s</string>
<string name="description_hint">Description: %1$s</string>
<string name="author_hint">Author: %1$s</string>