Skip to content

Commit

Permalink
Show when chapter was read by long press in details
Browse files Browse the repository at this point in the history
  • Loading branch information
Jays2Kings committed Aug 1, 2023
1 parent 121df1f commit 211068d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MaterialMenuSheet(
selectedId: Int? = null,
maxHeight: Int? = null,
showDivider: Boolean = false,
subtitle: String? = null,
onMenuItemClicked: (MaterialMenuSheet, Int) -> Boolean,
) : E2EBottomSheetDialog<BottomMenuSheetBinding>(activity) {

Expand Down Expand Up @@ -76,8 +77,11 @@ class MaterialMenuSheet(
sheetBehavior.skipCollapsed = true

binding.menuSheetRecycler.setOnApplyWindowInsetsListener(RecyclerWindowInsetsListener)
binding.titleLayout.isVisible = title != null
binding.titleLayout.isVisible = title != null || subtitle != null
binding.toolbarTitle.isVisible = title != null
binding.toolbarTitle.text = title
binding.toolbarSubtitle.isVisible = subtitle != null
binding.toolbarSubtitle.text = subtitle

if (selectedId != null) {
val pos = max(items.indexOfFirst { it.id == selectedId }, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.system.materialAlertDialog
import eu.kanade.tachiyomi.util.system.rootWindowInsetsCompat
import eu.kanade.tachiyomi.util.system.setCustomTitleAndMessage
import eu.kanade.tachiyomi.util.system.timeSpanFromNow
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.activityBinding
import eu.kanade.tachiyomi.util.view.findChild
Expand Down Expand Up @@ -869,7 +870,7 @@ class MangaDetailsController :
val adapter = adapter ?: return
val item = (adapter.getItem(position) as? ChapterItem) ?: return
val descending = presenter.sortDescending()
var items = mutableListOf(
val items = mutableListOf(
MaterialMenuSheet.MenuSheetItem(
0,
if (descending) R.drawable.ic_eye_down_24dp else R.drawable.ic_eye_up_24dp,
Expand Down Expand Up @@ -901,16 +902,20 @@ class MangaDetailsController :
),
)
}
val menuSheet = MaterialMenuSheet(activity!!, items, item.name) { _, itemPos ->
when (itemPos) {
0 -> markPreviousAs(item, true)
1 -> markPreviousAs(item, false)
2 -> startReadRange(position, RangeMode.Read)
3 -> startReadRange(position, RangeMode.Unread)
4 -> openChapterInWebView(item)
val lastRead = presenter.allHistory.find { it.chapter_id == item.id }?.let {
activity?.timeSpanFromNow(R.string.read_, it.last_read) + "\n"
}
val menuSheet =
MaterialMenuSheet(activity!!, items, item.name, subtitle = lastRead) { _, itemPos ->
when (itemPos) {
0 -> markPreviousAs(item, true)
1 -> markPreviousAs(item, false)
2 -> startReadRange(position, RangeMode.Read)
3 -> startReadRange(position, RangeMode.Unread)
4 -> openChapterInWebView(item)
}
true
}
true
}
menuSheet.show()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.History
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.download.DownloadManager
Expand Down Expand Up @@ -105,6 +106,9 @@ class MangaDetailsPresenter(
var allChapters: List<ChapterItem> = emptyList()
private set

var allHistory: List<History> = emptyList()
private set

val headerItem by lazy { MangaHeaderItem(manga, view?.fromCatalogue == true) }
var tabletChapterHeaderItem: MangaHeaderItem? = null
var allChapterScanlators: Set<String> = emptySet()
Expand Down Expand Up @@ -166,6 +170,9 @@ class MangaDetailsPresenter(
// Store the last emission
allChapters = chapters
this.chapters = applyChapterFilters(chapters)
presenterScope.launchIO {
allHistory = manga.id?.let { db.getHistoryByMangaId(it).executeOnIO() }.orEmpty()
}
}

/**
Expand Down
23 changes: 22 additions & 1 deletion app/src/main/res/layout/bottom_menu_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,33 @@
android:textAppearance="?textAppearanceHeadlineMedium"
android:textColor="?actionBarTintColor"
android:textSize="17sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/toolbar_subtitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="Title Text" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="end"
android:maxLines="1"
android:textStyle="italic"
android:textAppearance="?textAppearanceCaption"
android:textColor="?actionBarTintColor"
android:visibility="gone"
tools:visibility="visible"
android:alpha="0.75"
android:textSize="13sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar_title"
tools:text="subtitle text" />

<View
android:id="@+id/divider"
android:layout_width="match_parent"
Expand Down

0 comments on commit 211068d

Please sign in to comment.