mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 10:59:15 +01:00
More minor refactorings
Extracted from #7244 Co-authored-by: ivaniskandar <ivaniskandar@users.noreply.github.com>
This commit is contained in:
parent
68c47a3238
commit
cb1830d747
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.source
|
|||||||
|
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import eu.kanade.domain.source.model.SourceData
|
import eu.kanade.domain.source.model.SourceData
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
@ -105,3 +106,18 @@ fun Source.icon(): Drawable? = Injekt.get<ExtensionManager>().getAppIconForSourc
|
|||||||
fun Source.getPreferenceKey(): String = "source_$id"
|
fun Source.getPreferenceKey(): String = "source_$id"
|
||||||
|
|
||||||
fun Source.toSourceData(): SourceData = SourceData(id = id, lang = lang, name = name)
|
fun Source.toSourceData(): SourceData = SourceData(id = id, lang = lang, name = name)
|
||||||
|
|
||||||
|
fun Source.getNameForMangaInfo(): String {
|
||||||
|
val preferences = Injekt.get<PreferencesHelper>()
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -84,7 +84,7 @@ class SearchController(
|
|||||||
if (!isReplacingManga) {
|
if (!isReplacingManga) {
|
||||||
router.popController(this)
|
router.popController(this)
|
||||||
if (newManga != null) {
|
if (newManga != null) {
|
||||||
val newMangaController = RouterTransaction.with(MangaController(newManga))
|
val newMangaController = RouterTransaction.with(MangaController(newManga.id!!))
|
||||||
if (router.backstack.lastOrNull()?.controller is MangaController) {
|
if (router.backstack.lastOrNull()?.controller is MangaController) {
|
||||||
// Replace old MangaController
|
// Replace old MangaController
|
||||||
router.replaceTopController(newMangaController)
|
router.replaceTopController(newMangaController)
|
||||||
@ -140,7 +140,7 @@ class SearchController(
|
|||||||
}
|
}
|
||||||
.setNeutralButton(activity?.getString(R.string.action_show_manga)) { _, _ ->
|
.setNeutralButton(activity?.getString(R.string.action_show_manga)) { _, _ ->
|
||||||
dismissDialog()
|
dismissDialog()
|
||||||
router.pushController(MangaController(newManga))
|
router.pushController(MangaController(newManga!!.id!!))
|
||||||
}
|
}
|
||||||
.create()
|
.create()
|
||||||
}
|
}
|
||||||
|
@ -575,7 +575,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||||||
*/
|
*/
|
||||||
override fun onItemClick(view: View, position: Int): Boolean {
|
override fun onItemClick(view: View, position: Int): Boolean {
|
||||||
val item = adapter?.getItem(position) as? SourceItem ?: return false
|
val item = adapter?.getItem(position) as? SourceItem ?: return false
|
||||||
router.pushController(MangaController(item.manga, true))
|
router.pushController(MangaController(item.manga.id!!, true))
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ open class GlobalSearchController(
|
|||||||
* @param manga clicked item containing manga information.
|
* @param manga clicked item containing manga information.
|
||||||
*/
|
*/
|
||||||
override fun onMangaClick(manga: Manga) {
|
override fun onMangaClick(manga: Manga) {
|
||||||
router.pushController(MangaController(manga, true))
|
router.pushController(MangaController(manga.id!!, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -493,7 +493,7 @@ class LibraryController(
|
|||||||
// Notify the presenter a manga is being opened.
|
// Notify the presenter a manga is being opened.
|
||||||
presenter.onOpenManga()
|
presenter.onOpenManga()
|
||||||
|
|
||||||
router.pushController(MangaController(manga))
|
router.pushController(MangaController(manga.id!!))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,7 +40,7 @@ class AddDuplicateMangaDialog(bundle: Bundle? = null) : DialogController(bundle)
|
|||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
.setNeutralButton(activity?.getString(R.string.action_show_manga)) { _, _ ->
|
.setNeutralButton(activity?.getString(R.string.action_show_manga)) { _, _ ->
|
||||||
dismissDialog()
|
dismissDialog()
|
||||||
router.pushController(MangaController(libraryManga))
|
router.pushController(MangaController(libraryManga.id!!))
|
||||||
}
|
}
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.create()
|
.create()
|
||||||
|
@ -122,22 +122,18 @@ class MangaController :
|
|||||||
|
|
||||||
constructor(history: HistoryWithRelations) : this(history.mangaId)
|
constructor(history: HistoryWithRelations) : this(history.mangaId)
|
||||||
|
|
||||||
constructor(manga: Manga?, fromSource: Boolean = false) : super(
|
constructor(mangaId: Long, fromSource: Boolean = false) : super(
|
||||||
bundleOf(
|
bundleOf(
|
||||||
MANGA_EXTRA to (manga?.id ?: 0),
|
MANGA_EXTRA to mangaId,
|
||||||
FROM_SOURCE_EXTRA to fromSource,
|
FROM_SOURCE_EXTRA to fromSource,
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
this.manga = manga
|
this.manga = Injekt.get<DatabaseHelper>().getManga(mangaId).executeAsBlocking()
|
||||||
if (manga != null) {
|
if (this.manga != null) {
|
||||||
source = Injekt.get<SourceManager>().getOrStub(manga.source)
|
source = Injekt.get<SourceManager>().getOrStub(this.manga!!.source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(mangaId: Long) : this(
|
|
||||||
Injekt.get<DatabaseHelper>().getManga(mangaId).executeAsBlocking(),
|
|
||||||
)
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
constructor(bundle: Bundle) : this(bundle.getLong(MANGA_EXTRA))
|
constructor(bundle: Bundle) : this(bundle.getLong(MANGA_EXTRA))
|
||||||
|
|
||||||
@ -309,7 +305,7 @@ class MangaController :
|
|||||||
|
|
||||||
settingsSheet = ChaptersSettingsSheet(router, presenter)
|
settingsSheet = ChaptersSettingsSheet(router, presenter)
|
||||||
|
|
||||||
trackSheet = TrackSheet(this, manga!!, (activity as MainActivity).supportFragmentManager)
|
trackSheet = TrackSheet(this, (activity as MainActivity).supportFragmentManager)
|
||||||
|
|
||||||
updateFilterIconState()
|
updateFilterIconState()
|
||||||
recyclerViewUpdatesToolbarTitleAlpha(true)
|
recyclerViewUpdatesToolbarTitleAlpha(true)
|
||||||
|
@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.data.track.TrackManager
|
|||||||
import eu.kanade.tachiyomi.databinding.MangaInfoHeaderBinding
|
import eu.kanade.tachiyomi.databinding.MangaInfoHeaderBinding
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
|
import eu.kanade.tachiyomi.source.getNameForMangaInfo
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.getMainAppBarHeight
|
import eu.kanade.tachiyomi.ui.base.controller.getMainAppBarHeight
|
||||||
@ -247,20 +248,8 @@ class MangaInfoHeaderAdapter(
|
|||||||
// If manga source is known update source TextView.
|
// If manga source is known update source TextView.
|
||||||
binding.mangaMissingSourceIcon.isVisible = source is SourceManager.StubSource
|
binding.mangaMissingSourceIcon.isVisible = source is SourceManager.StubSource
|
||||||
|
|
||||||
val mangaSource = source.toString()
|
|
||||||
with(binding.mangaSource) {
|
with(binding.mangaSource) {
|
||||||
val enabledLanguages = preferences.enabledLanguages().get()
|
text = source.getNameForMangaInfo()
|
||||||
.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
|
|
||||||
}
|
|
||||||
|
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
controller.performSearch(sourceManager.getOrStub(source.id).name)
|
controller.performSearch(sourceManager.getOrStub(source.id).name)
|
||||||
|
@ -11,10 +11,8 @@ import com.google.android.material.datepicker.DateValidatorPointBackward
|
|||||||
import com.google.android.material.datepicker.DateValidatorPointForward
|
import com.google.android.material.datepicker.DateValidatorPointForward
|
||||||
import com.google.android.material.datepicker.MaterialDatePicker
|
import com.google.android.material.datepicker.MaterialDatePicker
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
|
||||||
import eu.kanade.tachiyomi.data.track.EnhancedTrackService
|
import eu.kanade.tachiyomi.data.track.EnhancedTrackService
|
||||||
import eu.kanade.tachiyomi.databinding.TrackControllerBinding
|
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.base.controller.openInBrowser
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
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.copyToClipboard
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.widget.sheet.BaseBottomSheetDialog
|
import eu.kanade.tachiyomi.widget.sheet.BaseBottomSheetDialog
|
||||||
import uy.kohesive.injekt.Injekt
|
|
||||||
import uy.kohesive.injekt.api.get
|
|
||||||
|
|
||||||
class TrackSheet(
|
class TrackSheet(
|
||||||
val controller: MangaController,
|
val controller: MangaController,
|
||||||
val manga: Manga,
|
|
||||||
val fragmentManager: FragmentManager,
|
val fragmentManager: FragmentManager,
|
||||||
private val sourceManager: SourceManager = Injekt.get(),
|
|
||||||
) : BaseBottomSheetDialog(controller.activity!!),
|
) : BaseBottomSheetDialog(controller.activity!!),
|
||||||
TrackAdapter.OnClickListener,
|
TrackAdapter.OnClickListener,
|
||||||
SetTrackStatusDialog.Listener,
|
SetTrackStatusDialog.Listener,
|
||||||
@ -80,6 +74,8 @@ class TrackSheet(
|
|||||||
|
|
||||||
override fun onSetClick(position: Int) {
|
override fun onSetClick(position: Int) {
|
||||||
val item = adapter.getItem(position) ?: return
|
val item = adapter.getItem(position) ?: return
|
||||||
|
val manga = controller.presenter.manga
|
||||||
|
val source = controller.presenter.source
|
||||||
|
|
||||||
if (item.service is EnhancedTrackService) {
|
if (item.service is EnhancedTrackService) {
|
||||||
if (item.track != null) {
|
if (item.track != null) {
|
||||||
@ -87,7 +83,7 @@ class TrackSheet(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.service.accept(sourceManager.getOrStub(manga.source))) {
|
if (!item.service.accept(source)) {
|
||||||
controller.presenter.view?.applicationContext?.toast(R.string.source_unsupported)
|
controller.presenter.view?.applicationContext?.toast(R.string.source_unsupported)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,7 @@ class UpdatesController :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun openManga(chapter: UpdatesItem) {
|
private fun openManga(chapter: UpdatesItem) {
|
||||||
router.pushController(MangaController(chapter.manga))
|
router.pushController(MangaController(chapter.manga.id!!))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user