|
@@ -5,10 +5,14 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
|
import eu.kanade.tachiyomi.data.database.models.History
|
|
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.data.database.models.MangaChapterHistory
|
|
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
|
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
|
|
|
+import eu.kanade.tachiyomi.ui.recent.DateSectionItem
|
|
|
|
+import eu.kanade.tachiyomi.util.lang.toDateKey
|
|
import java.util.Calendar
|
|
import java.util.Calendar
|
|
import java.util.Comparator
|
|
import java.util.Comparator
|
|
import java.util.Date
|
|
import java.util.Date
|
|
|
|
+import java.util.TreeMap
|
|
import rx.Observable
|
|
import rx.Observable
|
|
import rx.android.schedulers.AndroidSchedulers
|
|
import rx.android.schedulers.AndroidSchedulers
|
|
import uy.kohesive.injekt.injectLazy
|
|
import uy.kohesive.injekt.injectLazy
|
|
@@ -38,13 +42,21 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
|
|
* @return list of history
|
|
* @return list of history
|
|
*/
|
|
*/
|
|
fun getRecentMangaObservable(): Observable<List<HistoryItem>> {
|
|
fun getRecentMangaObservable(): Observable<List<HistoryItem>> {
|
|
- // Set date for recent manga
|
|
|
|
|
|
+ // Set date limit 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.MONTH, -1)
|
|
|
|
|
|
return db.getRecentManga(cal.time).asRxObservable()
|
|
return db.getRecentManga(cal.time).asRxObservable()
|
|
- .map { recents -> recents.map(::HistoryItem) }
|
|
|
|
|
|
+ .map { recents ->
|
|
|
|
+ val map = TreeMap<Date, MutableList<MangaChapterHistory>> { d1, d2 -> d2.compareTo(d1) }
|
|
|
|
+ val byDay = recents
|
|
|
|
+ .groupByTo(map, { it.history.last_read.toDateKey() })
|
|
|
|
+ byDay.flatMap {
|
|
|
|
+ val dateItem = DateSectionItem(it.key)
|
|
|
|
+ it.value.map { HistoryItem(it, dateItem) }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
}
|
|
}
|
|
|
|
|