Added option to share your favorite manga (#477)

This commit is contained in:
Bram van de Kerkhof
2016-09-22 21:36:40 +02:00
committed by GitHub
parent 9f20e40257
commit 596a24fce8
6 changed files with 39 additions and 2 deletions

View File

@ -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)
}

View File

@ -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<MangaInfoPresenter>() {
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<MangaInfoPresenter>() {
}
}
/**
* 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.
*

View File

@ -128,5 +128,4 @@ class MangaInfoPresenter : BasePresenter<MangaInfoFragment>() {
private fun refreshManga() {
start(GET_MANGA)
}
}