mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 22:39:18 +01:00
added duplicate manga check
When adding a manga to your library, the app will go through each manga previously added and compare their names. If a match is detected, it will prompt the user and ask for confirmation. On this prompt there is also an option to view the other manga.
This commit is contained in:
parent
f5c6e80dbb
commit
0390dd7672
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.manga
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.ActivityOptions
|
import android.app.ActivityOptions
|
||||||
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
@ -516,10 +517,55 @@ class MangaController :
|
|||||||
activity?.toast(activity?.getString(R.string.manga_removed_library))
|
activity?.toast(activity?.getString(R.string.manga_removed_library))
|
||||||
activity?.invalidateOptionsMenu()
|
activity?.invalidateOptionsMenu()
|
||||||
} else {
|
} else {
|
||||||
addToLibrary(manga)
|
if (!isDuplicateOfOtherSource(manga)) {
|
||||||
|
addToLibrary(manga)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isDuplicateOfOtherSource(origin: Manga): Boolean {
|
||||||
|
var result = false
|
||||||
|
val mangas = presenter.getAllMangaMutableList()
|
||||||
|
|
||||||
|
mangas.forEach { item ->
|
||||||
|
if (isSameManga(origin, item)) {
|
||||||
|
showAddDuplicateDialog(
|
||||||
|
origin,
|
||||||
|
item,
|
||||||
|
getSourceFromLong(item.source)
|
||||||
|
)
|
||||||
|
result = true
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isSameManga(origin: Manga, other: Manga): Boolean {
|
||||||
|
return origin.title.equals(other.title, ignoreCase = true) &&
|
||||||
|
// Source check, just in case we fetched the library list before it got removed
|
||||||
|
origin.source != other.source
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSourceFromLong(sourceId: Long): Source {
|
||||||
|
return Injekt.get<SourceManager>().getOrStub(sourceId)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showAddDuplicateDialog(manga: Manga, other: Manga, source: Source) {
|
||||||
|
AlertDialog.Builder(activity).apply {
|
||||||
|
setMessage(activity?.getString(R.string.confirm_manga_add_duplicate, source.name))
|
||||||
|
setPositiveButton(activity?.getString(R.string.action_add)) { _, _, ->
|
||||||
|
addToLibrary(manga)
|
||||||
|
}
|
||||||
|
setNegativeButton(activity?.getString(R.string.action_cancel)) { _, _, -> }
|
||||||
|
setNeutralButton(activity?.getString(R.string.action_show_manga)) { _, _, ->
|
||||||
|
router.pushController(MangaController(other).withFadeTransaction())
|
||||||
|
}
|
||||||
|
setCancelable(true)
|
||||||
|
}.create().show()
|
||||||
|
}
|
||||||
|
|
||||||
fun onTrackingClick() {
|
fun onTrackingClick() {
|
||||||
trackSheet?.show()
|
trackSheet?.show()
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.data.cache.CoverCache
|
|||||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||||
import eu.kanade.tachiyomi.data.database.models.Category
|
import eu.kanade.tachiyomi.data.database.models.Category
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||||
|
import eu.kanade.tachiyomi.data.database.models.LibraryManga
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.database.models.MangaCategory
|
import eu.kanade.tachiyomi.data.database.models.MangaCategory
|
||||||
import eu.kanade.tachiyomi.data.database.models.Track
|
import eu.kanade.tachiyomi.data.database.models.Track
|
||||||
@ -174,6 +175,10 @@ class MangaPresenter(
|
|||||||
fetchTrackers()
|
fetchTrackers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getAllMangaMutableList(): MutableList<LibraryManga> {
|
||||||
|
return db.getLibraryMangas().executeAsBlocking()
|
||||||
|
}
|
||||||
|
|
||||||
// Manga info - start
|
// Manga info - start
|
||||||
|
|
||||||
private fun getMangaObservable(): Observable<Manga> {
|
private fun getMangaObservable(): Observable<Manga> {
|
||||||
|
@ -81,6 +81,7 @@
|
|||||||
<string name="action_start">Start</string>
|
<string name="action_start">Start</string>
|
||||||
<string name="action_resume">Resume</string>
|
<string name="action_resume">Resume</string>
|
||||||
<string name="action_open_in_browser">Open in browser</string>
|
<string name="action_open_in_browser">Open in browser</string>
|
||||||
|
<string name="action_show_manga">Show manga</string>
|
||||||
<!-- Do not translate "WebView" -->
|
<!-- Do not translate "WebView" -->
|
||||||
<string name="action_open_in_web_view">Open in WebView</string>
|
<string name="action_open_in_web_view">Open in WebView</string>
|
||||||
<string name="action_web_view" translatable="false">WebView</string>
|
<string name="action_web_view" translatable="false">WebView</string>
|
||||||
@ -571,6 +572,7 @@
|
|||||||
<string name="in_library">In library</string>
|
<string name="in_library">In library</string>
|
||||||
<string name="remove_from_library">Remove from library</string>
|
<string name="remove_from_library">Remove from library</string>
|
||||||
<string name="manga_info_full_title_label">Title</string>
|
<string name="manga_info_full_title_label">Title</string>
|
||||||
|
<string name="confirm_manga_add_duplicate">We found a manga in your library with the same name, but from a different source (%1$s).\n\nDo you still wish to continue?</string>
|
||||||
<string name="manga_added_library">Added to library</string>
|
<string name="manga_added_library">Added to library</string>
|
||||||
<string name="manga_removed_library">Removed from library</string>
|
<string name="manga_removed_library">Removed from library</string>
|
||||||
<string name="manga_info_expand">More</string>
|
<string name="manga_info_expand">More</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user