diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt b/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt index 4ea66c81f..2acfd44bb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/Source.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.source import android.graphics.drawable.Drawable import eu.kanade.domain.source.model.SourceData +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter @@ -105,3 +106,18 @@ fun Source.icon(): Drawable? = Injekt.get().getAppIconForSourc fun Source.getPreferenceKey(): String = "source_$id" fun Source.toSourceData(): SourceData = SourceData(id = id, lang = lang, name = name) + +fun Source.getNameForMangaInfo(): String { + val preferences = Injekt.get() + val enabledLanguages = preferences.enabledLanguages().get() + .filterNot { it in listOf("all", "other") } + val hasOneActiveLanguages = enabledLanguages.size == 1 + val isInEnabledLanguages = lang in enabledLanguages + return when { + // For edge cases where user disables a source they got manga of in their library. + hasOneActiveLanguages && !isInEnabledLanguages -> toString() + // Hide the language tag when only one language is used. + hasOneActiveLanguages && isInEnabledLanguages -> name + else -> toString() + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt index a91e9a1b9..f8376a6fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt @@ -84,7 +84,7 @@ class SearchController( if (!isReplacingManga) { router.popController(this) if (newManga != null) { - val newMangaController = RouterTransaction.with(MangaController(newManga)) + val newMangaController = RouterTransaction.with(MangaController(newManga.id!!)) if (router.backstack.lastOrNull()?.controller is MangaController) { // Replace old MangaController router.replaceTopController(newMangaController) @@ -140,7 +140,7 @@ class SearchController( } .setNeutralButton(activity?.getString(R.string.action_show_manga)) { _, _ -> dismissDialog() - router.pushController(MangaController(newManga)) + router.pushController(MangaController(newManga!!.id!!)) } .create() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index b9b405718..f9915e110 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -575,7 +575,7 @@ open class BrowseSourceController(bundle: Bundle) : */ override fun onItemClick(view: View, position: Int): Boolean { val item = adapter?.getItem(position) as? SourceItem ?: return false - router.pushController(MangaController(item.manga, true)) + router.pushController(MangaController(item.manga.id!!, true)) return false } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt index 7103ea7e8..a040a3542 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt @@ -65,7 +65,7 @@ open class GlobalSearchController( * @param manga clicked item containing manga information. */ override fun onMangaClick(manga: Manga) { - router.pushController(MangaController(manga, true)) + router.pushController(MangaController(manga.id!!, true)) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index b7578fb2d..4318989fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -493,7 +493,7 @@ class LibraryController( // Notify the presenter a manga is being opened. presenter.onOpenManga() - router.pushController(MangaController(manga)) + router.pushController(MangaController(manga.id!!)) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/AddDuplicateMangaDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/AddDuplicateMangaDialog.kt index 58fbe282c..32f84cb92 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/AddDuplicateMangaDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/AddDuplicateMangaDialog.kt @@ -40,7 +40,7 @@ class AddDuplicateMangaDialog(bundle: Bundle? = null) : DialogController(bundle) .setNegativeButton(android.R.string.cancel, null) .setNeutralButton(activity?.getString(R.string.action_show_manga)) { _, _ -> dismissDialog() - router.pushController(MangaController(libraryManga)) + router.pushController(MangaController(libraryManga.id!!)) } .setCancelable(true) .create() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index 2426a50c7..48812da25 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -122,22 +122,18 @@ class MangaController : constructor(history: HistoryWithRelations) : this(history.mangaId) - constructor(manga: Manga?, fromSource: Boolean = false) : super( + constructor(mangaId: Long, fromSource: Boolean = false) : super( bundleOf( - MANGA_EXTRA to (manga?.id ?: 0), + MANGA_EXTRA to mangaId, FROM_SOURCE_EXTRA to fromSource, ), ) { - this.manga = manga - if (manga != null) { - source = Injekt.get().getOrStub(manga.source) + this.manga = Injekt.get().getManga(mangaId).executeAsBlocking() + if (this.manga != null) { + source = Injekt.get().getOrStub(this.manga!!.source) } } - constructor(mangaId: Long) : this( - Injekt.get().getManga(mangaId).executeAsBlocking(), - ) - @Suppress("unused") constructor(bundle: Bundle) : this(bundle.getLong(MANGA_EXTRA)) @@ -309,7 +305,7 @@ class MangaController : settingsSheet = ChaptersSettingsSheet(router, presenter) - trackSheet = TrackSheet(this, manga!!, (activity as MainActivity).supportFragmentManager) + trackSheet = TrackSheet(this, (activity as MainActivity).supportFragmentManager) updateFilterIconState() recyclerViewUpdatesToolbarTitleAlpha(true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt index 36a98a686..e6cfa5a33 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt @@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.databinding.MangaInfoHeaderBinding import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager +import eu.kanade.tachiyomi.source.getNameForMangaInfo import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.controller.getMainAppBarHeight @@ -247,20 +248,8 @@ class MangaInfoHeaderAdapter( // If manga source is known update source TextView. binding.mangaMissingSourceIcon.isVisible = source is SourceManager.StubSource - val mangaSource = source.toString() with(binding.mangaSource) { - val enabledLanguages = preferences.enabledLanguages().get() - .filterNot { it in listOf("all", "other") } - - val hasOneActiveLanguages = enabledLanguages.size == 1 - val isInEnabledLanguages = source.lang in enabledLanguages - text = when { - // For edge cases where user disables a source they got manga of in their library. - hasOneActiveLanguages && !isInEnabledLanguages -> mangaSource - // Hide the language tag when only one language is used. - hasOneActiveLanguages && isInEnabledLanguages -> source.name - else -> mangaSource - } + text = source.getNameForMangaInfo() setOnClickListener { controller.performSearch(sourceManager.getOrStub(source.id).name) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt index cf7a2a230..43783e4dd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt @@ -11,10 +11,8 @@ import com.google.android.material.datepicker.DateValidatorPointBackward import com.google.android.material.datepicker.DateValidatorPointForward import com.google.android.material.datepicker.MaterialDatePicker import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.databinding.TrackControllerBinding -import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.base.controller.openInBrowser import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.util.lang.launchIO @@ -24,14 +22,10 @@ import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.widget.sheet.BaseBottomSheetDialog -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get class TrackSheet( val controller: MangaController, - val manga: Manga, val fragmentManager: FragmentManager, - private val sourceManager: SourceManager = Injekt.get(), ) : BaseBottomSheetDialog(controller.activity!!), TrackAdapter.OnClickListener, SetTrackStatusDialog.Listener, @@ -80,6 +74,8 @@ class TrackSheet( override fun onSetClick(position: Int) { val item = adapter.getItem(position) ?: return + val manga = controller.presenter.manga + val source = controller.presenter.source if (item.service is EnhancedTrackService) { if (item.track != null) { @@ -87,7 +83,7 @@ class TrackSheet( return } - if (!item.service.accept(sourceManager.getOrStub(manga.source))) { + if (!item.service.accept(source)) { controller.presenter.view?.applicationContext?.toast(R.string.source_unsupported) return } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index a024023fe..33e143300 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -282,7 +282,7 @@ class UpdatesController : } private fun openManga(chapter: UpdatesItem) { - router.pushController(MangaController(chapter.manga)) + router.pushController(MangaController(chapter.manga.id!!)) } /**