Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit basic Manga information #398

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SyncChaptersWithSource(
.mapIndexed { i, sChapter ->
Chapter.create()
.copyFromSChapter(sChapter)
.copy(name = with(ChapterSanitizer) { sChapter.name.sanitize(manga.title) })
.copy(name = with(ChapterSanitizer) { sChapter.name.sanitize(manga.ogTitle) })
.copy(mangaId = manga.id, sourceOrder = i.toLong())
}

Expand Down Expand Up @@ -92,7 +92,12 @@ class SyncChaptersWithSource(
}

// Recognize chapter number for the chapter.
val chapterNumber = ChapterRecognition.parseChapterNumber(manga.title, chapter.name, chapter.chapterNumber)
val chapterNumber = ChapterRecognition.parseChapterNumber(
manga.ogTitle,
chapter.name,
chapter.chapterNumber
)

chapter = chapter.copy(chapterNumber = chapterNumber)

val dbChapter = dbChapters.find { it.url == chapter.url }
Expand All @@ -110,7 +115,7 @@ class SyncChaptersWithSource(
if (shouldUpdateDbChapter.await(dbChapter, chapter)) {
val shouldRenameChapter = downloadProvider.isChapterDirNameChanged(dbChapter, chapter) &&
downloadManager.isChapterDownloaded(
dbChapter.name, dbChapter.scanlator, manga.title, manga.source,
dbChapter.name, dbChapter.scanlator, manga.ogTitle, manga.source,
)

if (shouldRenameChapter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fun List<Chapter>.applyFilters(manga: Manga, downloadManager: DownloadManager):
val downloaded = downloadManager.isChapterDownloaded(
chapter.name,
chapter.scanlator,
manga.title,
manga.ogTitle,
manga.source,
)
downloaded || isLocalManga
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ class UpdateManga(
MangaUpdate(id = mangaId, favorite = favorite, dateAdded = dateAdded),
)
}

suspend fun awaitUpdateEditInfo(mangaUpdate: MangaUpdate): Boolean {
return mangaRepository.updateEditedInfo(mangaUpdate)
}
}
20 changes: 10 additions & 10 deletions app/src/main/java/eu/kanade/domain/manga/model/Manga.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ fun Manga.toSManga(): SManga = SManga.create().also {
}

fun Manga.copyFrom(other: SManga): Manga {
val author = other.author ?: author
val artist = other.artist ?: artist
val description = other.description ?: description
val author = other.author ?: ogAuthor
val artist = other.artist ?: ogArtist
val description = other.description ?: ogDescription
val genres = if (other.genre != null) {
other.getGenres()
} else {
genre
}
val thumbnailUrl = other.thumbnail_url ?: thumbnailUrl
return this.copy(
author = author,
artist = artist,
description = description,
ogAuthor = author,
ogArtist = artist,
ogDescription = description,
genre = genres,
thumbnailUrl = thumbnailUrl,
status = other.status.toLong(),
Expand All @@ -75,10 +75,10 @@ fun Manga.copyFrom(other: SManga): Manga {
fun SManga.toDomainManga(sourceId: Long): Manga {
return Manga.create().copy(
url = url,
title = title,
artist = artist,
author = author,
description = description,
ogTitle = title,
ogArtist = artist,
ogAuthor = author,
ogDescription = description,
genre = getGenres(),
status = status.toLong(),
thumbnailUrl = thumbnail_url,
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fun MangaScreen(
onEditCategoryClicked: (() -> Unit)?,
onEditFetchIntervalClicked: (() -> Unit)?,
onMigrateClicked: (() -> Unit)?,
onEditInfoClicked: (() -> Unit)?,

// For bottom action menu
onMultiBookmarkClicked: (List<Chapter>, bookmarked: Boolean) -> Unit,
Expand Down Expand Up @@ -160,6 +161,7 @@ fun MangaScreen(
onDownloadActionClicked = onDownloadActionClicked,
onEditCategoryClicked = onEditCategoryClicked,
onEditIntervalClicked = onEditFetchIntervalClicked,
onEditInfoClicked = onEditInfoClicked,
onMigrateClicked = onMigrateClicked,
onMultiBookmarkClicked = onMultiBookmarkClicked,
onMultiMarkAsReadClicked = onMultiMarkAsReadClicked,
Expand Down Expand Up @@ -195,6 +197,7 @@ fun MangaScreen(
onDownloadActionClicked = onDownloadActionClicked,
onEditCategoryClicked = onEditCategoryClicked,
onEditIntervalClicked = onEditFetchIntervalClicked,
onEditInfoClicked = onEditInfoClicked,
onMigrateClicked = onMigrateClicked,
onMultiBookmarkClicked = onMultiBookmarkClicked,
onMultiMarkAsReadClicked = onMultiMarkAsReadClicked,
Expand Down Expand Up @@ -241,6 +244,7 @@ private fun MangaScreenSmallImpl(
onEditCategoryClicked: (() -> Unit)?,
onEditIntervalClicked: (() -> Unit)?,
onMigrateClicked: (() -> Unit)?,
onEditInfoClicked: (() -> Unit)?,

// For bottom action menu
onMultiBookmarkClicked: (List<Chapter>, bookmarked: Boolean) -> Unit,
Expand Down Expand Up @@ -309,6 +313,7 @@ private fun MangaScreenSmallImpl(
actionModeCounter = selectedChapterCount,
onSelectAll = { onAllChapterSelected(true) },
onInvertSelection = { onInvertSelection() },
onClickEditInfo = onEditInfoClicked,
)
},
bottomBar = {
Expand Down Expand Up @@ -489,6 +494,7 @@ fun MangaScreenLargeImpl(
onEditCategoryClicked: (() -> Unit)?,
onEditIntervalClicked: (() -> Unit)?,
onMigrateClicked: (() -> Unit)?,
onEditInfoClicked: (() -> Unit)?,

// For bottom action menu
onMultiBookmarkClicked: (List<Chapter>, bookmarked: Boolean) -> Unit,
Expand Down Expand Up @@ -550,6 +556,7 @@ fun MangaScreenLargeImpl(
actionModeCounter = selectedChapterCount,
onSelectAll = { onAllChapterSelected(true) },
onInvertSelection = { onInvertSelection() },
onClickEditInfo = onEditInfoClicked,
)
},
bottomBar = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
Expand All @@ -23,6 +27,7 @@ import eu.kanade.tachiyomi.util.system.isDevFlavor
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
import kotlinx.collections.immutable.toImmutableList
import tachiyomi.domain.manga.interactor.FetchInterval
import tachiyomi.domain.manga.model.Manga
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.components.WheelTextPicker
import tachiyomi.presentation.core.components.material.padding
Expand Down Expand Up @@ -148,3 +153,80 @@ fun SetIntervalDialog(
},
)
}

@Composable
fun EditInfoDialog(
manga: Manga,
onDismissRequest: () -> Unit,
onConfirm: (manga: Manga) -> Unit,
) {
var editedManga by remember {
mutableStateOf(
manga.copy(
customTitle = manga.customTitle ?: manga.title,
customAuthor = manga.customAuthor ?: manga.author,
customArtist = manga.customArtist ?: manga.artist,
customDescription = manga.customDescription ?: manga.description,
)
)
}

AlertDialog(
onDismissRequest = onDismissRequest,
title = {
Text(text = stringResource(MR.strings.action_edit_info))
},
text = {
Column(
Modifier
.fillMaxWidth()
.verticalScroll(rememberScrollState()),
) {
OutlinedTextField(
value = editedManga.customTitle.orEmpty(),
onValueChange = {
editedManga = editedManga.copy(customTitle = it)
},
label = { Text(text = stringResource(MR.strings.title)) },
)

OutlinedTextField(
value = editedManga.customAuthor.orEmpty(),
onValueChange = {
editedManga = editedManga.copy(customAuthor = it)
},
label = { Text(text = stringResource(MR.strings.author)) },
)

OutlinedTextField(
value = editedManga.customArtist.orEmpty(),
onValueChange = {
editedManga = editedManga.copy(customArtist = it)
},
label = { Text(text = stringResource(MR.strings.artist)) },
)

OutlinedTextField(
value = editedManga.customDescription.orEmpty(),
onValueChange = {
editedManga = editedManga.copy(customDescription = it)
},
label = { Text(text = stringResource(MR.strings.description)) },
)
}
},
dismissButton = {
TextButton(onClick = onDismissRequest) {
Text(text = stringResource(MR.strings.action_cancel))
}
},
confirmButton = {
TextButton(onClick = {
onConfirm(editedManga)
onDismissRequest()
}) {
Text(text = stringResource(MR.strings.action_ok))
}
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fun MangaToolbar(
onClickEditCategory: (() -> Unit)?,
onClickRefresh: () -> Unit,
onClickMigrate: (() -> Unit)?,
onClickEditInfo: (() -> Unit)?,

// For action mode
actionModeCounter: Int,
Expand Down Expand Up @@ -149,6 +150,14 @@ fun MangaToolbar(
),
)
}
if (onClickEditInfo != null) {
add(
AppBar.OverflowAction(
title = stringResource(MR.strings.action_edit_info),
onClick = onClickEditInfo,
)
)
}
}
.build(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class MangaBackupCreator(
private fun Manga.toBackupManga() =
BackupManga(
url = this.url,
title = this.title,
artist = this.artist,
author = this.author,
description = this.description,
title = this.ogTitle,
artist = this.ogArtist,
author = this.ogAuthor,
description = this.ogDescription,
genre = this.genre.orEmpty(),
status = this.status.toInt(),
thumbnailUrl = this.thumbnailUrl,
Expand All @@ -98,4 +98,8 @@ private fun Manga.toBackupManga() =
updateStrategy = this.updateStrategy,
lastModifiedAt = this.lastModifiedAt,
favoriteModifiedAt = this.favoriteModifiedAt,
customArtist = this.customArtist,
customAuthor = this.customAuthor,
customTitle = this.customTitle,
customDescription = this.customDescription,
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ data class BackupManga(
@ProtoNumber(106) var lastModifiedAt: Long = 0,
@ProtoNumber(107) var favoriteModifiedAt: Long? = null,
@ProtoNumber(108) var excludedScanlators: List<String> = emptyList(),
// Numbers to keep compatibility with fork edited manga fields
// https://github.com/jobobby04/TachiyomiSY/blob/7e151ddb83d5d7e0ea553eca686a8c4aa3a1fa8c/app/src/main/java/eu/kanade/tachiyomi/data/backup/models/BackupManga.kt#L49
@ProtoNumber(800) var customTitle: String? = null,
@ProtoNumber(801) var customArtist: String? = null,
@ProtoNumber(802) var customAuthor: String? = null,
@ProtoNumber(804) var customDescription: String? = null,
) {
fun getMangaImpl(): Manga {
return Manga.create().copy(
url = [email protected],
title = [email protected],
artist = [email protected],
author = [email protected],
description = [email protected],
ogTitle = [email protected],
ogArtist = [email protected],
ogAuthor = [email protected],
ogDescription = [email protected],
genre = [email protected],
status = [email protected](),
thumbnailUrl = [email protected],
Expand All @@ -58,6 +64,10 @@ data class BackupManga(
updateStrategy = [email protected],
lastModifiedAt = [email protected],
favoriteModifiedAt = [email protected],
customTitle = [email protected],
customArtist = [email protected],
customAuthor = [email protected],
customDescription = [email protected],
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class MangaRestorer(
private fun Manga.copyFrom(newer: Manga): Manga {
return this.copy(
favorite = this.favorite || newer.favorite,
author = newer.author,
artist = newer.artist,
description = newer.description,
ogAuthor = newer.ogAuthor,
ogArtist = newer.ogArtist,
ogDescription = newer.ogDescription,
genre = newer.genre,
thumbnailUrl = newer.thumbnailUrl,
status = newer.status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class DownloadCache(

val sourceDir = rootDownloadsDir.sourceDirs[manga.source]
if (sourceDir != null) {
val mangaDir = sourceDir.mangaDirs[provider.getMangaDirName(manga.title)]
val mangaDir = sourceDir.mangaDirs[provider.getMangaDirName(manga.ogTitle)]
if (mangaDir != null) {
return mangaDir.chapterDirs.size
}
Expand All @@ -208,7 +208,7 @@ class DownloadCache(
}

// Retrieve the cached manga directory or cache a new one
val mangaDirName = provider.getMangaDirName(manga.title)
val mangaDirName = provider.getMangaDirName(manga.ogTitle)
var mangaDir = sourceDir.mangaDirs[mangaDirName]
if (mangaDir == null) {
mangaDir = MangaDirectory(mangaUniFile)
Expand All @@ -231,7 +231,7 @@ class DownloadCache(
suspend fun removeChapter(chapter: Chapter, manga: Manga) {
rootDownloadsDirLock.withLock {
val sourceDir = rootDownloadsDir.sourceDirs[manga.source] ?: return
val mangaDir = sourceDir.mangaDirs[provider.getMangaDirName(manga.title)] ?: return
val mangaDir = sourceDir.mangaDirs[provider.getMangaDirName(manga.ogTitle)] ?: return
provider.getValidChapterDirNames(chapter.name, chapter.scanlator).forEach {
if (it in mangaDir.chapterDirs) {
mangaDir.chapterDirs -= it
Expand All @@ -251,7 +251,7 @@ class DownloadCache(
suspend fun removeChapters(chapters: List<Chapter>, manga: Manga) {
rootDownloadsDirLock.withLock {
val sourceDir = rootDownloadsDir.sourceDirs[manga.source] ?: return
val mangaDir = sourceDir.mangaDirs[provider.getMangaDirName(manga.title)] ?: return
val mangaDir = sourceDir.mangaDirs[provider.getMangaDirName(manga.ogTitle)] ?: return
chapters.forEach { chapter ->
provider.getValidChapterDirNames(chapter.name, chapter.scanlator).forEach {
if (it in mangaDir.chapterDirs) {
Expand All @@ -272,7 +272,7 @@ class DownloadCache(
suspend fun removeManga(manga: Manga) {
rootDownloadsDirLock.withLock {
val sourceDir = rootDownloadsDir.sourceDirs[manga.source] ?: return
val mangaDirName = provider.getMangaDirName(manga.title)
val mangaDirName = provider.getMangaDirName(manga.ogTitle)
if (sourceDir.mangaDirs.containsKey(mangaDirName)) {
sourceDir.mangaDirs -= mangaDirName
}
Expand Down
Loading