Add share menu item in reader

Closes #9510

(cherry picked from commit 841f80f935225bdb7ee7e400d2b2aa8176c5e4c5)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
#	app/src/main/res/menu/reader.xml
This commit is contained in:
arkon
2023-06-09 22:52:49 -04:00
committed by Jobobby04
parent 40353c6dc9
commit 805a88df25
4 changed files with 59 additions and 51 deletions
@@ -377,16 +377,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
}
@@ -398,7 +398,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)
@@ -408,6 +408,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)
}*/
@@ -701,7 +707,7 @@ class ReaderActivity : BaseActivity() {
setTooltip(R.string.action_open_in_web_view)
setOnClickListener {
openChapterInWebview()
openChapterInWebView()
}
}
@@ -713,6 +719,17 @@ class ReaderActivity : BaseActivity() {
}
}
with(binding.actionShare) {
setTooltip(R.string.action_share)
setOnClickListener {
assistUrl?.let {
val intent = it.toUri().toShareIntent(this@ReaderActivity, type = "text/plain")
startActivity(Intent.createChooser(intent, getString(R.string.action_share)))
}
}
}
with(binding.doublePage) {
setTooltip(R.string.page_layout)
@@ -915,6 +932,8 @@ class ReaderActivity : BaseActivity() {
}
actionWebView.isVisible =
ReaderBottomButton.WebView.isIn(enabledButtons) && viewModel.getSource() is HttpSource
actionShare.isVisible =
ReaderBottomButton.Share.isIn(enabledButtons) && viewModel.getSource() is HttpSource
actionChapterList.isVisible =
ReaderBottomButton.ViewChapters.isIn(enabledButtons)
shiftPageButton.isVisible = (viewer as? PagerViewer)?.config?.doublePages ?: false
@@ -1160,14 +1179,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)
}
}
@@ -6,6 +6,7 @@ import eu.kanade.tachiyomi.R
enum class ReaderBottomButton(val value: String, @StringRes val stringRes: Int) {
ViewChapters("vc", R.string.action_view_chapters),
WebView("wb", R.string.action_open_in_web_view),
Share("sh", R.string.action_share),
ReadingMode("rm", R.string.viewer),
Rotation("rot", R.string.rotation_type),
CropBordersPager("cbp", R.string.pref_crop_borders_pager),