Commit 966c53f5 authored by Christophe Henry's avatar Christophe Henry

Merge branch 'handle-url-clicks' into 'develop'

Solves #55: Links click open page in the webview

See merge request !18
parents 83ac0c15 a0c03c01
......@@ -8,6 +8,7 @@
* [#50](https://git.feneas.org/christophehenry/freshrss-android/issues/50): Categories are not alphabetically sorted
* [#51](https://git.feneas.org/christophehenry/freshrss-android/issues/51): Unread subscription time groups are not time-sorted
* [#55]()https://git.feneas.org/christophehenry/freshrss-android/issues/55: Links click open page in the webview ([!18](https://git.feneas.org/christophehenry/freshrss-android/merge_requests/18))
# 1.1.0
......
......@@ -12,7 +12,8 @@ import androidx.core.view.MenuItemCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.*
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.components.subscriptionarticles.shareintent.ShareIntent
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.FRSSWebViewClient
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.ShareIntent
import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.store.database.models.*
import fr.chenry.android.freshrss.store.database.models.ReadStatus.UNREAD
......@@ -66,6 +67,7 @@ class SubscriptionArticlesDetailFragment: Fragment() {
wv.settings.javaScriptEnabled = false
wv.settings.defaultTextEncodingName = "UTF-8"
wv.loadDataWithBaseURL("file:///android_asset/", it, "text/html; charset=utf-8", "UTF-8", null)
wv.webViewClient = FRSSWebViewClient(this, article.url)
}
}
......
package fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils
import android.content.Intent
class MailIntent(address: String, subject: String = "", body: String = "", cc: String = ""):
Intent(ACTION_SEND) {
init {
putExtra(EXTRA_EMAIL, arrayOf(address))
putExtra(EXTRA_TEXT, body)
putExtra(EXTRA_SUBJECT, subject)
putExtra(EXTRA_CC, cc)
type = "message/rfc822"
}
}
\ No newline at end of file
package fr.chenry.android.freshrss.components.subscriptionarticles.shareintent
package fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils
import android.content.Intent
import com.x5.template.Theme
import fr.chenry.android.freshrss.components.subscriptionarticles.shareintent.chunkfilters.SentenceCapFilter
import fr.chenry.android.freshrss.components.subscriptionarticles.shareintent.chunkfilters.StripFragmentFilter
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.chunkfilters.SentenceCapFilter
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.chunkfilters.StripFragmentFilter
class ShareIntent(attributes: Map<String, String>): Intent(Intent.ACTION_SEND) {
......
package fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils
import android.content.Intent
import android.net.MailTo
import android.net.Uri
import android.webkit.*
import androidx.fragment.app.Fragment
class FRSSWebViewClient(private val fragment: Fragment, private val sourceUrl: Uri?): WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
if(request?.url?.scheme?.startsWith("mailto") == true) {
val mt = MailTo.parse(request.url.toString())
fragment.startActivity(MailIntent(mt.to, mt.subject, mt.body, mt.cc))
} else if(request?.url?.scheme?.startsWith("http") == true) {
if(request.url.isRelative && sourceUrl == null) return true
val url = if(request.url.isRelative)
sourceUrl!!.buildUpon().path(request.url.path ?: "").build() else request.url
fragment.startActivity(Intent(Intent.ACTION_VIEW).apply {data = url})
}
return true
}
}
\ No newline at end of file
package fr.chenry.android.freshrss.components.subscriptionarticles.shareintent.chunkfilters
package fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.chunkfilters
import com.x5.template.Chunk
import com.x5.template.filters.FilterArgs
......
package fr.chenry.android.freshrss.components.subscriptionarticles
import fr.chenry.android.freshrss.components.subscriptionarticles.shareintent.ShareIntent
import fr.chenry.android.freshrss.components.subscriptionarticles.shareintent.chunkfilters.StripFragmentFilter
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.ShareIntent
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.chunkfilters.StripFragmentFilter
import org.junit.Assert.assertEquals
import org.junit.Test
......
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