From 841f80f935225bdb7ee7e400d2b2aa8176c5e4c5 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 9 Jun 2023 22:52:49 -0400 Subject: [PATCH] Add share menu item in reader Closes #9510 --- .../tachiyomi/ui/reader/ReaderActivity.kt | 26 +++++++++++-------- app/src/main/res/menu/reader.xml | 9 ++++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index d6e127adb..1e275b99e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -286,16 +286,16 @@ class ReaderActivity : BaseActivity() { 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 { menuInflater.inflate(R.menu.reader, menu) val isChapterBookmarked = viewModel.getCurrentChapter()?.chapter?.bookmark ?: false menu.findItem(R.id.action_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 } @@ -307,7 +307,7 @@ class ReaderActivity : BaseActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.action_open_in_web_view -> { - openChapterInWebview() + openChapterInWebView() } R.id.action_bookmark -> { viewModel.bookmarkCurrentChapter(true) @@ -317,6 +317,12 @@ class ReaderActivity : BaseActivity() { viewModel.bookmarkCurrentChapter(false) 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) } @@ -662,14 +668,12 @@ class ReaderActivity : BaseActivity() { startPostponedEnterTransition() } - private fun openChapterInWebview() { + private fun openChapterInWebView() { val manga = viewModel.manga ?: return val source = viewModel.getSource() ?: return - lifecycleScope.launchIO { - viewModel.getChapterUrl()?.let { url -> - val intent = WebViewActivity.newIntent(this@ReaderActivity, url, source.id, manga.title) - withUIContext { startActivity(intent) } - } + assistUrl?.let { + val intent = WebViewActivity.newIntent(this@ReaderActivity, it, source.id, manga.title) + startActivity(intent) } } diff --git a/app/src/main/res/menu/reader.xml b/app/src/main/res/menu/reader.xml index 0d29f06d5..cff2ad3f6 100644 --- a/app/src/main/res/menu/reader.xml +++ b/app/src/main/res/menu/reader.xml @@ -18,9 +18,12 @@ + app:showAsAction="never" /> + +