From 596a24fce813694bc873dc54f361aeb02b72fa6b Mon Sep 17 00:00:00 2001 From: Bram van de Kerkhof Date: Thu, 22 Sep 2016 21:36:40 +0200 Subject: [PATCH] Added option to share your favorite manga (#477) --- .../data/source/online/OnlineSource.kt | 2 +- .../ui/manga/info/MangaInfoFragment.kt | 20 +++++++++++++++++++ .../ui/manga/info/MangaInfoPresenter.kt | 1 - .../main/res/drawable/ic_share_white_24dp.xml | 9 +++++++++ app/src/main/res/menu/manga_info.xml | 6 ++++++ app/src/main/res/values/strings.xml | 3 +++ 6 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/ic_share_white_24dp.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt index 8daa87703f..4df59bc370 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt @@ -192,7 +192,7 @@ abstract class OnlineSource(context: Context) : Source { * * @param manga the manga to be updated. */ - open protected fun mangaDetailsRequest(manga: Manga): Request { + open fun mangaDetailsRequest(manga: Manga): Request { return GET(baseUrl + manga.url, headers) } 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 9bc40b823b..6ab67a9233 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,5 +1,6 @@ package eu.kanade.tachiyomi.ui.manga.info +import android.content.Intent import android.net.Uri import android.os.Bundle import android.support.customtabs.CustomTabsIntent @@ -59,6 +60,7 @@ class MangaInfoFragment : BaseRxFragment() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.action_open_in_browser -> openInBrowser() + R.id.action_share -> shareManga() else -> return super.onOptionsItemSelected(item) } return true @@ -158,6 +160,24 @@ class MangaInfoFragment : BaseRxFragment() { } } + /** + * Called to run Intent with [Intent.ACTION_SEND], which show share dialog. + */ + private fun shareManga() { + val source = presenter.source as? OnlineSource ?: return + try { + val url = source.mangaDetailsRequest(presenter.manga).url().toString() + val sharingIntent = Intent(Intent.ACTION_SEND).apply { + type = "text/plain" + putExtra(android.content.Intent.EXTRA_SUBJECT, presenter.manga.title) + putExtra(android.content.Intent.EXTRA_TEXT, resources.getString(R.string.share_text, presenter.manga.title, url)) + } + startActivity(Intent.createChooser(sharingIntent, resources.getText(R.string.share_subject))) + } catch (e: Exception) { + context.toast(e.message) + } + } + /** * Update FAB with correct drawable. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt index 3c54c6ff8b..35941b3d01 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt @@ -128,5 +128,4 @@ class MangaInfoPresenter : BasePresenter() { private fun refreshManga() { start(GET_MANGA) } - } diff --git a/app/src/main/res/drawable/ic_share_white_24dp.xml b/app/src/main/res/drawable/ic_share_white_24dp.xml new file mode 100644 index 0000000000..c5027c6598 --- /dev/null +++ b/app/src/main/res/drawable/ic_share_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/menu/manga_info.xml b/app/src/main/res/menu/manga_info.xml index 8cb84e3820..e9aa77c9f9 100644 --- a/app/src/main/res/menu/manga_info.xml +++ b/app/src/main/res/menu/manga_info.xml @@ -2,6 +2,12 @@ + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1447866d97..d77e2da59a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -56,6 +56,7 @@ Cancel Sort Install + Share Deleting… @@ -222,6 +223,8 @@ Status Source Genres + Share… + Check out %1$s! at %2$s Chapters