mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Move history object outside of the chapter object
a bit of refactoring if you will
This commit is contained in:
parent
d3cb32af38
commit
9ffde130b9
7 changed files with 27 additions and 30 deletions
|
@ -21,9 +21,6 @@ interface Chapter : SChapter, Serializable {
|
|||
|
||||
var source_order: Int
|
||||
|
||||
var dateRead: Long?
|
||||
var history: History?
|
||||
|
||||
val isRecognizedNumber: Boolean
|
||||
get() = chapter_number >= 0f
|
||||
|
||||
|
|
|
@ -24,13 +24,6 @@ class ChapterImpl : Chapter {
|
|||
|
||||
override var date_upload: Long = 0
|
||||
|
||||
override var dateRead: Long? = null
|
||||
override var history: History? = null
|
||||
set(value) {
|
||||
field = value
|
||||
dateRead = history?.last_read
|
||||
}
|
||||
|
||||
override var chapter_number: Float = 0f
|
||||
|
||||
override var source_order: Int = 0
|
||||
|
|
|
@ -7,9 +7,11 @@ package eu.kanade.tachiyomi.data.database.models
|
|||
* @param chapter object containing chater
|
||||
* @param history object containing history
|
||||
*/
|
||||
data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val history: History, var extraChapters: List<Chapter> = emptyList()) {
|
||||
data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val history: History, var extraChapters: List<ChapterHistory> = emptyList()) {
|
||||
|
||||
companion object {
|
||||
fun createBlank() = MangaChapterHistory(MangaImpl(), ChapterImpl(), HistoryImpl())
|
||||
}
|
||||
}
|
||||
|
||||
data class ChapterHistory(val chapter: Chapter, var history: History? = null) : Chapter by chapter
|
||||
|
|
|
@ -5,6 +5,7 @@ import androidx.recyclerview.widget.ItemTouchHelper
|
|||
import com.fredporciuncula.flow.preferences.Preference
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.ChapterHistory
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
|
||||
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterAdapter
|
||||
|
@ -96,7 +97,7 @@ class RecentMangaAdapter(val delegate: RecentsInterface) :
|
|||
fun alwaysExpanded(): Boolean
|
||||
fun scope(): CoroutineScope
|
||||
fun getViewType(): RecentsViewType
|
||||
fun onItemLongClick(position: Int, chapter: Chapter): Boolean
|
||||
fun onItemLongClick(position: Int, chapter: ChapterHistory): Boolean
|
||||
}
|
||||
|
||||
override fun onItemSwiped(position: Int, direction: Int) {
|
||||
|
|
|
@ -17,6 +17,7 @@ import androidx.transition.TransitionManager
|
|||
import androidx.transition.TransitionSet
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.ChapterHistory
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.data.image.coil.loadManga
|
||||
import eu.kanade.tachiyomi.databinding.RecentMangaItemBinding
|
||||
|
@ -335,16 +336,16 @@ class RecentMangaHolder(
|
|||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun RecentSubChapterItemBinding.configureView(chapter: Chapter, item: RecentMangaItem) {
|
||||
private fun RecentSubChapterItemBinding.configureView(chapter: ChapterHistory, item: RecentMangaItem) {
|
||||
val context = itemView.context
|
||||
val showDLs = adapter.showDownloads
|
||||
title.text = chapter.preferredChapterName(context, item.mch.manga, adapter.preferences)
|
||||
title.setTextColor(ChapterUtil.readColor(context, chapter))
|
||||
val notReadYet = item.chapter.id != item.mch.chapter.id && item.mch.history.id != null
|
||||
subtitle.text = chapter.dateRead?.let { dateRead ->
|
||||
context.timeSpanFromNow(R.string.read_, dateRead)
|
||||
subtitle.text = chapter.history?.let { history ->
|
||||
context.timeSpanFromNow(R.string.read_, history.last_read)
|
||||
.takeIf {
|
||||
Date().time - dateRead < TimeUnit.DAYS.toMillis(1) || notReadYet
|
||||
Date().time - history.last_read < TimeUnit.DAYS.toMillis(1) || notReadYet
|
||||
}
|
||||
} ?: ""
|
||||
if (isUpdates && chapter.isRecognizedNumber &&
|
||||
|
|
|
@ -31,6 +31,7 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
|
|||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.backup.BackupRestoreService
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.ChapterHistory
|
||||
import eu.kanade.tachiyomi.data.database.models.History
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.download.DownloadService
|
||||
|
@ -653,7 +654,7 @@ class RecentsController(bundle: Bundle? = null) :
|
|||
override fun areExtraChaptersExpanded(position: Int): Boolean {
|
||||
if (alwaysExpanded()) return true
|
||||
val item = (adapter.getItem(position) as? RecentMangaItem) ?: return false
|
||||
val date = presenter.dateFormat.format(item.chapter.dateRead ?: item.chapter.date_fetch)
|
||||
val date = presenter.dateFormat.format(item.mch.history.last_read)
|
||||
val invertDefault = !adapter.collapseGrouped
|
||||
return presenter.expandedSectionsMap["${item.mch.manga} - $date"]?.xor(invertDefault)
|
||||
?: invertDefault
|
||||
|
@ -662,7 +663,7 @@ class RecentsController(bundle: Bundle? = null) :
|
|||
override fun updateExpandedExtraChapters(position: Int, expanded: Boolean) {
|
||||
if (alwaysExpanded()) return
|
||||
val item = (adapter.getItem(position) as? RecentMangaItem) ?: return
|
||||
val date = presenter.dateFormat.format(item.chapter.dateRead ?: item.chapter.date_fetch)
|
||||
val date = presenter.dateFormat.format(item.mch.history.last_read)
|
||||
val invertDefault = !adapter.collapseGrouped
|
||||
presenter.expandedSectionsMap["${item.mch.manga} - $date"] = expanded.xor(invertDefault)
|
||||
}
|
||||
|
@ -729,7 +730,7 @@ class RecentsController(bundle: Bundle? = null) :
|
|||
}
|
||||
}
|
||||
|
||||
override fun onItemLongClick(position: Int, chapter: Chapter): Boolean {
|
||||
override fun onItemLongClick(position: Int, chapter: ChapterHistory): Boolean {
|
||||
val history = chapter.history ?: return false
|
||||
val item = adapter.getItem(position) as? RecentMangaItem ?: return false
|
||||
val manga = item.mch.manga
|
||||
|
|
|
@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.recents
|
|||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.ChapterHistory
|
||||
import eu.kanade.tachiyomi.data.database.models.History
|
||||
import eu.kanade.tachiyomi.data.database.models.HistoryImpl
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
|
@ -185,7 +186,7 @@ class RecentsPresenter(
|
|||
.mapNotNull { (key, mchs) ->
|
||||
val manga = mchs.first().manga
|
||||
val chapters = mchs.map { mch ->
|
||||
mch.chapter.also { it.history = mch.history }
|
||||
ChapterHistory(mch.chapter, mch.history)
|
||||
}.filterChaptersByScanlators(manga)
|
||||
extraCount += mchs.size - chapters.size
|
||||
if (chapters.isEmpty()) return@mapNotNull null
|
||||
|
@ -193,8 +194,8 @@ class RecentsPresenter(
|
|||
val date = Date(it.mch.history.last_read)
|
||||
key == it.manga_id to dateFormat.format(date)
|
||||
}?.takeIf { updatePageCount }
|
||||
val sort = Comparator<Chapter> { c1, c2 ->
|
||||
c2.dateRead!!.compareTo(c1.dateRead!!)
|
||||
val sort = Comparator<ChapterHistory> { c1, c2 ->
|
||||
c2.history!!.last_read.compareTo(c1.history!!.last_read)
|
||||
}
|
||||
val (sortedChapters, firstChapter, subCount) =
|
||||
setupExtraChapters(existingItem, chapters, sort)
|
||||
|
@ -219,14 +220,15 @@ class RecentsPresenter(
|
|||
}
|
||||
.mapNotNull { (key, mcs) ->
|
||||
val manga = mcs.first().manga
|
||||
val chapters = mcs.map { it.chapter }.filterChaptersByScanlators(manga)
|
||||
val chapters = mcs.map { ChapterHistory(it.chapter) }
|
||||
.filterChaptersByScanlators(manga)
|
||||
extraCount += mcs.size - chapters.size
|
||||
if (chapters.isEmpty()) return@mapNotNull null
|
||||
val existingItem = recentItems.takeLast(ENDLESS_LIMIT).find {
|
||||
val date = Date(it.chapter.date_fetch)
|
||||
key == it.manga_id to dateFormat.format(date)
|
||||
}?.takeIf { updatePageCount }
|
||||
val sort: Comparator<Chapter> =
|
||||
val sort: Comparator<ChapterHistory> =
|
||||
ChapterSort(manga, chapterFilter, preferences)
|
||||
.sortComparator(true)
|
||||
val (sortedChapters, firstChapter, subCount) =
|
||||
|
@ -283,8 +285,8 @@ class RecentsPresenter(
|
|||
if (viewType.isHistory && nextChapter?.id != null &&
|
||||
nextChapter.id != it.chapter.id
|
||||
) {
|
||||
nextChapter.dateRead = it.chapter.dateRead
|
||||
it.extraChapters = listOf(it.chapter) + it.extraChapters
|
||||
it.extraChapters = listOf(ChapterHistory(it.chapter, it.history)) +
|
||||
it.extraChapters
|
||||
}
|
||||
nextChapter
|
||||
}
|
||||
|
@ -386,12 +388,12 @@ class RecentsPresenter(
|
|||
|
||||
private fun setupExtraChapters(
|
||||
existingItem: RecentMangaItem?,
|
||||
chapters: List<Chapter>,
|
||||
sort: Comparator<Chapter>,
|
||||
): Triple<MutableList<Chapter>, Chapter?, Int> {
|
||||
chapters: List<ChapterHistory>,
|
||||
sort: Comparator<ChapterHistory>,
|
||||
): Triple<MutableList<ChapterHistory>, Chapter?, Int> {
|
||||
var extraCount = 0
|
||||
val firstChapter: Chapter
|
||||
var sortedChapters: MutableList<Chapter>
|
||||
var sortedChapters: MutableList<ChapterHistory>
|
||||
val reverseRead = !viewType.isHistory
|
||||
if (existingItem != null) {
|
||||
extraCount += chapters.size
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue