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) { if (manga.initialized) {
// Update view. // Update view.
setMangaInfo(manga, source, chapters) setMangaInfo(manga, source, chapters)
if (fromSource && !presenter.hasRequested) {
fetchMangaFromSource(fetchManga = false)
}
} else { } else {
// Initialize manga. // Initialize manga.
fetchMangaFromSource() fetchMangaFromSource()
@ -621,10 +624,6 @@ class MangaAllInOneController :
} }
} }
fun setTracking() {
binding.btnTracking.icon = resources!!.getDrawable(R.drawable.ic_cloud_white_24dp, null)
}
private fun hideMangaInfo() { private fun hideMangaInfo() {
binding.mangaSummaryLabel.gone() binding.mangaSummaryLabel.gone()
binding.mangaSummary.gone() binding.mangaSummary.gone()
@ -759,10 +758,10 @@ class MangaAllInOneController :
/** /**
* Start fetching manga information from source. * 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) setRefreshing(true)
// Call presenter and start fetching manga information // Call presenter and start fetching manga information
presenter.fetchMangaFromSource(manualFetch) presenter.fetchMangaFromSource(manualFetch, fetchManga, fetchChapters)
} }
fun onFetchMangaDone() { fun onFetchMangaDone() {
@ -911,10 +910,10 @@ class MangaAllInOneController :
// CHAPTER FUNCTIONS START HERE // CHAPTER FUNCTIONS START HERE
override fun onDestroyView(view: View) { override fun onDestroyView(view: View) {
super.onDestroyView(view)
destroyActionModeIfNeeded() destroyActionModeIfNeeded()
binding.actionToolbar.destroy() binding.actionToolbar.destroy()
adapter = null adapter = null
super.onDestroyView(view)
} }
override fun onActivityResumed(activity: Activity) { 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.ChapterItem
import eu.kanade.tachiyomi.ui.manga.chapter.ChaptersPresenter import eu.kanade.tachiyomi.ui.manga.chapter.ChaptersPresenter
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
import eu.kanade.tachiyomi.util.isLocal
import eu.kanade.tachiyomi.util.prepUpdateCover import eu.kanade.tachiyomi.util.prepUpdateCover
import eu.kanade.tachiyomi.util.removeCovers import eu.kanade.tachiyomi.util.removeCovers
import exh.MERGED_SOURCE_ID import exh.MERGED_SOURCE_ID
@ -84,21 +83,13 @@ class MangaAllInOnePresenter(
// EXH --> // EXH -->
private val updateHelper: EHentaiUpdateHelper by injectLazy() private val updateHelper: EHentaiUpdateHelper by injectLazy()
val redirectUserRelay = BehaviorRelay.create<ChaptersPresenter.EXHRedirect>() private val redirectUserRelay = BehaviorRelay.create<ChaptersPresenter.EXHRedirect>()
// EXH <-- // EXH <--
override fun onCreate(savedState: Bundle?) { override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState) super.onCreate(savedState)
if (manga.isLocal()) { updateManga()
controller.setRefreshing(true)
fetchMangaFromSource()
} else if (!manga.initialized) {
controller.setRefreshing(true)
fetchMangaFromSource()
} else {
updateManga()
}
// Listen for download status changes // Listen for download status changes
observeDownloads() observeDownloads()
@ -139,7 +130,7 @@ class MangaAllInOnePresenter(
this.chapters = applyChapterFilters(chapters) this.chapters = applyChapterFilters(chapters)
} }
fun updateChaptersView() { private fun updateChaptersView() {
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
updateChapters() updateChapters()
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
@ -182,11 +173,13 @@ class MangaAllInOnePresenter(
/** /**
* Fetch manga information from source. * Fetch manga information from source.
*/ */
fun fetchMangaFromSource(manualFetch: Boolean = false, FetchManga: Boolean = true, FetchChapters: Boolean = true) { fun fetchMangaFromSource(manualFetch: Boolean = false, fetchManga: Boolean = true, fetchChapters: Boolean = true) {
hasRequested = true if (fetchChapters) {
hasRequested = true
}
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
if (FetchManga) { if (fetchManga) {
val networkManga = try { val networkManga = try {
source.fetchMangaDetails(manga).toBlocking().single() source.fetchMangaDetails(manga).toBlocking().single()
} catch (e: Exception) { } catch (e: Exception) {
@ -201,7 +194,7 @@ class MangaAllInOnePresenter(
} }
} }
var chapters: List<SChapter> = listOf() var chapters: List<SChapter> = listOf()
if (FetchChapters) { if (fetchChapters) {
try { try {
chapters = source.fetchChapterList(manga).toBlocking().single() chapters = source.fetchChapterList(manga).toBlocking().single()
} catch (e: Exception) { } catch (e: Exception) {
@ -210,7 +203,7 @@ class MangaAllInOnePresenter(
} }
} }
try { try {
if (FetchChapters) { if (fetchChapters) {
syncChaptersWithSource(db, chapters, manga, source) syncChaptersWithSource(db, chapters, manga, source)
updateChapters() updateChapters()
@ -303,12 +296,7 @@ class MangaAllInOnePresenter(
fun moveMangaToCategory(manga: Manga, category: Category?) { fun moveMangaToCategory(manga: Manga, category: Category?) {
moveMangaToCategories(manga, listOfNotNull(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 { suspend fun smartSearchMerge(manga: Manga, originalMangaId: Long): Manga {
val originalManga = db.getManga(originalMangaId).await() val originalManga = db.getManga(originalMangaId).await()
?: throw IllegalArgumentException("Unknown manga ID: $originalMangaId") ?: throw IllegalArgumentException("Unknown manga ID: $originalMangaId")