Commit 3a4f0937 authored by Christophe Henry's avatar Christophe Henry

Solves #20: Add linebreak between article title and url

parent affe46b5
......@@ -10,6 +10,7 @@ import com.facebook.stetho.Stetho
import fr.chenry.android.freshrss.RefresherService.RefresherBinder
import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.store.database.FreshRSSDabatabase
import fr.chenry.android.freshrss.utils.Try
import fr.chenry.android.freshrss.utils.whenNotNull
import nl.komponents.kovenant.android.startKovenant
import nl.komponents.kovenant.android.stopKovenant
......@@ -32,13 +33,11 @@ class FreshRSSApplication: Application() {
bindService(Intent(this, RefresherService::class.java), serviceConnection, Context.BIND_AUTO_CREATE)
Store.debugMode = try {
Store.debugMode = Try {
val properties = Properties()
properties.load(baseContext.assets.open("config.properties"))
properties.getProperty("debug", "false")!!.toBoolean()
} catch(_: Throwable) {
false
}
}.getOrDefault(false)
if(Store.debugMode) Stetho.initializeWithDefaults(this)
}
......
......@@ -82,20 +82,9 @@ class SubscriptionArticlesDetailFragment: Fragment() {
}
private fun setupShareAction(menu: Menu) {
val intent = Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
val regex = "\\s*[^\\p{L}]*\\s*${Pattern.quote(article.author)}\\s*\\W*\\s*".toRegex(IGNORE_CASE)
val computedTitle = regex.replace(article.title, "")
val computedAuthor = if(article.author.isBlank()) "" else " — ${article.author}"
val comutedUrl = if(article.href.isBlank()) "" else "\n${article.href}"
val intantValue = "${computedTitle.capitalize()}${computedAuthor.capitalizeFull()}$comutedUrl"
putExtra(Intent.EXTRA_TEXT, intantValue)
}
menu.findItem(R.id.action_share)
.let {MenuItemCompat.getActionProvider(it) as ShareActionProvider}
.setShareIntent(intent)
.setShareIntent(ShareIntent())
}
private fun setupOpenInBrowser(menu: Menu) {
......@@ -164,4 +153,21 @@ class SubscriptionArticlesDetailFragment: Fragment() {
return true
}
inner class ShareIntent: Intent(Intent.ACTION_SEND) {
private val stripAuthorRegex = "\\s*[^\\p{L}]*\\s*${Pattern.quote(article.author)}\\s*\\W*\\s*".toRegex(IGNORE_CASE)
private val articleTitle get() = stripAuthorRegex.replace(article.title, "").capitalize()
private val articleAuthor get() = if(article.author.isBlank()) "" else "— ${article.author}".capitalizeFull()
private val articleShareString get() = """
$articleTitle $articleAuthor
${article.href}
""".trimIndent().trim()
init {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, articleShareString)
}
}
}
......@@ -4,7 +4,7 @@ class Try<T: Any>(body: () -> T) {
private lateinit var _error: Throwable
private lateinit var _value: T
val isSuccess: Boolean get() = ::_error.isInitialized
val isSuccess: Boolean get() = ::_value.isInitialized
val value: T get() = _value
val error: Throwable get() = _error
......@@ -19,4 +19,5 @@ class Try<T: Any>(body: () -> T) {
fun <U: Any>map(body: (Try<T>) -> U): Try<U> = Try{body(this)}
fun <U: Any>whenSuccess(body: (T) -> U): Try<T> = if(isSuccess) body(value).let{this} else this
fun <U: Any>whenError(body: (Throwable) -> U): Try<T> = if(!isSuccess) body(error).let{this} else this
fun getOrDefault(default: T) = if(isSuccess) value else default
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-rc02"
......
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