parent
39a7356ed1
commit
841f80f935
2 changed files with 21 additions and 14 deletions
|
@ -286,16 +286,16 @@ class ReaderActivity : BaseActivity() {
|
||||||
assistUrl?.let { outContent.webUri = it.toUri() }
|
assistUrl?.let { outContent.webUri = it.toUri() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the options menu of the toolbar is being created. It adds our custom menu.
|
|
||||||
*/
|
|
||||||
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 = viewModel.getCurrentChapter()?.chapter?.bookmark ?: false
|
val isChapterBookmarked = viewModel.getCurrentChapter()?.chapter?.bookmark ?: false
|
||||||
menu.findItem(R.id.action_bookmark).isVisible = !isChapterBookmarked
|
menu.findItem(R.id.action_bookmark).isVisible = !isChapterBookmarked
|
||||||
menu.findItem(R.id.action_remove_bookmark).isVisible = isChapterBookmarked
|
menu.findItem(R.id.action_remove_bookmark).isVisible = isChapterBookmarked
|
||||||
menu.findItem(R.id.action_open_in_web_view).isVisible = viewModel.getSource() is HttpSource
|
|
||||||
|
val isHttpSource = viewModel.getSource() is HttpSource
|
||||||
|
menu.findItem(R.id.action_open_in_web_view).isVisible = isHttpSource
|
||||||
|
menu.findItem(R.id.action_share).isVisible = isHttpSource
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -307,7 +307,7 @@ class ReaderActivity : BaseActivity() {
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.action_open_in_web_view -> {
|
R.id.action_open_in_web_view -> {
|
||||||
openChapterInWebview()
|
openChapterInWebView()
|
||||||
}
|
}
|
||||||
R.id.action_bookmark -> {
|
R.id.action_bookmark -> {
|
||||||
viewModel.bookmarkCurrentChapter(true)
|
viewModel.bookmarkCurrentChapter(true)
|
||||||
|
@ -317,6 +317,12 @@ class ReaderActivity : BaseActivity() {
|
||||||
viewModel.bookmarkCurrentChapter(false)
|
viewModel.bookmarkCurrentChapter(false)
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
R.id.action_share -> {
|
||||||
|
assistUrl?.let {
|
||||||
|
val intent = it.toUri().toShareIntent(this, type = "text/plain")
|
||||||
|
startActivity(Intent.createChooser(intent, getString(R.string.action_share)))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
@ -662,14 +668,12 @@ class ReaderActivity : BaseActivity() {
|
||||||
startPostponedEnterTransition()
|
startPostponedEnterTransition()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openChapterInWebview() {
|
private fun openChapterInWebView() {
|
||||||
val manga = viewModel.manga ?: return
|
val manga = viewModel.manga ?: return
|
||||||
val source = viewModel.getSource() ?: return
|
val source = viewModel.getSource() ?: return
|
||||||
lifecycleScope.launchIO {
|
assistUrl?.let {
|
||||||
viewModel.getChapterUrl()?.let { url ->
|
val intent = WebViewActivity.newIntent(this@ReaderActivity, it, source.id, manga.title)
|
||||||
val intent = WebViewActivity.newIntent(this@ReaderActivity, url, source.id, manga.title)
|
startActivity(intent)
|
||||||
withUIContext { startActivity(intent) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,12 @@
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_open_in_web_view"
|
android:id="@+id/action_open_in_web_view"
|
||||||
android:icon="@drawable/ic_webview_24dp"
|
|
||||||
android:title="@string/action_open_in_web_view"
|
android:title="@string/action_open_in_web_view"
|
||||||
app:iconTint="?attr/colorOnSurface"
|
app:showAsAction="never" />
|
||||||
app:showAsAction="ifRoom" />
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_share"
|
||||||
|
android:title="@string/action_share"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
|
Reference in a new issue