mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 03:07:25 +01:00
Bookmark via reader (closes #1413)
This commit is contained in:
parent
bf1fb8b7bd
commit
ed277357cf
@ -208,6 +208,11 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
*/
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.reader, menu)
|
||||
|
||||
val isChapterBookmarked = presenter?.getCurrentChapter()?.chapter?.bookmark ?: false
|
||||
menu.findItem(R.id.action_bookmark).isVisible = !isChapterBookmarked
|
||||
menu.findItem(R.id.action_remove_bookmark).isVisible = isChapterBookmarked
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@ -217,6 +222,14 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
*/
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_bookmark -> {
|
||||
presenter.bookmarkCurrentChapter(true)
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
R.id.action_remove_bookmark -> {
|
||||
presenter.bookmarkCurrentChapter(false)
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
R.id.action_settings -> ReaderSettingsSheet(this).show()
|
||||
R.id.action_custom_filter -> ReaderColorFilterSheet(this).show()
|
||||
}
|
||||
@ -402,6 +415,9 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
please_wait.gone()
|
||||
viewer?.setChapters(viewerChapters)
|
||||
toolbar.subtitle = viewerChapters.currChapter.chapter.name
|
||||
|
||||
// Invalidate menu to show proper chapter bookmark state
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -407,6 +407,19 @@ class ReaderPresenter(
|
||||
return viewerChaptersRelay.value?.currChapter
|
||||
}
|
||||
|
||||
/**
|
||||
* Bookmarks the currently active chapter.
|
||||
*/
|
||||
fun bookmarkCurrentChapter(bookmarked: Boolean) {
|
||||
if (getCurrentChapter()?.chapter == null) {
|
||||
return
|
||||
}
|
||||
|
||||
val chapter = getCurrentChapter()?.chapter!!
|
||||
chapter.bookmark = bookmarked
|
||||
db.updateChapterProgress(chapter).executeAsBlocking()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the viewer position used by this manga or the default one.
|
||||
*/
|
||||
|
@ -2,6 +2,20 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_bookmark"
|
||||
android:icon="@drawable/ic_bookmark_border_24dp"
|
||||
android:title="@string/action_bookmark"
|
||||
app:iconTint="?attr/colorOnPrimary"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_remove_bookmark"
|
||||
android:icon="@drawable/ic_bookmark_24dp"
|
||||
android:title="@string/action_remove_bookmark"
|
||||
app:iconTint="?attr/colorOnPrimary"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_custom_filter"
|
||||
android:icon="@drawable/ic_brightness_4_24dp"
|
||||
|
Loading…
Reference in New Issue
Block a user