diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt index 80f284204..97cfd76e1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt @@ -17,11 +17,13 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.model.FilterList +import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog import eu.kanade.tachiyomi.ui.manga.MangaController +import eu.kanade.tachiyomi.ui.manga.info.MangaWebViewController import eu.kanade.tachiyomi.util.* import eu.kanade.tachiyomi.widget.AutofitRecyclerView import kotlinx.android.synthetic.main.catalogue_controller.* @@ -259,15 +261,38 @@ open class BrowseCatalogueController(bundle: Bundle) : } } + override fun onPrepareOptionsMenu(menu: Menu) { + 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 + } + override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.action_display_mode -> swapDisplayMode() R.id.action_set_filter -> navView?.let { activity?.drawer?.openDrawer(Gravity.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 + + router.pushController(MangaWebViewController(source.id, source.baseUrl) + .withFadeTransaction()) + } + /** * Restarts the request with a new query. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index f2a0f412e..b3bb48289 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -42,6 +42,7 @@ import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.util.getResourceColor +import eu.kanade.tachiyomi.util.openInBrowser import eu.kanade.tachiyomi.util.snack import eu.kanade.tachiyomi.util.toast import eu.kanade.tachiyomi.util.truncateCenter @@ -287,15 +288,7 @@ class MangaInfoController : NucleusController(), val context = view?.context ?: return val source = presenter.source as? HttpSource ?: return - try { - val url = Uri.parse(source.mangaDetailsRequest(presenter.manga).url().toString()) - val intent = CustomTabsIntent.Builder() - .setToolbarColor(context.getResourceColor(R.attr.colorPrimary)) - .build() - intent.launchUrl(activity, url) - } catch (e: Exception) { - context.toast(e.message) - } + context.openInBrowser(source.mangaDetailsRequest(presenter.manga).url().toString()) } private fun openInWebView() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt index d89b3ce5a..2c54b236c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ContextExtensions.kt @@ -10,14 +10,17 @@ import android.content.IntentFilter import android.content.pm.PackageManager import android.content.res.Resources import android.net.ConnectivityManager +import android.net.Uri import android.os.PowerManager import android.support.annotation.AttrRes import android.support.annotation.StringRes +import android.support.customtabs.CustomTabsIntent import android.support.v4.app.NotificationCompat import android.support.v4.content.ContextCompat import android.support.v4.content.LocalBroadcastManager import android.widget.Toast import com.nononsenseapps.filepicker.FilePickerActivity +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.widget.CustomLayoutPickerActivity /** @@ -163,3 +166,18 @@ fun Context.isServiceRunning(serviceClass: Class<*>): Boolean { return manager.getRunningServices(Integer.MAX_VALUE) .any { className == it.service.className } } + +/** + * Opens a URL in a custom tab. + */ +fun Context.openInBrowser(url: String) { + try { + val url = Uri.parse(url) + val intent = CustomTabsIntent.Builder() + .setToolbarColor(getResourceColor(R.attr.colorPrimary)) + .build() + intent.launchUrl(this, url) + } catch (e: Exception) { + toast(e.message) + } +} diff --git a/app/src/main/res/menu/catalogue_list.xml b/app/src/main/res/menu/catalogue_list.xml index ff4373df4..1b75d4ae7 100644 --- a/app/src/main/res/menu/catalogue_list.xml +++ b/app/src/main/res/menu/catalogue_list.xml @@ -19,4 +19,15 @@ android:id="@+id/action_display_mode" android:title="@string/action_display_mode" app:showAsAction="ifRoom"/> + + + + +