fix: Sometimes url isn't even defined.
This commit is contained in:
parent
85208c4e5a
commit
996a7ed22c
@ -31,7 +31,6 @@ import bou.amine.apps.readerforselfossv2.android.utils.openInBrowserAsNewTask
|
|||||||
import bou.amine.apps.readerforselfossv2.android.utils.shareLink
|
import bou.amine.apps.readerforselfossv2.android.utils.shareLink
|
||||||
import bou.amine.apps.readerforselfossv2.model.MercuryModel
|
import bou.amine.apps.readerforselfossv2.model.MercuryModel
|
||||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||||
import bou.amine.apps.readerforselfossv2.model.StatusAndData
|
|
||||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||||
import bou.amine.apps.readerforselfossv2.rest.MercuryApi
|
import bou.amine.apps.readerforselfossv2.rest.MercuryApi
|
||||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||||
@ -260,21 +259,8 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
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) {
|
||||||
binding.titleView.text = response.data!!.title.orEmpty()
|
handleMercuryData(response.data!!)
|
||||||
if (typeface != null) {
|
|
||||||
binding.titleView.typeface = typeface
|
|
||||||
}
|
|
||||||
URL(response.data!!.url)
|
|
||||||
url = response.data!!.url
|
|
||||||
|
|
||||||
contentText = response.data!!.content.orEmpty()
|
|
||||||
htmlToWebview()
|
|
||||||
|
|
||||||
handleLeadImage(response)
|
|
||||||
|
|
||||||
binding.nestedScrollView.scrollTo(0, 0)
|
|
||||||
binding.progressBar.visibility = View.GONE
|
|
||||||
} else {
|
} else {
|
||||||
openInBrowserAfterFailing()
|
openInBrowserAfterFailing()
|
||||||
}
|
}
|
||||||
@ -287,14 +273,35 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleLeadImage(response: StatusAndData<MercuryModel.ParsedContent>) {
|
private fun handleMercuryData(data: MercuryModel.ParsedContent) {
|
||||||
if (!response.data?.lead_image_url.isNullOrEmpty() && context != null) {
|
if (data.error == true || data.failed == true) {
|
||||||
|
openInBrowserAfterFailing()
|
||||||
|
} else {
|
||||||
|
binding.titleView.text = data.title.orEmpty()
|
||||||
|
if (typeface != null) {
|
||||||
|
binding.titleView.typeface = typeface
|
||||||
|
}
|
||||||
|
URL(data.url)
|
||||||
|
url = data.url!!
|
||||||
|
|
||||||
|
contentText = data.content.orEmpty()
|
||||||
|
htmlToWebview()
|
||||||
|
|
||||||
|
handleLeadImage(data?.lead_image_url)
|
||||||
|
|
||||||
|
binding.nestedScrollView.scrollTo(0, 0)
|
||||||
|
binding.progressBar.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleLeadImage(lead_image_url: String?) {
|
||||||
|
if (!lead_image_url.isNullOrEmpty() && context != null) {
|
||||||
binding.imageView.visibility = View.VISIBLE
|
binding.imageView.visibility = View.VISIBLE
|
||||||
Glide
|
Glide
|
||||||
.with(requireContext())
|
.with(requireContext())
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.load(
|
.load(
|
||||||
response.data!!.lead_image_url.orEmpty()
|
lead_image_url
|
||||||
)
|
)
|
||||||
.apply(RequestOptions.fitCenterTransform())
|
.apply(RequestOptions.fitCenterTransform())
|
||||||
.into(binding.imageView)
|
.into(binding.imageView)
|
||||||
|
@ -9,6 +9,9 @@ class MercuryModel {
|
|||||||
val title: String?,
|
val title: String?,
|
||||||
val content: String?,
|
val content: String?,
|
||||||
val lead_image_url: String?, // NOSONAR
|
val lead_image_url: String?, // NOSONAR
|
||||||
val url: String
|
val url: String?,
|
||||||
|
val error: Boolean?,
|
||||||
|
val message: String?,
|
||||||
|
val failed: Boolean?
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user