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