Fixes #157.
This commit is contained in:
parent
a11007113a
commit
e177c22032
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
- Added an option to use a webview in the article viewer (see #149)
|
- Added an option to use a webview in the article viewer (see #149)
|
||||||
|
|
||||||
- Fixes (#151 #152 #155)
|
- Fixes (#151 #152 #155 #157)
|
||||||
|
|
||||||
**1.5.5.x (didn't last long) AND 1.5.6.x**
|
**1.5.5.x (didn't last long) AND 1.5.6.x**
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ import android.support.v4.content.ContextCompat
|
|||||||
import android.support.v4.widget.NestedScrollView
|
import android.support.v4.widget.NestedScrollView
|
||||||
import android.text.Html
|
import android.text.Html
|
||||||
import android.text.method.LinkMovementMethod
|
import android.text.method.LinkMovementMethod
|
||||||
import android.util.TypedValue
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -38,6 +37,8 @@ import org.sufficientlysecure.htmltextview.HtmlHttpImageGetter
|
|||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
|
import java.net.MalformedURLException
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
class ArticleFragment : Fragment() {
|
class ArticleFragment : Fragment() {
|
||||||
private lateinit var pageNumber: Number
|
private lateinit var pageNumber: Number
|
||||||
@ -124,7 +125,7 @@ class ArticleFragment : Fragment() {
|
|||||||
if (!useWebview) {
|
if (!useWebview) {
|
||||||
htmlToTextview(contentText, customTabsIntent, prefs)
|
htmlToTextview(contentText, customTabsIntent, prefs)
|
||||||
} else {
|
} else {
|
||||||
htmlToWebview(contentText)
|
htmlToWebview(contentText, prefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!contentImage.isEmptyOrNullOrNullString()) {
|
if (!contentImage.isEmptyOrNullOrNullString()) {
|
||||||
@ -186,7 +187,7 @@ class ArticleFragment : Fragment() {
|
|||||||
prefs
|
prefs
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
htmlToWebview(response.body()!!.content)
|
htmlToWebview(response.body()!!.content, prefs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,15 +239,9 @@ class ArticleFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun htmlToWebview(c: String) {
|
private fun htmlToWebview(c: String, prefs: SharedPreferences) {
|
||||||
|
|
||||||
val defaultColor = TypedValue()
|
val accentColor = ContextCompat.getColor(activity!!.baseContext, R.color.accent)
|
||||||
activity!!.baseContext.theme.resolveAttribute(
|
|
||||||
android.R.attr.colorAccent,
|
|
||||||
defaultColor,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
val accentColor = fab.backgroundTintList?.defaultColor ?: defaultColor.data
|
|
||||||
val stringColor = String.format("#%06X", 0xFFFFFF and accentColor)
|
val stringColor = String.format("#%06X", 0xFFFFFF and accentColor)
|
||||||
|
|
||||||
rootView.webcontent.visibility = View.VISIBLE
|
rootView.webcontent.visibility = View.VISIBLE
|
||||||
@ -270,10 +265,23 @@ class ArticleFragment : Fragment() {
|
|||||||
rootView.webcontent.settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
|
rootView.webcontent.settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
|
||||||
}
|
}
|
||||||
|
|
||||||
rootView.webcontent.loadData(
|
var baseUrl: String? = null
|
||||||
|
|
||||||
|
try {
|
||||||
|
val itemUrl = URL(url)
|
||||||
|
baseUrl = itemUrl.protocol + "://" + itemUrl.host
|
||||||
|
} catch (e: MalformedURLException) {
|
||||||
|
Crashlytics.setUserIdentifier(prefs.getString("unique_id", ""))
|
||||||
|
Crashlytics.log(100, "BASE_URL_MALFORMED", e.message)
|
||||||
|
Crashlytics.logException(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
rootView.webcontent.loadDataWithBaseURL(
|
||||||
|
baseUrl,
|
||||||
"<style>img{display: inline-block;height: auto; width: 100%; max-width: 100%;} a{color: $stringColor;} *:not(a){color: $stringTextColor;}</style>$c",
|
"<style>img{display: inline-block;height: auto; width: 100%; max-width: 100%;} a{color: $stringColor;} *:not(a){color: $stringTextColor;}</style>$c",
|
||||||
"text/html; charset=utf-8",
|
"text/html; charset=utf-8",
|
||||||
"utf-8"
|
"utf-8",
|
||||||
|
null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user