mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Fix manual refresh for manga, attempt to fix last chapter and last updated
This commit is contained in:
		| @@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.util.system.getResourceColor | ||||
| import java.text.DateFormat | ||||
| import java.text.DecimalFormat | ||||
| import java.text.DecimalFormatSymbols | ||||
| import java.util.Date | ||||
| import kotlinx.coroutines.CoroutineScope | ||||
| import uy.kohesive.injekt.injectLazy | ||||
|  | ||||
| @@ -55,8 +56,8 @@ class MangaAllInOneAdapter( | ||||
|         fun openSmartSearch() | ||||
|         fun mangaPresenter(): MangaAllInOnePresenter | ||||
|         fun openRecommends() | ||||
|         fun onNextManga(manga: Manga, source: Source, chapters: List<MangaAllInOneChapterItem>) | ||||
|         fun setMangaInfo(manga: Manga, source: Source?, chapters: List<MangaAllInOneChapterItem>) | ||||
|         fun onNextManga(manga: Manga, source: Source, chapters: List<MangaAllInOneChapterItem>, lastUpdateDate: Date, chapterCount: Float) | ||||
|         fun setMangaInfo(manga: Manga, source: Source?, chapters: List<MangaAllInOneChapterItem>, lastUpdateDate: Date, chapterCount: Float) | ||||
|         fun openInWebView() | ||||
|         fun shareManga() | ||||
|         fun fetchMangaFromSource(manualFetch: Boolean = false, fetchManga: Boolean = true, fetchChapters: Boolean = true) | ||||
|   | ||||
| @@ -72,6 +72,7 @@ import kotlinx.coroutines.flow.launchIn | ||||
| import kotlinx.coroutines.flow.onEach | ||||
| import kotlinx.coroutines.withContext | ||||
| import reactivecircus.flowbinding.android.view.clicks | ||||
| import reactivecircus.flowbinding.swiperefreshlayout.refreshes | ||||
| import timber.log.Timber | ||||
| import uy.kohesive.injekt.Injekt | ||||
| import uy.kohesive.injekt.api.get | ||||
| @@ -192,6 +193,11 @@ class MangaAllInOneController : | ||||
|  | ||||
|         if (manga == null || source == null) return | ||||
|  | ||||
|         // Set SwipeRefresh to refresh manga data. | ||||
|         binding.swipeRefresh.refreshes() | ||||
|             .onEach { fetchMangaFromSource(manualFetch = true) } | ||||
|             .launchIn(scope) | ||||
|  | ||||
|         // Init RecyclerView and adapter | ||||
|         adapter = MangaAllInOneAdapter(this, view.context) | ||||
|  | ||||
| @@ -329,10 +335,10 @@ class MangaAllInOneController : | ||||
|      * @param manga manga object containing information about manga. | ||||
|      * @param source the source of the manga. | ||||
|      */ | ||||
|     override fun onNextManga(manga: Manga, source: Source, chapters: List<MangaAllInOneChapterItem>) { | ||||
|     override fun onNextManga(manga: Manga, source: Source, chapters: List<MangaAllInOneChapterItem>, lastUpdateDate: Date, chapterCount: Float) { | ||||
|         if (manga.initialized) { | ||||
|             // Update view. | ||||
|             setMangaInfo(manga, source, chapters) | ||||
|             setMangaInfo(manga, source, chapters, lastUpdateDate, chapterCount) | ||||
|             if (fromSource && !presenter.hasRequested && chapters.isNullOrEmpty()) { | ||||
|                 fetchMangaFromSource(fetchManga = false) | ||||
|             } | ||||
| @@ -348,7 +354,7 @@ class MangaAllInOneController : | ||||
|      * @param manga manga object containing information about manga. | ||||
|      * @param source the source of the manga. | ||||
|      */ | ||||
|     override fun setMangaInfo(manga: Manga, source: Source?, chapters: List<MangaAllInOneChapterItem>) { | ||||
|     override fun setMangaInfo(manga: Manga, source: Source?, chapters: List<MangaAllInOneChapterItem>, lastUpdateDate: Date, chapterCount: Float) { | ||||
|         val view = view ?: return | ||||
|  | ||||
|         if (update || | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package eu.kanade.tachiyomi.ui.manga | ||||
|  | ||||
| import android.content.Context | ||||
| import android.util.Log | ||||
| import android.view.View | ||||
| import androidx.core.content.ContextCompat | ||||
| import com.bumptech.glide.load.engine.DiskCacheStrategy | ||||
| @@ -284,6 +285,9 @@ class MangaAllInOneHolder( | ||||
|             } | ||||
|         ) | ||||
|  | ||||
|         setChapterCount(0F) | ||||
|         setLastUpdateDate(Date(0L)) | ||||
|  | ||||
|         // Set the favorite drawable to the correct one. | ||||
|         setFavoriteButtonState(manga.favorite) | ||||
|  | ||||
|   | ||||
| @@ -67,6 +67,10 @@ class MangaAllInOnePresenter( | ||||
|     var chapters: List<MangaAllInOneChapterItem> = emptyList() | ||||
|         private set | ||||
|  | ||||
|     lateinit var lastUpdateDate: Date | ||||
|  | ||||
|     var chapterCount: Float = 0F | ||||
|  | ||||
|     private val scope = CoroutineScope(Job() + Dispatchers.Default) | ||||
|  | ||||
|     /** | ||||
| @@ -138,29 +142,18 @@ class MangaAllInOnePresenter( | ||||
|             withContext(Dispatchers.Main) { | ||||
|                 Observable.just(manga) | ||||
|                     .observeOn(AndroidSchedulers.mainThread()) | ||||
|                     .subscribeLatestCache({ view, manga -> view.onNextManga(manga, source, chapters) }) | ||||
|                     .subscribeLatestCache({ view, manga -> view.onNextManga(manga, source, chapters, lastUpdateDate, chapterCount) }) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun updateChapterInfo() { | ||||
|         scope.launch(Dispatchers.IO) { | ||||
|             val lastUpdateDate = Date( | ||||
|             lastUpdateDate = Date( | ||||
|                 chapters.maxBy { it.date_upload }?.date_upload ?: 0 | ||||
|             ) | ||||
|  | ||||
|             val chapterCount = chapters.maxBy { it.chapter_number }?.chapter_number ?: 0f | ||||
|  | ||||
|             withContext(Dispatchers.Main) { | ||||
|                 // set chapter count | ||||
|                 Observable.just(chapterCount) | ||||
|                     .observeOn(AndroidSchedulers.mainThread()) | ||||
|                     .subscribeLatestCache({ view, chapterCount -> view.setChapterCount(chapterCount) }) | ||||
|                 // update last update date | ||||
|                 Observable.just(lastUpdateDate) | ||||
|                     .observeOn(AndroidSchedulers.mainThread()) | ||||
|                     .subscribeLatestCache({ view, lastUpdateDate -> view.setLastUpdateDate(lastUpdateDate) }) | ||||
|             } | ||||
|             chapterCount = chapters.maxBy { it.chapter_number }?.chapter_number ?: 0f | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -179,7 +172,7 @@ class MangaAllInOnePresenter( | ||||
|                 } else { | ||||
|                     Observable.just(manga) | ||||
|                 }.observeOn(AndroidSchedulers.mainThread()) | ||||
|                     .subscribeLatestCache({ view, manga -> view.onNextManga(manga, source, chapters) }) | ||||
|                     .subscribeLatestCache({ view, manga -> view.onNextManga(manga, source, chapters, lastUpdateDate, chapterCount) }) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user