Recent Reads now expanded to a year
also has lazy loading
This commit is contained in:
parent
4c5fc25a68
commit
011510574d
@ -22,10 +22,10 @@ interface HistoryQueries : DbProvider {
|
||||
* Returns history of recent manga containing last read chapter
|
||||
* @param date recent date range
|
||||
*/
|
||||
fun getRecentManga(date: Date) = db.get()
|
||||
fun getRecentManga(date: Date, offset: Int = 0) = db.get()
|
||||
.listOfObjects(MangaChapterHistory::class.java)
|
||||
.withQuery(RawQuery.builder()
|
||||
.query(getRecentMangasQuery())
|
||||
.query(getRecentMangasQuery(offset))
|
||||
.args(date.time)
|
||||
.observesTables(HistoryTable.TABLE)
|
||||
.build())
|
||||
|
@ -47,7 +47,7 @@ fun getRecentsQuery() = """
|
||||
* and are read after the given time period
|
||||
* @return return limit is 25
|
||||
*/
|
||||
fun getRecentMangasQuery() = """
|
||||
fun getRecentMangasQuery(offset: Int = 0) = """
|
||||
SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, ${Manga.TABLE}.*, ${Chapter.TABLE}.*, ${History.TABLE}.*
|
||||
FROM ${Manga.TABLE}
|
||||
JOIN ${Chapter.TABLE}
|
||||
@ -62,7 +62,7 @@ fun getRecentMangasQuery() = """
|
||||
ON ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} = max_last_read.${Chapter.COL_MANGA_ID}
|
||||
WHERE ${History.TABLE}.${History.COL_LAST_READ} > ? AND max_last_read.${History.COL_CHAPTER_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
|
||||
ORDER BY max_last_read.${History.COL_LAST_READ} DESC
|
||||
LIMIT 25
|
||||
LIMIT 25 OFFSET $offset
|
||||
"""
|
||||
|
||||
fun getHistoryByMangaId() = """
|
||||
|
@ -72,9 +72,9 @@ class RecentChaptersController : NucleusController<RecentChaptersPresenter>(),
|
||||
super.onViewCreated(view)
|
||||
view.context.notificationManager.cancel(Notifications.ID_NEW_CHAPTERS)
|
||||
// Init RecyclerView and adapter
|
||||
val layoutManager = androidx.recyclerview.widget.LinearLayoutManager(view.context)
|
||||
val layoutManager = LinearLayoutManager(view.context)
|
||||
recycler.layoutManager = layoutManager
|
||||
recycler.addItemDecoration(androidx.recyclerview.widget.DividerItemDecoration(view.context, androidx.recyclerview.widget.DividerItemDecoration.VERTICAL))
|
||||
recycler.addItemDecoration(DividerItemDecoration(view.context, DividerItemDecoration.VERTICAL))
|
||||
recycler.setHasFixedSize(true)
|
||||
adapter = RecentChaptersAdapter(this@RecentChaptersController)
|
||||
recycler.adapter = adapter
|
||||
|
@ -1,6 +1,7 @@
|
||||
package eu.kanade.tachiyomi.ui.recently_read
|
||||
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.text.DateFormat
|
||||
@ -16,7 +17,7 @@ import java.text.DecimalFormatSymbols
|
||||
* @constructor creates an instance of the adapter.
|
||||
*/
|
||||
class RecentlyReadAdapter(controller: RecentlyReadController)
|
||||
: FlexibleAdapter<RecentlyReadItem>(null, controller, true) {
|
||||
: FlexibleAdapter<IFlexible<*>>(null, controller, true) {
|
||||
|
||||
val sourceManager by injectLazy<SourceManager>()
|
||||
|
||||
|
@ -10,6 +10,7 @@ import eu.kanade.tachiyomi.data.database.models.History
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.catalogue.browse.ProgressItem
|
||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
import eu.kanade.tachiyomi.util.RecyclerWindowInsetsListener
|
||||
@ -23,6 +24,7 @@ import kotlinx.android.synthetic.main.recently_read_controller.*
|
||||
*/
|
||||
class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
||||
FlexibleAdapter.OnUpdateListener,
|
||||
FlexibleAdapter.EndlessScrollListener,
|
||||
RecentlyReadAdapter.OnRemoveClickListener,
|
||||
RecentlyReadAdapter.OnResumeClickListener,
|
||||
RecentlyReadAdapter.OnCoverClickListener,
|
||||
@ -34,6 +36,11 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
||||
var adapter: RecentlyReadAdapter? = null
|
||||
private set
|
||||
|
||||
/**
|
||||
* Endless loading item.
|
||||
*/
|
||||
private var progressItem: ProgressItem? = null
|
||||
|
||||
override fun getTitle(): String? {
|
||||
return resources?.getString(R.string.label_recent_manga)
|
||||
}
|
||||
@ -55,7 +62,7 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
||||
super.onViewCreated(view)
|
||||
|
||||
// Initialize adapter
|
||||
recycler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(view.context)
|
||||
recycler.layoutManager = LinearLayoutManager(view.context)
|
||||
adapter = RecentlyReadAdapter(this@RecentlyReadController)
|
||||
recycler.setHasFixedSize(true)
|
||||
recycler.adapter = adapter
|
||||
@ -73,7 +80,14 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
||||
* @param mangaHistory list of manga history
|
||||
*/
|
||||
fun onNextManga(mangaHistory: List<RecentlyReadItem>) {
|
||||
adapter?.updateDataSet(mangaHistory)
|
||||
if (adapter?.itemCount ?: 0 == 0)
|
||||
resetProgressItem()
|
||||
adapter?.onLoadMoreComplete(mangaHistory)
|
||||
}
|
||||
|
||||
fun onAddPageError(error: Throwable) {
|
||||
adapter?.onLoadMoreComplete(null)
|
||||
adapter?.endlessTargetCount = 1
|
||||
}
|
||||
|
||||
override fun onUpdateEmptyView(size: Int) {
|
||||
@ -84,9 +98,26 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new progress item and reenables the scroll listener.
|
||||
*/
|
||||
private fun resetProgressItem() {
|
||||
progressItem = ProgressItem()
|
||||
adapter?.endlessTargetCount = 0
|
||||
adapter?.setEndlessScrollListener(this, progressItem!!)
|
||||
}
|
||||
|
||||
override fun onLoadMore(lastPosition: Int, currentPage: Int) {
|
||||
val adapter = adapter ?: return
|
||||
presenter.requestNext(adapter.itemCount)
|
||||
}
|
||||
|
||||
override fun noMoreLoad(newItemsSize: Int) { }
|
||||
|
||||
|
||||
override fun onResumeClick(position: Int) {
|
||||
val activity = activity ?: return
|
||||
val (manga, chapter, _) = adapter?.getItem(position)?.mch ?: return
|
||||
val (manga, chapter, _) = (adapter?.getItem(position) as? RecentlyReadItem)?.mch ?: return
|
||||
|
||||
val nextChapter = presenter.getNextChapter(chapter, manga)
|
||||
if (nextChapter != null) {
|
||||
@ -98,12 +129,12 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
||||
}
|
||||
|
||||
override fun onRemoveClick(position: Int) {
|
||||
val (manga, _, history) = adapter?.getItem(position)?.mch ?: return
|
||||
val (manga, _, history) = (adapter?.getItem(position) as? RecentlyReadItem)?.mch ?: return
|
||||
RemoveHistoryDialog(this, manga, history).showDialog(router)
|
||||
}
|
||||
|
||||
override fun onCoverClick(position: Int, lastTouchY: Float) {
|
||||
val manga = adapter?.getItem(position)?.mch?.manga ?: return
|
||||
val manga = (adapter?.getItem(position) as? RecentlyReadItem)?.mch?.manga ?: return
|
||||
router.pushController(MangaController(manga, lastTouchY).withFadeTransaction())
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,9 @@ import eu.kanade.tachiyomi.data.database.models.History
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.schedulers.Schedulers
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Calendar
|
||||
import java.util.Comparator
|
||||
@ -28,22 +30,32 @@ class RecentlyReadPresenter : BasePresenter<RecentlyReadController>() {
|
||||
override fun onCreate(savedState: Bundle?) {
|
||||
super.onCreate(savedState)
|
||||
|
||||
//pageSubscription?.let { remove(it) }
|
||||
// Used to get a list of recently read manga
|
||||
getRecentMangaObservable()
|
||||
.subscribeLatestCache(RecentlyReadController::onNextManga)
|
||||
.subscribeLatestCache({ view, mangas ->
|
||||
view.onNextManga(mangas)
|
||||
}, RecentlyReadController::onAddPageError)
|
||||
}
|
||||
|
||||
fun requestNext(offset: Int) {
|
||||
getRecentMangaObservable((offset))
|
||||
.subscribeLatestCache({ view, mangas ->
|
||||
view.onNextManga(mangas)
|
||||
}, RecentlyReadController::onAddPageError)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recent manga observable
|
||||
* @return list of history
|
||||
*/
|
||||
fun getRecentMangaObservable(): Observable<List<RecentlyReadItem>> {
|
||||
private fun getRecentMangaObservable(offset: Int = 0): Observable<List<RecentlyReadItem>> {
|
||||
// Set date for recent manga
|
||||
val cal = Calendar.getInstance()
|
||||
cal.time = Date()
|
||||
cal.add(Calendar.MONTH, -1)
|
||||
cal.add(Calendar.YEAR, -1)
|
||||
|
||||
return db.getRecentManga(cal.time).asRxObservable()
|
||||
return db.getRecentManga(cal.time, offset).asRxObservable()
|
||||
.map { recents -> recents.map(::RecentlyReadItem) }
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user