mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 16:31:50 +01:00
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
|
* Returns history of recent manga containing last read chapter
|
||||||
* @param date recent date range
|
* @param date recent date range
|
||||||
*/
|
*/
|
||||||
fun getRecentManga(date: Date) = db.get()
|
fun getRecentManga(date: Date, offset: Int = 0) = db.get()
|
||||||
.listOfObjects(MangaChapterHistory::class.java)
|
.listOfObjects(MangaChapterHistory::class.java)
|
||||||
.withQuery(RawQuery.builder()
|
.withQuery(RawQuery.builder()
|
||||||
.query(getRecentMangasQuery())
|
.query(getRecentMangasQuery(offset))
|
||||||
.args(date.time)
|
.args(date.time)
|
||||||
.observesTables(HistoryTable.TABLE)
|
.observesTables(HistoryTable.TABLE)
|
||||||
.build())
|
.build())
|
||||||
|
@ -47,7 +47,7 @@ fun getRecentsQuery() = """
|
|||||||
* and are read after the given time period
|
* and are read after the given time period
|
||||||
* @return return limit is 25
|
* @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}.*
|
SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, ${Manga.TABLE}.*, ${Chapter.TABLE}.*, ${History.TABLE}.*
|
||||||
FROM ${Manga.TABLE}
|
FROM ${Manga.TABLE}
|
||||||
JOIN ${Chapter.TABLE}
|
JOIN ${Chapter.TABLE}
|
||||||
@ -62,7 +62,7 @@ fun getRecentMangasQuery() = """
|
|||||||
ON ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} = max_last_read.${Chapter.COL_MANGA_ID}
|
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}
|
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
|
ORDER BY max_last_read.${History.COL_LAST_READ} DESC
|
||||||
LIMIT 25
|
LIMIT 25 OFFSET $offset
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fun getHistoryByMangaId() = """
|
fun getHistoryByMangaId() = """
|
||||||
|
@ -72,9 +72,9 @@ class RecentChaptersController : NucleusController<RecentChaptersPresenter>(),
|
|||||||
super.onViewCreated(view)
|
super.onViewCreated(view)
|
||||||
view.context.notificationManager.cancel(Notifications.ID_NEW_CHAPTERS)
|
view.context.notificationManager.cancel(Notifications.ID_NEW_CHAPTERS)
|
||||||
// Init RecyclerView and adapter
|
// Init RecyclerView and adapter
|
||||||
val layoutManager = androidx.recyclerview.widget.LinearLayoutManager(view.context)
|
val layoutManager = LinearLayoutManager(view.context)
|
||||||
recycler.layoutManager = layoutManager
|
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)
|
recycler.setHasFixedSize(true)
|
||||||
adapter = RecentChaptersAdapter(this@RecentChaptersController)
|
adapter = RecentChaptersAdapter(this@RecentChaptersController)
|
||||||
recycler.adapter = adapter
|
recycler.adapter = adapter
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.kanade.tachiyomi.ui.recently_read
|
package eu.kanade.tachiyomi.ui.recently_read
|
||||||
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
|
import eu.davidea.flexibleadapter.items.IFlexible
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
@ -16,7 +17,7 @@ import java.text.DecimalFormatSymbols
|
|||||||
* @constructor creates an instance of the adapter.
|
* @constructor creates an instance of the adapter.
|
||||||
*/
|
*/
|
||||||
class RecentlyReadAdapter(controller: RecentlyReadController)
|
class RecentlyReadAdapter(controller: RecentlyReadController)
|
||||||
: FlexibleAdapter<RecentlyReadItem>(null, controller, true) {
|
: FlexibleAdapter<IFlexible<*>>(null, controller, true) {
|
||||||
|
|
||||||
val sourceManager by injectLazy<SourceManager>()
|
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.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
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.manga.MangaController
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||||
import eu.kanade.tachiyomi.util.RecyclerWindowInsetsListener
|
import eu.kanade.tachiyomi.util.RecyclerWindowInsetsListener
|
||||||
@ -23,6 +24,7 @@ import kotlinx.android.synthetic.main.recently_read_controller.*
|
|||||||
*/
|
*/
|
||||||
class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
||||||
FlexibleAdapter.OnUpdateListener,
|
FlexibleAdapter.OnUpdateListener,
|
||||||
|
FlexibleAdapter.EndlessScrollListener,
|
||||||
RecentlyReadAdapter.OnRemoveClickListener,
|
RecentlyReadAdapter.OnRemoveClickListener,
|
||||||
RecentlyReadAdapter.OnResumeClickListener,
|
RecentlyReadAdapter.OnResumeClickListener,
|
||||||
RecentlyReadAdapter.OnCoverClickListener,
|
RecentlyReadAdapter.OnCoverClickListener,
|
||||||
@ -34,6 +36,11 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
|||||||
var adapter: RecentlyReadAdapter? = null
|
var adapter: RecentlyReadAdapter? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endless loading item.
|
||||||
|
*/
|
||||||
|
private var progressItem: ProgressItem? = null
|
||||||
|
|
||||||
override fun getTitle(): String? {
|
override fun getTitle(): String? {
|
||||||
return resources?.getString(R.string.label_recent_manga)
|
return resources?.getString(R.string.label_recent_manga)
|
||||||
}
|
}
|
||||||
@ -55,7 +62,7 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
|||||||
super.onViewCreated(view)
|
super.onViewCreated(view)
|
||||||
|
|
||||||
// Initialize adapter
|
// Initialize adapter
|
||||||
recycler.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(view.context)
|
recycler.layoutManager = LinearLayoutManager(view.context)
|
||||||
adapter = RecentlyReadAdapter(this@RecentlyReadController)
|
adapter = RecentlyReadAdapter(this@RecentlyReadController)
|
||||||
recycler.setHasFixedSize(true)
|
recycler.setHasFixedSize(true)
|
||||||
recycler.adapter = adapter
|
recycler.adapter = adapter
|
||||||
@ -73,7 +80,14 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
|||||||
* @param mangaHistory list of manga history
|
* @param mangaHistory list of manga history
|
||||||
*/
|
*/
|
||||||
fun onNextManga(mangaHistory: List<RecentlyReadItem>) {
|
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) {
|
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) {
|
override fun onResumeClick(position: Int) {
|
||||||
val activity = activity ?: return
|
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)
|
val nextChapter = presenter.getNextChapter(chapter, manga)
|
||||||
if (nextChapter != null) {
|
if (nextChapter != null) {
|
||||||
@ -98,12 +129,12 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onRemoveClick(position: Int) {
|
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)
|
RemoveHistoryDialog(this, manga, history).showDialog(router)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCoverClick(position: Int, lastTouchY: Float) {
|
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())
|
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.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
|
import rx.Subscription
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
|
import rx.schedulers.Schedulers
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Comparator
|
import java.util.Comparator
|
||||||
@ -28,24 +30,34 @@ class RecentlyReadPresenter : BasePresenter<RecentlyReadController>() {
|
|||||||
override fun onCreate(savedState: Bundle?) {
|
override fun onCreate(savedState: Bundle?) {
|
||||||
super.onCreate(savedState)
|
super.onCreate(savedState)
|
||||||
|
|
||||||
|
//pageSubscription?.let { remove(it) }
|
||||||
// Used to get a list of recently read manga
|
// Used to get a list of recently read manga
|
||||||
getRecentMangaObservable()
|
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
|
* Get recent manga observable
|
||||||
* @return list of history
|
* @return list of history
|
||||||
*/
|
*/
|
||||||
fun getRecentMangaObservable(): Observable<List<RecentlyReadItem>> {
|
private fun getRecentMangaObservable(offset: Int = 0): Observable<List<RecentlyReadItem>> {
|
||||||
// Set date for recent manga
|
// Set date for recent manga
|
||||||
val cal = Calendar.getInstance()
|
val cal = Calendar.getInstance()
|
||||||
cal.time = Date()
|
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) }
|
.map { recents -> recents.map(::RecentlyReadItem) }
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user