Even more updates to recents

*Fix history chapters showing the same unread chapter twice
*When searching, automatically expand all items, with no option to collapse (why would you?)
*Hide subtitle in sub chapters in history if the chapter's read date is over a day old (no point showing the same text that would be there already in the main section)
set a min height for the sub chapter items
* Make sub chapter text slightly bigger if there is no subtitle
This commit is contained in:
Jays2Kings 2023-03-03 19:50:24 -05:00
parent 597a37f1c2
commit 0485a7f692
5 changed files with 45 additions and 26 deletions

View file

@ -28,6 +28,7 @@ class RecentMangaAdapter(val delegate: RecentsInterface) :
var uniformCovers = preferences.uniformGrid().get() var uniformCovers = preferences.uniformGrid().get()
var showOutline = preferences.outlineOnCovers().get() var showOutline = preferences.outlineOnCovers().get()
var sortByFetched = preferences.sortFetchedTime().get() var sortByFetched = preferences.sortFetchedTime().get()
var isSearching = false
private var collapseGroupedUpdates = preferences.collapseGroupedUpdates().get() private var collapseGroupedUpdates = preferences.collapseGroupedUpdates().get()
private var collapseGroupedHistory = preferences.collapseGroupedHistory().get() private var collapseGroupedHistory = preferences.collapseGroupedHistory().get()
val collapseGrouped: Boolean val collapseGrouped: Boolean

View file

@ -30,6 +30,9 @@ import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.timeSpanFromNow import eu.kanade.tachiyomi.util.system.timeSpanFromNow
import eu.kanade.tachiyomi.util.view.setAnimVectorCompat import eu.kanade.tachiyomi.util.view.setAnimVectorCompat
import eu.kanade.tachiyomi.util.view.setCards import eu.kanade.tachiyomi.util.view.setCards
import java.util.Calendar
import java.util.Date
import java.util.concurrent.TimeUnit
class RecentMangaHolder( class RecentMangaHolder(
view: View, view: View,
@ -214,8 +217,8 @@ class RecentMangaHolder(
) )
} }
binding.showMoreChapters.isVisible = item.mch.extraChapters.isNotEmpty() binding.showMoreChapters.isVisible = item.mch.extraChapters.isNotEmpty() && !adapter.isSearching
binding.moreChaptersLayout.isVisible = binding.showMoreChapters.isVisible && binding.moreChaptersLayout.isVisible = item.mch.extraChapters.isNotEmpty() &&
adapter.delegate.areExtraChaptersExpanded(flexibleAdapterPosition) adapter.delegate.areExtraChaptersExpanded(flexibleAdapterPosition)
val moreVisible = binding.moreChaptersLayout.isVisible val moreVisible = binding.moreChaptersLayout.isVisible
binding.showMoreChapters.setImageResource( binding.showMoreChapters.setImageResource(
@ -334,10 +337,19 @@ class RecentMangaHolder(
val showDLs = adapter.showDownloads val showDLs = adapter.showDownloads
title.text = chapter.preferredChapterName(context, item.mch.manga, adapter.preferences) title.text = chapter.preferredChapterName(context, item.mch.manga, adapter.preferences)
title.setTextColor(ChapterUtil.readColor(context, chapter)) title.setTextColor(ChapterUtil.readColor(context, chapter))
subtitle.isVisible = chapter.dateRead != null
subtitle.text = chapter.dateRead?.let { dateRead -> subtitle.text = chapter.dateRead?.let { dateRead ->
val date = Calendar.getInstance().apply {
time = Date()
set(Calendar.HOUR_OF_DAY, 0)
set(Calendar.MINUTE, 0)
set(Calendar.MILLISECOND, 0)
set(Calendar.SECOND, 0)
}.timeInMillis
context.timeSpanFromNow(R.string.read_, dateRead) context.timeSpanFromNow(R.string.read_, dateRead)
.takeIf { date - dateRead < TimeUnit.DAYS.toMillis(1) }
} ?: "" } ?: ""
subtitle.isVisible = subtitle.text.isNotBlank()
title.textSize = (if (subtitle.isVisible) 14f else 14.5f)
root.setOnClickListener { root.setOnClickListener {
adapter.delegate.onSubChapterClicked( adapter.delegate.onSubChapterClicked(
bindingAdapterPosition, bindingAdapterPosition,

View file

@ -126,6 +126,9 @@ class RecentsController(bundle: Bundle? = null) :
set(value) { set(value) {
field = value field = value
presenter.query = value presenter.query = value
if (this::adapter.isInitialized) {
adapter.isSearching = value.isNotBlank()
}
} }
override val mainRecycler: RecyclerView override val mainRecycler: RecyclerView
@ -651,6 +654,7 @@ class RecentsController(bundle: Bundle? = null) :
} }
override fun areExtraChaptersExpanded(position: Int): Boolean { override fun areExtraChaptersExpanded(position: Int): Boolean {
if (query.isNotBlank()) return true
val item = (adapter.getItem(position) as? RecentMangaItem) ?: return false 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.chapter.dateRead ?: item.chapter.date_fetch)
val invertDefault = !adapter.collapseGrouped val invertDefault = !adapter.collapseGrouped
@ -659,6 +663,7 @@ class RecentsController(bundle: Bundle? = null) :
} }
override fun updateExpandedExtraChapters(position: Int, expanded: Boolean) { override fun updateExpandedExtraChapters(position: Int, expanded: Boolean) {
if (query.isNotBlank()) return
val item = (adapter.getItem(position) as? RecentMangaItem) ?: 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.chapter.dateRead ?: item.chapter.date_fetch)
val invertDefault = !adapter.collapseGrouped val invertDefault = !adapter.collapseGrouped

View file

@ -267,25 +267,24 @@ class RecentsPresenter(
} }
} }
val pairs = mangaList.mapNotNull { val pairs = mangaList.mapNotNull {
val chapter = run result@{ val chapter = when {
when {
(viewType == VIEW_TYPE_ONLY_UPDATES && !groupChaptersUpdates) || (viewType == VIEW_TYPE_ONLY_UPDATES && !groupChaptersUpdates) ||
(viewType == VIEW_TYPE_ONLY_HISTORY && !groupChaptersHistory) -> { (viewType == VIEW_TYPE_ONLY_HISTORY && !groupChaptersHistory) -> {
it.chapter it.chapter
} }
(it.chapter.read && viewType != VIEW_TYPE_ONLY_UPDATES) || it.chapter.id == null -> { (it.chapter.read && viewType != VIEW_TYPE_ONLY_UPDATES) || it.chapter.id == null -> {
val unreadChapterIsAlreadyInList by lazy {
val fIndex = mangaList.indexOfFirst { item -> item.manga.id == it.manga.id }
(
recentItems.any { item -> item.mch.manga.id == it.manga.id } ||
fIndex < mangaList.indexOf(it)
)
}
if (viewType == VIEW_TYPE_ONLY_HISTORY && unreadChapterIsAlreadyInList) {
it.chapter
} else {
val nextChapter = getNextChapter(it.manga) val nextChapter = getNextChapter(it.manga)
?: if (showRead && it.chapter.id != null) it.chapter else null ?: if (showRead && it.chapter.id != null) it.chapter else null
if (viewType == VIEW_TYPE_ONLY_HISTORY && nextChapter != null) {
val unreadChapterIsAlreadyInList =
recentItems.any { item -> item.mch.manga.id == it.manga.id } ||
mangaList.indexOfFirst { item ->
item.manga.id == it.manga.id
} > mangaList.indexOf(it)
if (unreadChapterIsAlreadyInList) {
return@result it.chapter
}
}
if (viewType == VIEW_TYPE_ONLY_HISTORY && nextChapter?.id != null && if (viewType == VIEW_TYPE_ONLY_HISTORY && nextChapter?.id != null &&
nextChapter.id != it.chapter.id nextChapter.id != it.chapter.id
) { ) {
@ -294,6 +293,7 @@ class RecentsPresenter(
} }
nextChapter nextChapter
} }
}
it.history.id == null && viewType != VIEW_TYPE_ONLY_UPDATES -> { it.history.id == null && viewType != VIEW_TYPE_ONLY_UPDATES -> {
getFirstUpdatedChapter(it.manga, it.chapter) getFirstUpdatedChapter(it.manga, it.chapter)
?: if ((showRead && it.chapter.id != null)) it.chapter else null ?: if ((showRead && it.chapter.id != null)) it.chapter else null
@ -302,7 +302,6 @@ class RecentsPresenter(
it.chapter it.chapter
} }
} }
}
if (chapter == null) if ((query.isNotEmpty() || viewType > VIEW_TYPE_UNGROUP_ALL) && if (chapter == null) if ((query.isNotEmpty() || viewType > VIEW_TYPE_UNGROUP_ALL) &&
it.chapter.id != null it.chapter.id != null
) { ) {

View file

@ -26,6 +26,8 @@
android:paddingBottom="12dp" android:paddingBottom="12dp"
android:paddingStart="84dp" android:paddingStart="84dp"
android:paddingEnd="2dp" android:paddingEnd="2dp"
android:gravity="center"
app:layout_constraintHeight_min="48dp"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/download_button" app:layout_constraintEnd_toStartOf="@id/download_button"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"