fix: Sometimes url isn't even defined.
All checks were successful
continuous-integration/drone/tag Build is passing
All checks were successful
continuous-integration/drone/tag Build is passing
This commit is contained in:
parent
85208c4e5a
commit
2dc7d240a5
@ -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.model.MercuryModel
|
||||
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.rest.MercuryApi
|
||||
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||
@ -260,21 +259,8 @@ class ArticleFragment : Fragment(), DIAware {
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
try {
|
||||
val response = mercuryApi.query(url)
|
||||
if (response.success && response.data != null && !response.data?.content.isNullOrEmpty()) {
|
||||
binding.titleView.text = response.data!!.title.orEmpty()
|
||||
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
|
||||
if (response.success && response.data != null) {
|
||||
handleMercuryData(response.data!!)
|
||||
} else {
|
||||
openInBrowserAfterFailing()
|
||||
}
|
||||
@ -287,14 +273,35 @@ class ArticleFragment : Fragment(), DIAware {
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleLeadImage(response: StatusAndData<MercuryModel.ParsedContent>) {
|
||||
if (!response.data?.lead_image_url.isNullOrEmpty() && context != null) {
|
||||
private fun handleMercuryData(data: MercuryModel.ParsedContent) {
|
||||
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
|
||||
Glide
|
||||
.with(requireContext())
|
||||
.asBitmap()
|
||||
.load(
|
||||
response.data!!.lead_image_url.orEmpty()
|
||||
lead_image_url
|
||||
)
|
||||
.apply(RequestOptions.fitCenterTransform())
|
||||
.into(binding.imageView)
|
||||
|
@ -9,6 +9,9 @@ class MercuryModel {
|
||||
val title: String?,
|
||||
val content: String?,
|
||||
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