Share Button in WebView + Open in broswer moved there

This commit is contained in:
arkon 2020-01-16 22:13:34 -05:00 committed by Jay
parent f465785935
commit a8d1999fc2
6 changed files with 50 additions and 49 deletions

View File

@ -41,7 +41,6 @@ import eu.kanade.tachiyomi.util.doOnApplyWindowInsets
import eu.kanade.tachiyomi.util.gone
import eu.kanade.tachiyomi.util.inflate
import eu.kanade.tachiyomi.util.marginTop
import eu.kanade.tachiyomi.util.openInBrowser
import eu.kanade.tachiyomi.util.snack
import eu.kanade.tachiyomi.util.updateLayoutParams
import eu.kanade.tachiyomi.util.updatePaddingRelative
@ -319,7 +318,6 @@ open class BrowseCatalogueController(bundle: Bundle) :
super.onPrepareOptionsMenu(menu)
val isHttpSource = presenter.source is HttpSource
menu.findItem(R.id.action_open_in_browser).isVisible = isHttpSource
menu.findItem(R.id.action_open_in_web_view).isVisible = isHttpSource
}
@ -328,19 +326,12 @@ open class BrowseCatalogueController(bundle: Bundle) :
R.id.action_search -> expandActionViewFromInteraction = true
R.id.action_display_mode -> swapDisplayMode()
R.id.action_set_filter -> navView?.let { activity?.drawer?.openDrawer(GravityCompat.END) }
R.id.action_open_in_browser -> openInBrowser()
R.id.action_open_in_web_view -> openInWebView()
else -> return super.onOptionsItemSelected(item)
}
return true
}
private fun openInBrowser() {
val source = presenter.source as? HttpSource ?: return
activity?.openInBrowser(source.baseUrl)
}
private fun openInWebView() {
val source = presenter.source as? HttpSource ?: return
val activity = activity ?: return

View File

@ -64,7 +64,6 @@ import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.doOnApplyWindowInsets
import eu.kanade.tachiyomi.util.getUriCompat
import eu.kanade.tachiyomi.util.marginBottom
import eu.kanade.tachiyomi.util.openInBrowser
import eu.kanade.tachiyomi.util.snack
import eu.kanade.tachiyomi.util.toast
import eu.kanade.tachiyomi.util.updateLayoutParams
@ -229,13 +228,11 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_edit -> EditMangaDialog(this, presenter.manga).showDialog(router)
R.id.action_open_in_browser -> openInBrowser()
R.id.action_open_in_web_view -> openInWebView()
R.id.action_share -> prepareToShareManga()
R.id.action_add_to_home_screen -> addToHomeScreen()
else -> return super.onOptionsItemSelected(item)
}
return true
return super.onOptionsItemSelected(item)
}
/**
@ -384,16 +381,6 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
presenter.toggleFavorite()
}
/**
* Open the manga in browser.
*/
private fun openInBrowser() {
val context = view?.context ?: return
val source = presenter.source as? HttpSource ?: return
context.openInBrowser(source.mangaDetailsRequest(presenter.manga).url.toString())
}
private fun openInWebView() {
val source = presenter.source as? HttpSource ?: return

View File

@ -26,6 +26,8 @@ import eu.kanade.tachiyomi.util.doOnApplyWindowInsets
import eu.kanade.tachiyomi.util.getResourceColor
import eu.kanade.tachiyomi.util.invisible
import eu.kanade.tachiyomi.util.marginBottom
import eu.kanade.tachiyomi.util.openInBrowser
import eu.kanade.tachiyomi.util.toast
import eu.kanade.tachiyomi.util.updateLayoutParams
import eu.kanade.tachiyomi.util.updatePadding
import eu.kanade.tachiyomi.util.visible
@ -244,8 +246,25 @@ class WebViewActivity : BaseActivity() {
when (item.itemId) {
R.id.action_web_back -> webview.goBack()
R.id.action_web_forward -> webview.goForward()
else -> return super.onOptionsItemSelected(item)
R.id.action_web_share -> shareWebpage()
R.id.action_web_browser -> openInBrowser()
}
return true
return super.onOptionsItemSelected(item)
}
private fun shareWebpage() {
try {
val intent = Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, webview.url)
}
startActivity(Intent.createChooser(intent, getString(R.string.action_share)))
} catch (e: Exception) {
toast(e.message)
}
}
private fun openInBrowser() {
openInBrowser(webview.url)
}
}

View File

@ -1,33 +1,29 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".CatalogueListActivity">
xmlns:tools="http://schemas.android.com/tools"
tools:context=".CatalogueListActivity">
<item
android:id="@+id/action_search"
android:title="@string/action_search"
android:icon="@drawable/ic_search_white_24dp"
app:showAsAction="collapseActionView|ifRoom"
app:actionViewClass="androidx.appcompat.widget.SearchView"/>
android:title="@string/action_search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="collapseActionView|ifRoom" />
<item
android:id="@+id/action_set_filter"
android:title="@string/action_set_filter"
android:icon="@drawable/ic_filter_list_white_24dp"
app:showAsAction="ifRoom"/>
android:title="@string/action_set_filter"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_display_mode"
android:title="@string/action_display_mode"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_open_in_browser"
android:title="@string/action_open_in_browser"
app:showAsAction="never"/>
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_open_in_web_view"
android:title="@string/action_open_in_web_view"
app:showAsAction="never"/>
app:showAsAction="never" />
</menu>

View File

@ -14,16 +14,14 @@
android:title="@string/action_share"
app:showAsAction="ifRoom" />
<item android:id="@+id/action_open_in_browser"
android:title="@string/action_open_in_browser"
app:showAsAction="never"/>
<item android:id="@+id/action_open_in_web_view"
<item
android:id="@+id/action_open_in_web_view"
android:title="@string/action_open_in_web_view"
app:showAsAction="never"/>
app:showAsAction="never" />
<item android:id="@+id/action_add_to_home_screen"
<item
android:id="@+id/action_add_to_home_screen"
android:title="@string/action_add_to_home_screen"
app:showAsAction="never"/>
app:showAsAction="never" />
</menu>

View File

@ -11,6 +11,16 @@
android:id="@+id/action_web_forward"
android:icon="@drawable/ic_arrow_forward_white_24dp"
android:title="@string/action_webview_forward"
app:showAsAction="ifRoom"
/>
</menu>
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_web_share"
android:title="@string/action_share"
app:showAsAction="never" />
<item
android:id="@+id/action_web_browser"
android:title="@string/action_open_in_browser"
app:showAsAction="never" />
</menu>