Commit b70c935f authored by Christophe Henry's avatar Christophe Henry

Fix share feature

parent 734d24ae
package fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils
import android.content.Intent
import android.content.Intent.*
import com.x5.template.Theme
import fr.chenry.android.freshrss.FreshRSSApplication
import fr.chenry.android.freshrss.R
......@@ -9,7 +10,7 @@ import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.c
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.chunkfilters.StripFragmentFilter
import fr.chenry.android.freshrss.utils.nullIfBlank
object ShareIntent : Intent(Intent.ACTION_SEND) {
object ShareIntent {
private val defaultTemplate = """
|{${'$'}title|strip_fragment(subscription)|sentence_cap} — {${'$'}subscription|capitalize}
......@@ -19,17 +20,17 @@ object ShareIntent : Intent(Intent.ACTION_SEND) {
private val template = Theme().let {
it.registerFilter(SentenceCapFilter())
it.registerFilter(StripFragmentFilter())
it.makeChunk().apply { append(defaultTemplate) }
it.makeChunk().apply {append(defaultTemplate)}
}
fun format(attributes: Map<String, String>) = template.apply {
attributes.entries.forEach { (t, u) -> set(t, u) }
attributes.entries.forEach {(t, u) -> set(t, u)}
}.toString()
fun create(attributes: Map<String, String>) = Intent(Intent.ACTION_SEND).apply {
fun create(attributes: Map<String, String>) = Intent(ACTION_SEND).apply {
type = "text/plain"
ShareIntent.putExtra(EXTRA_TEXT, format(attributes))
putExtra(EXTRA_TEXT, format(attributes))
val feedName = attributes["subscription"]?.nullIfBlank() ?: FreshRSSApplication.getStringR(R.string.this_feed)
ShareIntent.putExtra(EXTRA_SUBJECT, FreshRSSApplication.getStringR(string.share_article, feedName))
putExtra(EXTRA_SUBJECT, FreshRSSApplication.getStringR(string.share_article, feedName))
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment