Fixes #110.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
aminecmi 2022-12-13 20:40:50 +01:00
parent 4fce19bad4
commit 430fc8e8cb

View File

@ -70,7 +70,7 @@ class ArticleFragment : Fragment(), DIAware {
private lateinit var fab: FloatingActionButton private lateinit var fab: FloatingActionButton
private lateinit var textAlignment: String private lateinit var textAlignment: String
private var _binding: FragmentArticleBinding? = null private var _binding: FragmentArticleBinding? = null
private val binding get() = _binding!! private val binding get() = _binding
override val di : DI by closestDI() override val di : DI by closestDI()
private val repository: Repository by instance() private val repository: Repository by instance()
@ -113,13 +113,13 @@ class ArticleFragment : Fragment(), DIAware {
refreshAlignment() refreshAlignment()
fab = binding.fab fab = binding!!.fab
fab.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.colorAccent)) fab.backgroundTintList = ColorStateList.valueOf(resources.getColor(R.color.colorAccent))
fab.rippleColor = resources.getColor(R.color.colorAccentDark) fab.rippleColor = resources.getColor(R.color.colorAccentDark)
val floatingToolbar: FloatingToolbar = binding.floatingToolbar val floatingToolbar: FloatingToolbar = binding!!.floatingToolbar
floatingToolbar.attachFab(fab) floatingToolbar.attachFab(fab)
floatingToolbar.background = ColorDrawable(resources.getColor(R.color.colorAccent)) floatingToolbar.background = ColorDrawable(resources.getColor(R.color.colorAccent))
@ -167,35 +167,35 @@ class ArticleFragment : Fragment(), DIAware {
floatingToolbar.show() floatingToolbar.show()
} }
binding.source.text = contentSource binding!!.source.text = contentSource
if (typeface != null) { if (typeface != null) {
binding.source.typeface = typeface binding!!.source.typeface = typeface
} }
if (contentText.isEmptyOrNullOrNullString()) { if (contentText.isEmptyOrNullOrNullString()) {
getContentFromMercury() getContentFromMercury()
} else { } else {
binding.titleView.text = contentTitle binding!!.titleView.text = contentTitle
if (typeface != null) { if (typeface != null) {
binding.titleView.typeface = typeface binding!!.titleView.typeface = typeface
} }
htmlToWebview() htmlToWebview()
if (!contentImage.isEmptyOrNullOrNullString() && context != null) { if (!contentImage.isEmptyOrNullOrNullString() && context != null) {
binding.imageView.visibility = View.VISIBLE binding!!.imageView.visibility = View.VISIBLE
Glide Glide
.with(requireContext()) .with(requireContext())
.asBitmap() .asBitmap()
.load(contentImage) .load(contentImage)
.apply(RequestOptions.fitCenterTransform()) .apply(RequestOptions.fitCenterTransform())
.into(binding.imageView) .into(binding!!.imageView)
} else { } else {
binding.imageView.visibility = View.GONE binding!!.imageView.visibility = View.GONE
} }
} }
binding.nestedScrollView.setOnScrollChangeListener( binding!!.nestedScrollView.setOnScrollChangeListener(
NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, oldScrollY -> NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
if (scrollY > oldScrollY) { if (scrollY > oldScrollY) {
floatingToolbar.hide() floatingToolbar.hide()
@ -224,7 +224,7 @@ class ArticleFragment : Fragment(), DIAware {
.show() .show()
} }
return binding.root return binding!!.root
} }
override fun onDestroyView() { override fun onDestroyView() {
@ -242,16 +242,16 @@ class ArticleFragment : Fragment(), DIAware {
private fun getContentFromMercury() { private fun getContentFromMercury() {
if (repository.isNetworkAvailable()) { if (repository.isNetworkAvailable()) {
binding.progressBar.visibility = View.VISIBLE binding!!.progressBar.visibility = View.VISIBLE
CoroutineScope(Dispatchers.Main).launch { CoroutineScope(Dispatchers.Main).launch {
try { try {
val response = mercuryApi.query(url) val response = mercuryApi.query(url)
if (response.success && response.data != null && !response.data?.content.isNullOrEmpty()) { if (response.success && response.data != null && !response.data?.content.isNullOrEmpty()) {
binding.titleView.text = response.data!!.title.orEmpty() binding!!.titleView.text = response.data!!.title.orEmpty()
try { try {
if (typeface != null) { if (typeface != null) {
binding.titleView.typeface = typeface binding!!.titleView.typeface = typeface
} }
} catch (e: Exception) { } catch (e: Exception) {
e.sendSilentlyWithAcraWithName("getContentFromMercury > typeface") e.sendSilentlyWithAcraWithName("getContentFromMercury > typeface")
@ -275,7 +275,7 @@ class ArticleFragment : Fragment(), DIAware {
if (!response.data?.lead_image_url.isNullOrEmpty() && context != null) { if (!response.data?.lead_image_url.isNullOrEmpty() && context != null) {
try { try {
binding.imageView.visibility = View.VISIBLE binding!!.imageView.visibility = View.VISIBLE
try { try {
Glide Glide
.with(requireContext()) .with(requireContext())
@ -284,7 +284,7 @@ class ArticleFragment : Fragment(), DIAware {
response.data!!.lead_image_url.orEmpty() response.data!!.lead_image_url.orEmpty()
) )
.apply(RequestOptions.fitCenterTransform()) .apply(RequestOptions.fitCenterTransform())
.into(binding.imageView) .into(binding!!.imageView)
} catch (e: Exception) { } catch (e: Exception) {
e.sendSilentlyWithAcraWithName("getContentFromMercury > glide lead image") e.sendSilentlyWithAcraWithName("getContentFromMercury > glide lead image")
} }
@ -292,12 +292,12 @@ class ArticleFragment : Fragment(), DIAware {
e.sendSilentlyWithAcraWithName("getContentFromMercury > outside glide lead image") e.sendSilentlyWithAcraWithName("getContentFromMercury > outside glide lead image")
} }
} else { } else {
binding.imageView.visibility = View.GONE binding!!.imageView.visibility = View.GONE
} }
try { try {
binding.nestedScrollView.scrollTo(0, 0) binding!!.nestedScrollView.scrollTo(0, 0)
binding.progressBar.visibility = View.GONE binding!!.progressBar.visibility = View.GONE
} catch (e: Exception) { } catch (e: Exception) {
e.sendSilentlyWithAcraWithName("getContentFromMercury > scrollview") e.sendSilentlyWithAcraWithName("getContentFromMercury > scrollview")
} }
@ -320,8 +320,8 @@ class ArticleFragment : Fragment(), DIAware {
val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs) val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs)
binding.webcontent.settings.standardFontFamily = a.getString(0) binding!!.webcontent.settings.standardFontFamily = a.getString(0)
binding.webcontent.visibility = View.VISIBLE binding!!.webcontent.visibility = View.VISIBLE
val colorOnSurface = TypedValue() val colorOnSurface = TypedValue()
requireContext().theme.resolveAttribute(R.attr.colorOnSurface, colorOnSurface, true) requireContext().theme.resolveAttribute(R.attr.colorOnSurface, colorOnSurface, true)
@ -329,14 +329,14 @@ class ArticleFragment : Fragment(), DIAware {
val colorSurface = TypedValue() val colorSurface = TypedValue()
requireContext().theme.resolveAttribute(R.attr.colorSurface, colorSurface, true) requireContext().theme.resolveAttribute(R.attr.colorSurface, colorSurface, true)
binding.webcontent.settings.useWideViewPort = true binding!!.webcontent.settings.useWideViewPort = true
binding.webcontent.settings.loadWithOverviewMode = true binding!!.webcontent.settings.loadWithOverviewMode = true
binding.webcontent.settings.javaScriptEnabled = false binding!!.webcontent.settings.javaScriptEnabled = false
binding.webcontent.webViewClient = object : WebViewClient() { binding!!.webcontent.webViewClient = object : WebViewClient() {
@Deprecated("Deprecated in Java") @Deprecated("Deprecated in Java")
override fun shouldOverrideUrlLoading(view: WebView?, url : String): Boolean { override fun shouldOverrideUrlLoading(view: WebView?, url : String): Boolean {
if (binding.webcontent.hitTestResult.type != WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { if (binding!!.webcontent.hitTestResult.type != WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
requireContext().startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) requireContext().startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
} }
return true return true
@ -380,9 +380,9 @@ class ArticleFragment : Fragment(), DIAware {
} }
}) })
binding.webcontent.setOnTouchListener { _, event -> gestureDetector.onTouchEvent(event)} binding!!.webcontent.setOnTouchListener { _, event -> gestureDetector.onTouchEvent(event)}
binding.webcontent.settings.layoutAlgorithm = binding!!.webcontent.settings.layoutAlgorithm =
WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING
var baseUrl: String? = null var baseUrl: String? = null
@ -413,7 +413,7 @@ class ArticleFragment : Fragment(), DIAware {
"" ""
} }
binding.webcontent.loadDataWithBaseURL( binding!!.webcontent.loadDataWithBaseURL(
baseUrl, baseUrl,
"""<html> """<html>
|<head> |<head>
@ -466,17 +466,17 @@ class ArticleFragment : Fragment(), DIAware {
} }
fun scrollDown() { fun scrollDown() {
val height = binding.nestedScrollView.measuredHeight val height = binding!!.nestedScrollView.measuredHeight
binding.nestedScrollView.smoothScrollBy(0, height/2) binding!!.nestedScrollView.smoothScrollBy(0, height/2)
} }
fun scrollUp() { fun scrollUp() {
val height = binding.nestedScrollView.measuredHeight val height = binding!!.nestedScrollView.measuredHeight
binding.nestedScrollView.smoothScrollBy(0, -height/2) binding!!.nestedScrollView.smoothScrollBy(0, -height/2)
} }
private fun openInBrowserAfterFailing() { private fun openInBrowserAfterFailing() {
binding.progressBar.visibility = View.GONE binding!!.progressBar.visibility = View.GONE
requireActivity().openInBrowserAsNewTask(this@ArticleFragment.item) requireActivity().openInBrowserAsNewTask(this@ArticleFragment.item)
} }
@ -495,10 +495,10 @@ class ArticleFragment : Fragment(), DIAware {
} }
fun performClick(): Boolean { fun performClick(): Boolean {
if (binding.webcontent.hitTestResult.type == WebView.HitTestResult.IMAGE_TYPE || if (binding!!.webcontent.hitTestResult.type == WebView.HitTestResult.IMAGE_TYPE ||
binding.webcontent.hitTestResult.type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { binding!!.webcontent.hitTestResult.type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
val position : Int = allImages.indexOf(binding.webcontent.hitTestResult.extra) val position : Int = allImages.indexOf(binding!!.webcontent.hitTestResult.extra)
val intent = Intent(activity, ImageActivity::class.java) val intent = Intent(activity, ImageActivity::class.java)
intent.putExtra("allImages", allImages) intent.putExtra("allImages", allImages)