Fix multiple bugs when fetching manga info

This commit is contained in:
Jobobby04 2020-05-17 17:11:40 -04:00
parent 5271abbd1f
commit f5f7971cb5
2 changed files with 16 additions and 29 deletions

View File

@ -467,6 +467,9 @@ class MangaAllInOneController :
if (manga.initialized) {
// Update view.
setMangaInfo(manga, source, chapters)
if (fromSource && !presenter.hasRequested) {
fetchMangaFromSource(fetchManga = false)
}
} else {
// Initialize manga.
fetchMangaFromSource()
@ -621,10 +624,6 @@ class MangaAllInOneController :
}
}
fun setTracking() {
binding.btnTracking.icon = resources!!.getDrawable(R.drawable.ic_cloud_white_24dp, null)
}
private fun hideMangaInfo() {
binding.mangaSummaryLabel.gone()
binding.mangaSummary.gone()
@ -759,10 +758,10 @@ class MangaAllInOneController :
/**
* Start fetching manga information from source.
*/
private fun fetchMangaFromSource(manualFetch: Boolean = false) {
private fun fetchMangaFromSource(manualFetch: Boolean = false, fetchManga: Boolean = true, fetchChapters: Boolean = true) {
setRefreshing(true)
// Call presenter and start fetching manga information
presenter.fetchMangaFromSource(manualFetch)
presenter.fetchMangaFromSource(manualFetch, fetchManga, fetchChapters)
}
fun onFetchMangaDone() {
@ -911,10 +910,10 @@ class MangaAllInOneController :
// CHAPTER FUNCTIONS START HERE
override fun onDestroyView(view: View) {
super.onDestroyView(view)
destroyActionModeIfNeeded()
binding.actionToolbar.destroy()
adapter = null
super.onDestroyView(view)
}
override fun onActivityResumed(activity: Activity) {

View File

@ -21,7 +21,6 @@ import eu.kanade.tachiyomi.ui.browse.source.SourceController
import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem
import eu.kanade.tachiyomi.ui.manga.chapter.ChaptersPresenter
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
import eu.kanade.tachiyomi.util.isLocal
import eu.kanade.tachiyomi.util.prepUpdateCover
import eu.kanade.tachiyomi.util.removeCovers
import exh.MERGED_SOURCE_ID
@ -84,21 +83,13 @@ class MangaAllInOnePresenter(
// EXH -->
private val updateHelper: EHentaiUpdateHelper by injectLazy()
val redirectUserRelay = BehaviorRelay.create<ChaptersPresenter.EXHRedirect>()
private val redirectUserRelay = BehaviorRelay.create<ChaptersPresenter.EXHRedirect>()
// EXH <--
override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState)
if (manga.isLocal()) {
controller.setRefreshing(true)
fetchMangaFromSource()
} else if (!manga.initialized) {
controller.setRefreshing(true)
fetchMangaFromSource()
} else {
updateManga()
}
updateManga()
// Listen for download status changes
observeDownloads()
@ -139,7 +130,7 @@ class MangaAllInOnePresenter(
this.chapters = applyChapterFilters(chapters)
}
fun updateChaptersView() {
private fun updateChaptersView() {
scope.launch(Dispatchers.IO) {
updateChapters()
withContext(Dispatchers.Main) {
@ -182,11 +173,13 @@ class MangaAllInOnePresenter(
/**
* Fetch manga information from source.
*/
fun fetchMangaFromSource(manualFetch: Boolean = false, FetchManga: Boolean = true, FetchChapters: Boolean = true) {
hasRequested = true
fun fetchMangaFromSource(manualFetch: Boolean = false, fetchManga: Boolean = true, fetchChapters: Boolean = true) {
if (fetchChapters) {
hasRequested = true
}
scope.launch(Dispatchers.IO) {
if (FetchManga) {
if (fetchManga) {
val networkManga = try {
source.fetchMangaDetails(manga).toBlocking().single()
} catch (e: Exception) {
@ -201,7 +194,7 @@ class MangaAllInOnePresenter(
}
}
var chapters: List<SChapter> = listOf()
if (FetchChapters) {
if (fetchChapters) {
try {
chapters = source.fetchChapterList(manga).toBlocking().single()
} catch (e: Exception) {
@ -210,7 +203,7 @@ class MangaAllInOnePresenter(
}
}
try {
if (FetchChapters) {
if (fetchChapters) {
syncChaptersWithSource(db, chapters, manga, source)
updateChapters()
@ -303,12 +296,7 @@ class MangaAllInOnePresenter(
fun moveMangaToCategory(manga: Manga, category: Category?) {
moveMangaToCategories(manga, listOfNotNull(category))
}
/*
suspend fun recommendationView(manga: Manga): Manga {
val title = manga.title
val source = manga.source
}*/
suspend fun smartSearchMerge(manga: Manga, originalMangaId: Long): Manga {
val originalManga = db.getManga(originalMangaId).await()
?: throw IllegalArgumentException("Unknown manga ID: $originalMangaId")