From 62d5deaa6fa5f1558a6cb510ca0fe37879041770 Mon Sep 17 00:00:00 2001 From: len Date: Sun, 8 May 2016 15:20:55 +0200 Subject: [PATCH] Allow to open manga in the browser. Closes #157 (Doesn't work with kissmanga) --- .../ui/manga/info/MangaInfoFragment.kt | 36 +++++++++++++++++-- app/src/main/res/menu/manga_info.xml | 9 +++++ app/src/main/res/menu/menu_manga_detail.xml | 7 ---- 3 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/menu/manga_info.xml delete mode 100644 app/src/main/res/menu/menu_manga_detail.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.kt index 15a27b0a6b..e50f812c23 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoFragment.kt @@ -1,9 +1,9 @@ package eu.kanade.tachiyomi.ui.manga.info +import android.content.Intent +import android.net.Uri import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup +import android.view.* import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.model.GlideUrl @@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.source.base.Source import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment +import eu.kanade.tachiyomi.util.toast import kotlinx.android.synthetic.main.fragment_manga_info.* import nucleus.factory.RequiresPresenter @@ -34,6 +35,11 @@ class MangaInfoFragment : BaseRxFragment() { } } + override fun onCreate(savedState: Bundle?) { + super.onCreate(savedState) + setHasOptionsMenu(true) + } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedState: Bundle?): View? { return inflater.inflate(R.layout.fragment_manga_info, container, false) } @@ -46,6 +52,18 @@ class MangaInfoFragment : BaseRxFragment() { swipe_refresh.setOnRefreshListener { fetchMangaFromSource() } } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + inflater.inflate(R.menu.manga_info, menu) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_open_in_browser -> openInBrowser() + else -> return super.onOptionsItemSelected(item) + } + return true + } + /** * Check if manga is initialized. * If true update view with manga information, @@ -145,6 +163,18 @@ class MangaInfoFragment : BaseRxFragment() { manga_chapters.text = count.toString() } + /** + * Open the manga in browser. + */ + fun openInBrowser() { + try { + val url = presenter.source.baseUrl + presenter.manga.url + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) + } catch (e: Exception) { + context.toast(e.message) + } + } + /** * Update FAB with correct drawable. * diff --git a/app/src/main/res/menu/manga_info.xml b/app/src/main/res/menu/manga_info.xml new file mode 100644 index 0000000000..8cb84e3820 --- /dev/null +++ b/app/src/main/res/menu/manga_info.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_manga_detail.xml b/app/src/main/res/menu/menu_manga_detail.xml deleted file mode 100644 index db39161b19..0000000000 --- a/app/src/main/res/menu/menu_manga_detail.xml +++ /dev/null @@ -1,7 +0,0 @@ - - -