mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 20:31:02 -05:00
Bookmark via reader (closes #1413)
This commit is contained in:
parent
bf1fb8b7bd
commit
ed277357cf
3 changed files with 43 additions and 0 deletions
|
@ -208,6 +208,11 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||||
*/
|
*/
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.reader, menu)
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,6 +222,14 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||||
*/
|
*/
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
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_settings -> ReaderSettingsSheet(this).show()
|
||||||
R.id.action_custom_filter -> ReaderColorFilterSheet(this).show()
|
R.id.action_custom_filter -> ReaderColorFilterSheet(this).show()
|
||||||
}
|
}
|
||||||
|
@ -402,6 +415,9 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||||
please_wait.gone()
|
please_wait.gone()
|
||||||
viewer?.setChapters(viewerChapters)
|
viewer?.setChapters(viewerChapters)
|
||||||
toolbar.subtitle = viewerChapters.currChapter.chapter.name
|
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
|
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.
|
* 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"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
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
|
<item
|
||||||
android:id="@+id/action_custom_filter"
|
android:id="@+id/action_custom_filter"
|
||||||
android:icon="@drawable/ic_brightness_4_24dp"
|
android:icon="@drawable/ic_brightness_4_24dp"
|
||||||
|
|
Loading…
Reference in a new issue