Commit 42155437 authored by Christophe Henry's avatar Christophe Henry

Solves #26: UTF-8 problem on article detail on android 5.0

parent 8579f4f8
......@@ -18,6 +18,7 @@
* Fix crash hapening when object is returned from `unread-counts` endpoint without `newestItemTimestampUsec` property ([8cfcd932](https://git.feneas.org/christophehenry/freshrss-android/commit/8cfcd932619b601371b6f0d0a4bcb7d4b92ce3dd))
* Fix spinner infinitely loading when comming back from a feed with a single unread article ([3088922f](https://git.feneas.org/christophehenry/freshrss-android/commit/3088922f9405ee173d6a6cb81b8868a35759aedd))
* Fix articles in subscriptions not being sorted by publication date ([3088922f](https://git.feneas.org/christophehenry/freshrss-android/commit/3088922f9405ee173d6a6cb81b8868a35759aedd))
* Fix [#26](https://git.feneas.org/christophehenry/freshrss-android/issues/26): UTF-8 problem on article detail on android 5.0 ([!7](https://git.feneas.org/christophehenry/freshrss-android/merge_requests/7))
## Refactoring
......
......@@ -8,7 +8,6 @@ import androidx.core.app.NotificationManagerCompat
import androidx.core.os.postDelayed
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
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
......
......@@ -3,6 +3,7 @@ package fr.chenry.android.freshrss.components.subscriptionarticles
import android.content.Intent
import android.os.Bundle
import android.view.*
import android.webkit.WebView
import android.widget.Toast
import android.widget.Toast.LENGTH_SHORT
import androidx.appcompat.app.AppCompatActivity
......@@ -18,7 +19,6 @@ import fr.chenry.android.freshrss.store.database.models.ReadStatus.UNREAD
import fr.chenry.android.freshrss.store.viewmodels.SubscriptionArticleVM
import fr.chenry.android.freshrss.store.viewmodels.SubscriptionArticleVMF
import fr.chenry.android.freshrss.utils.e
import kotlinx.android.synthetic.main.fragment_subscription_article_detail.*
import nl.komponents.kovenant.ui.alwaysUi
import nl.komponents.kovenant.ui.failUi
......@@ -45,7 +45,30 @@ class SubscriptionArticlesDetailFragment: Fragment() {
.let {activity -> activity as AppCompatActivity}.supportActionBar
?.apply {subtitle = article.title}
return inflater.inflate(R.layout.fragment_subscription_article_detail, container, false)
val view = inflater.inflate(R.layout.fragment_subscription_article_detail, container, false)
view.findViewById<WebView>(R.id.fragment_subscription_article_detail_web_view).let {wv ->
"""
|<!DOCTYPE html>
|<html>
| <head>
| <title>${article.title}</title>
| <meta charset="UTF-8" />
| </head>
| <body>
| <h1 id="article-title">${article.title}</h1>
| ${if(article.author.isEmpty()) "<h2 id='article-authors'>${article.author}</h2>" else ""}
| <div id="main-content">${article.content}</div>
| </body>
|</html>
""".trimMargin("|").let {
wv.settings.javaScriptEnabled = false
wv.settings.defaultTextEncodingName = "UTF-8"
wv.loadData(it, "text/html; charset=utf-8", "UTF-8")
}
}
return view
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
......@@ -58,15 +81,6 @@ class SubscriptionArticlesDetailFragment: Fragment() {
super.onCreateOptionsMenu(menu, inflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
"<h1>${article.title}</h1>${article.content}".let {
content_detail.settings.javaScriptEnabled = false
content_detail.loadData(it, "text/html", "UTF-8")
}
}
override fun onResume() {
super.onResume()
if(article.readStatus == UNREAD) setReadStatus(ReadStatus.READ)
......
......@@ -26,7 +26,7 @@ class ShareIntent(attributes: Map<String, String>): Intent(Intent.ACTION_SEND) {
}
fun format(attributes: Map<String, String>) = template.apply {
attributes.forEach {t, u -> set(t, u)}
attributes.entries.forEach {(t, u) -> set(t, u)}
}.toString()
}
}
package fr.chenry.android.freshrss.utils
import android.annotation.TargetApi
import android.content.Context
import android.content.res.Configuration
import android.os.Build
import android.util.AttributeSet
import android.webkit.WebView
// WebView crashing on Lollipop devices
// See https://stackoverflow.com/a/49024931
class LollipopFixedWebView: WebView {
constructor(context: Context): super(getFixedContext(context))
constructor(context: Context, attrs: AttributeSet): super(getFixedContext(context), attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int):
super(getFixedContext(context), attrs, defStyleAttr)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int):
super(getFixedContext(context), attrs, defStyleAttr, defStyleRes)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, privateBrowsing: Boolean):
super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing)
companion object {
fun getFixedContext(context: Context): Context = context.createConfigurationContext(Configuration())
}
}
\ No newline at end of file
......@@ -6,10 +6,8 @@
tools:context=".components.subscriptionarticles.SubscriptionArticlesDetailFragment"
android:orientation="vertical">
<WebView
android:id="@+id/content_detail"
<fr.chenry.android.freshrss.utils.LollipopFixedWebView
android:id="@+id/fragment_subscription_article_detail_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
android:layout_height="match_parent" />
</LinearLayout>
\ No newline at end of file
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