More minor refactorings
Extracted from #7244 Co-authored-by: ivaniskandar <ivaniskandar@users.noreply.github.com> (cherry picked from commit cb1830d74773544c6063371df74b268dab0c85fa) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt # app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt # app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt # app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt
This commit is contained in:
parent
a9227a13e1
commit
ea712646fc
@ -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
|
||||||
@ -12,6 +13,7 @@ import eu.kanade.tachiyomi.source.model.toPageUrl
|
|||||||
import eu.kanade.tachiyomi.source.model.toSChapter
|
import eu.kanade.tachiyomi.source.model.toSChapter
|
||||||
import eu.kanade.tachiyomi.source.model.toSManga
|
import eu.kanade.tachiyomi.source.model.toSManga
|
||||||
import eu.kanade.tachiyomi.util.lang.awaitSingle
|
import eu.kanade.tachiyomi.util.lang.awaitSingle
|
||||||
|
import exh.source.MERGED_SOURCE_ID
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import tachiyomi.source.model.ChapterInfo
|
import tachiyomi.source.model.ChapterInfo
|
||||||
import tachiyomi.source.model.MangaInfo
|
import tachiyomi.source.model.MangaInfo
|
||||||
@ -105,3 +107,46 @@ 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(source: Source, getMergedSourcesString: (List<String>, Boolean) -> String): String {
|
||||||
|
val preferences = Injekt.get<PreferencesHelper>()
|
||||||
|
val enabledLanguages = preferences.enabledLanguages().get()
|
||||||
|
.filterNot { it in listOf("all", "other") }
|
||||||
|
// SY -->
|
||||||
|
val isMergedSource = source.id == MERGED_SOURCE_ID
|
||||||
|
// SY <--
|
||||||
|
val hasOneActiveLanguages = enabledLanguages.size == 1
|
||||||
|
val isInEnabledLanguages = source.lang in enabledLanguages
|
||||||
|
return when {
|
||||||
|
// SY -->
|
||||||
|
isMergedSource && hasOneActiveLanguages -> getMergedSourcesString(
|
||||||
|
enabledLanguages,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
isMergedSource -> getMergedSourcesString(
|
||||||
|
enabledLanguages,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
// SY <--
|
||||||
|
// 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -115,7 +115,7 @@ open class FeedController :
|
|||||||
*/
|
*/
|
||||||
override fun onMangaClick(manga: Manga) {
|
override fun onMangaClick(manga: Manga) {
|
||||||
// Open MangaController.
|
// Open MangaController.
|
||||||
parentController?.router?.pushController(MangaController(manga, true))
|
parentController?.router?.pushController(MangaController(manga.id!!, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -420,7 +420,7 @@ class MigrationListController(bundle: Bundle? = null) :
|
|||||||
it.controller !is MangaController &&
|
it.controller !is MangaController &&
|
||||||
it.controller !is MigrationListController &&
|
it.controller !is MigrationListController &&
|
||||||
it.controller !is PreMigrationController
|
it.controller !is PreMigrationController
|
||||||
} + MangaController(manga).withFadeTransaction()
|
} + MangaController(manga.id!!).withFadeTransaction()
|
||||||
router.setBackstack(newStack, OneWayFadeChangeHandler())
|
router.setBackstack(newStack, OneWayFadeChangeHandler())
|
||||||
return@launchUI
|
return@launchUI
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ class MigrationProcessHolder(
|
|||||||
.onEach {
|
.onEach {
|
||||||
adapter.controller.router.pushController(
|
adapter.controller.router.pushController(
|
||||||
MangaController(
|
MangaController(
|
||||||
manga,
|
manga.id!!,
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -103,7 +103,7 @@ class MigrationProcessHolder(
|
|||||||
.onEach {
|
.onEach {
|
||||||
adapter.controller.router.pushController(
|
adapter.controller.router.pushController(
|
||||||
MangaController(
|
MangaController(
|
||||||
searchResult,
|
searchResult.id!!,
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -760,7 +760,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||||||
val item = adapter?.getItem(position) as? SourceItem ?: return false
|
val item = adapter?.getItem(position) as? SourceItem ?: return false
|
||||||
router.pushController(
|
router.pushController(
|
||||||
MangaController(
|
MangaController(
|
||||||
item.manga,
|
item.manga.id!!,
|
||||||
true,
|
true,
|
||||||
args.getParcelable(MangaController.SMART_SEARCH_CONFIG_EXTRA),
|
args.getParcelable(MangaController.SMART_SEARCH_CONFIG_EXTRA),
|
||||||
),
|
),
|
||||||
|
@ -100,7 +100,7 @@ open class SourceFeedController :
|
|||||||
*/
|
*/
|
||||||
override fun onMangaClick(manga: Manga) {
|
override fun onMangaClick(manga: Manga) {
|
||||||
// Open MangaController.
|
// Open MangaController.
|
||||||
router.pushController(MangaController(manga, true).withFadeTransaction())
|
router.pushController(MangaController(manga.id!!, true).withFadeTransaction())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,7 +71,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))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -585,7 +585,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()
|
||||||
|
@ -142,9 +142,9 @@ class MangaController :
|
|||||||
|
|
||||||
constructor(history: HistoryWithRelations) : this(history.mangaId)
|
constructor(history: HistoryWithRelations) : this(history.mangaId)
|
||||||
|
|
||||||
constructor(manga: Manga?, fromSource: Boolean = false, smartSearchConfig: SourcesController.SmartSearchConfig? = null, update: Boolean = false) : super(
|
constructor(mangaId: Long, fromSource: Boolean = false, smartSearchConfig: SourcesController.SmartSearchConfig? = null, update: 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,
|
||||||
// SY -->
|
// SY -->
|
||||||
SMART_SEARCH_CONFIG_EXTRA to smartSearchConfig,
|
SMART_SEARCH_CONFIG_EXTRA to smartSearchConfig,
|
||||||
@ -152,16 +152,12 @@ class MangaController :
|
|||||||
// SY <--
|
// SY <--
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
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))
|
||||||
|
|
||||||
@ -382,7 +378,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)
|
||||||
|
|
||||||
presenter.redirectFlow
|
presenter.redirectFlow
|
||||||
.onEach { redirect ->
|
.onEach { redirect ->
|
||||||
@ -766,7 +762,7 @@ class MangaController :
|
|||||||
router?.popCurrentController()
|
router?.popCurrentController()
|
||||||
router?.replaceTopController(
|
router?.replaceTopController(
|
||||||
MangaController(
|
MangaController(
|
||||||
mergedManga,
|
mergedManga.id!!,
|
||||||
true,
|
true,
|
||||||
update = true,
|
update = true,
|
||||||
).withFadeTransaction(),
|
).withFadeTransaction(),
|
||||||
|
@ -15,6 +15,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.source.online.MetadataSource
|
import eu.kanade.tachiyomi.source.online.MetadataSource
|
||||||
@ -306,33 +307,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(source, ::getMergedSourcesString)
|
||||||
.filterNot { it in listOf("all", "other") }
|
|
||||||
|
|
||||||
// SY -->
|
|
||||||
val isMergedSource = source.id == MERGED_SOURCE_ID
|
|
||||||
// SY <--
|
|
||||||
val hasOneActiveLanguages = enabledLanguages.size == 1
|
|
||||||
val isInEnabledLanguages = source.lang in enabledLanguages
|
|
||||||
text = when {
|
|
||||||
// SY -->
|
|
||||||
isMergedSource && hasOneActiveLanguages -> getMergedSourcesString(
|
|
||||||
enabledLanguages,
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
isMergedSource -> getMergedSourcesString(
|
|
||||||
enabledLanguages,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
// SY <--
|
|
||||||
// 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!!))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,7 +15,6 @@ import eu.kanade.tachiyomi.ui.manga.MangaController
|
|||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.plus
|
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
class SmartSearchController(bundle: Bundle? = null) : NucleusController<EhSmartSearchBinding, SmartSearchPresenter>() {
|
class SmartSearchController(bundle: Bundle? = null) : NucleusController<EhSmartSearchBinding, SmartSearchPresenter>() {
|
||||||
@ -44,7 +43,7 @@ class SmartSearchController(bundle: Bundle? = null) : NucleusController<EhSmartS
|
|||||||
presenter.smartSearchFlow
|
presenter.smartSearchFlow
|
||||||
.onEach { results ->
|
.onEach { results ->
|
||||||
if (results is SmartSearchPresenter.SearchResults.Found) {
|
if (results is SmartSearchPresenter.SearchResults.Found) {
|
||||||
val transaction = MangaController(results.manga, true, smartSearchConfig).withFadeTransaction()
|
val transaction = MangaController(results.manga.id!!, true, smartSearchConfig).withFadeTransaction()
|
||||||
router.replaceTopController(transaction)
|
router.replaceTopController(transaction)
|
||||||
} else {
|
} else {
|
||||||
if (results is SmartSearchPresenter.SearchResults.NotFound) {
|
if (results is SmartSearchPresenter.SearchResults.NotFound) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user