Cleaning, and fixing socket timeout log.
All checks were successful
continuous-integration/drone/tag Build is passing

This commit is contained in:
aminecmi 2022-12-04 20:46:43 +01:00
parent 6947743ac0
commit 1c2b88a4ff
2 changed files with 55 additions and 62 deletions

View File

@ -59,8 +59,6 @@ import com.mikepenz.materialdrawer.util.updateBadge
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.acra.ACRA
import org.acra.ktx.sendSilentlyWithAcra
import org.kodein.di.DIAware import org.kodein.di.DIAware
import org.kodein.di.android.closestDI import org.kodein.di.android.closestDI
import org.kodein.di.instance import org.kodein.di.instance
@ -324,7 +322,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
private fun handleGDPRDialog(GDPRShown: Boolean) { private fun handleGDPRDialog(GDPRShown: Boolean) {
val messageDigest: MessageDigest = MessageDigest.getInstance("SHA-256") val messageDigest: MessageDigest = MessageDigest.getInstance("SHA-256")
messageDigest.update(appSettingsService.getBaseUrl().toByteArray()) messageDigest.update(appSettingsService.getBaseUrl().toByteArray())
ACRA.errorReporter.putCustomData("unique_id", String(messageDigest.digest()))
if (!GDPRShown) { if (!GDPRShown) {
val alertDialog = AlertDialog.Builder(this).create() val alertDialog = AlertDialog.Builder(this).create()
alertDialog.setTitle(getString(R.string.gdpr_dialog_title)) alertDialog.setTitle(getString(R.string.gdpr_dialog_title))

View File

@ -52,6 +52,7 @@ import org.kodein.di.DIAware
import org.kodein.di.android.x.closestDI import org.kodein.di.android.x.closestDI
import org.kodein.di.instance import org.kodein.di.instance
import java.net.MalformedURLException import java.net.MalformedURLException
import java.net.SocketTimeoutException
import java.net.URL import java.net.URL
import java.util.* import java.util.*
import java.util.concurrent.ExecutionException import java.util.concurrent.ExecutionException
@ -255,15 +256,18 @@ class ArticleFragment : Fragment(), DIAware {
binding.progressBar.visibility = View.VISIBLE binding.progressBar.visibility = View.VISIBLE
CoroutineScope(Dispatchers.Main).launch { CoroutineScope(Dispatchers.Main).launch {
try {
val response = mercuryApi.query(url) val response = mercuryApi.query(url)
if (response.success) { if (response.success && response.data != null && !response.data?.content.isNullOrEmpty()) {
binding.titleView.text = response.data!!.title.orEmpty()
try { try {
if (response.data != null && response.data!!.content != null && !response.data!!.content.isNullOrEmpty()) {
try {
binding.titleView.text = response.data!!.title
if (typeface != null) { if (typeface != null) {
binding.titleView.typeface = typeface binding.titleView.typeface = typeface
} }
} catch (e: Exception) {
e.sendSilentlyWithAcraWithName("getContentFromMercury > typeface")
}
try { try {
// Note: Mercury may return relative urls... If it does the url val will not be changed. // Note: Mercury may return relative urls... If it does the url val will not be changed.
URL(response.data!!.url) URL(response.data!!.url)
@ -272,9 +276,6 @@ class ArticleFragment : Fragment(), DIAware {
// Mercury returned a relative url // Mercury returned a relative url
e.sendSilentlyWithAcraWithName("getContentFromMercury > malformedurlexception") e.sendSilentlyWithAcraWithName("getContentFromMercury > malformedurlexception")
} }
} catch (e: Exception) {
e.sendSilentlyWithAcraWithName("getContentFromMercury > title or typeface")
}
try { try {
contentText = response.data!!.content.orEmpty() contentText = response.data!!.content.orEmpty()
@ -283,8 +284,8 @@ class ArticleFragment : Fragment(), DIAware {
e.sendSilentlyWithAcraWithName("getContentFromMercury > contenttext or html") e.sendSilentlyWithAcraWithName("getContentFromMercury > contenttext or html")
} }
if (!response.data?.lead_image_url.isNullOrEmpty() && context != null) {
try { try {
if (response.data!!.lead_image_url != null && !response.data!!.lead_image_url.isNullOrEmpty() && context != null) {
binding.imageView.visibility = View.VISIBLE binding.imageView.visibility = View.VISIBLE
try { try {
Glide Glide
@ -298,31 +299,26 @@ class ArticleFragment : Fragment(), DIAware {
} catch (e: Exception) { } catch (e: Exception) {
e.sendSilentlyWithAcraWithName("getContentFromMercury > glide lead image") e.sendSilentlyWithAcraWithName("getContentFromMercury > glide lead image")
} }
} else {
binding.imageView.visibility = View.GONE
}
} catch (e: Exception) { } catch (e: Exception) {
e.sendSilentlyWithAcraWithName("getContentFromMercury > outside glide lead image") e.sendSilentlyWithAcraWithName("getContentFromMercury > outside glide lead image")
} }
} else {
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")
} }
} else { } else {
try {
openInBrowserAfterFailing() openInBrowserAfterFailing()
} catch (e: Exception) { }
e.sendSilentlyWithAcraWithName("getContentFromMercury > open after fail") } catch (e: SocketTimeoutException) {
} openInBrowserAfterFailing()
}
} catch (e: Exception) { } catch (e: Exception) {
e.sendSilentlyWithAcraWithName("getContentFromMercury > whole thing") e.sendSilentlyWithAcraWithName("getContentFromMercury > whole thing")
}
} else {
openInBrowserAfterFailing() openInBrowserAfterFailing()
} }
} }