From 87ed5b0fa8fb622f325569916fa23ef93998963e Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sun, 4 Dec 2022 20:46:43 +0100 Subject: [PATCH] Cleaning, and fixing socket timeout log. --- .../android/HomeActivity.kt | 3 - .../android/fragments/ArticleFragment.kt | 114 +++++++++--------- 2 files changed, 55 insertions(+), 62 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt index 882fd1c..29c575f 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt @@ -59,8 +59,6 @@ import com.mikepenz.materialdrawer.util.updateBadge import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import org.acra.ACRA -import org.acra.ktx.sendSilentlyWithAcra import org.kodein.di.DIAware import org.kodein.di.android.closestDI import org.kodein.di.instance @@ -324,7 +322,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar private fun handleGDPRDialog(GDPRShown: Boolean) { val messageDigest: MessageDigest = MessageDigest.getInstance("SHA-256") messageDigest.update(appSettingsService.getBaseUrl().toByteArray()) - ACRA.errorReporter.putCustomData("unique_id", String(messageDigest.digest())) if (!GDPRShown) { val alertDialog = AlertDialog.Builder(this).create() alertDialog.setTitle(getString(R.string.gdpr_dialog_title)) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt index e52ff45..c3d6d9c 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt @@ -52,6 +52,7 @@ import org.kodein.di.DIAware import org.kodein.di.android.x.closestDI import org.kodein.di.instance import java.net.MalformedURLException +import java.net.SocketTimeoutException import java.net.URL import java.util.* import java.util.concurrent.ExecutionException @@ -255,74 +256,69 @@ class ArticleFragment : Fragment(), DIAware { binding.progressBar.visibility = View.VISIBLE CoroutineScope(Dispatchers.Main).launch { - val response = mercuryApi.query(url) - if (response.success) { - try { - if (response.data != null && response.data!!.content != null && !response.data!!.content.isNullOrEmpty()) { + try { + val response = mercuryApi.query(url) + if (response.success && response.data != null && !response.data?.content.isNullOrEmpty()) { + binding.titleView.text = response.data!!.title.orEmpty() + try { + if (typeface != null) { + binding.titleView.typeface = typeface + } + } catch (e: Exception) { + e.sendSilentlyWithAcraWithName("getContentFromMercury > typeface") + } + + try { + // Note: Mercury may return relative urls... If it does the url val will not be changed. + URL(response.data!!.url) + url = response.data!!.url + } catch (e: MalformedURLException) { + // Mercury returned a relative url + e.sendSilentlyWithAcraWithName("getContentFromMercury > malformedurlexception") + } + + try { + contentText = response.data!!.content.orEmpty() + htmlToWebview() + } catch (e: Exception) { + e.sendSilentlyWithAcraWithName("getContentFromMercury > contenttext or html") + } + + if (!response.data?.lead_image_url.isNullOrEmpty() && context != null) { try { - binding.titleView.text = response.data!!.title - if (typeface != null) { - binding.titleView.typeface = typeface - } + binding.imageView.visibility = View.VISIBLE try { - // Note: Mercury may return relative urls... If it does the url val will not be changed. - URL(response.data!!.url) - url = response.data!!.url - } catch (e: MalformedURLException) { - // Mercury returned a relative url - e.sendSilentlyWithAcraWithName("getContentFromMercury > malformedurlexception") - } - } catch (e: Exception) { - e.sendSilentlyWithAcraWithName("getContentFromMercury > title or typeface") - } - - try { - contentText = response.data!!.content.orEmpty() - htmlToWebview() - } catch (e: Exception) { - e.sendSilentlyWithAcraWithName("getContentFromMercury > contenttext or html") - } - - try { - if (response.data!!.lead_image_url != null && !response.data!!.lead_image_url.isNullOrEmpty() && context != null) { - binding.imageView.visibility = View.VISIBLE - try { - Glide - .with(requireContext()) - .asBitmap() - .load( - response.data!!.lead_image_url.orEmpty() - ) - .apply(RequestOptions.fitCenterTransform()) - .into(binding.imageView) - } catch (e: Exception) { - e.sendSilentlyWithAcraWithName("getContentFromMercury > glide lead image") - } - } else { - binding.imageView.visibility = View.GONE + Glide + .with(requireContext()) + .asBitmap() + .load( + response.data!!.lead_image_url.orEmpty() + ) + .apply(RequestOptions.fitCenterTransform()) + .into(binding.imageView) + } catch (e: Exception) { + e.sendSilentlyWithAcraWithName("getContentFromMercury > glide lead image") } } catch (e: Exception) { e.sendSilentlyWithAcraWithName("getContentFromMercury > outside glide lead image") } - - try { - binding.nestedScrollView.scrollTo(0, 0) - - binding.progressBar.visibility = View.GONE - } catch (e: Exception) { - e.sendSilentlyWithAcraWithName("getContentFromMercury > scrollview") - } } else { - try { - openInBrowserAfterFailing() - } catch (e: Exception) { - e.sendSilentlyWithAcraWithName("getContentFromMercury > open after fail") - } + binding.imageView.visibility = View.GONE } - } catch (e: Exception) { - e.sendSilentlyWithAcraWithName("getContentFromMercury > whole thing") + + try { + binding.nestedScrollView.scrollTo(0, 0) + binding.progressBar.visibility = View.GONE + } catch (e: Exception) { + e.sendSilentlyWithAcraWithName("getContentFromMercury > scrollview") + } + } else { + openInBrowserAfterFailing() } - } else { + } catch (e: SocketTimeoutException) { + openInBrowserAfterFailing() + } catch (e: Exception) { + e.sendSilentlyWithAcraWithName("getContentFromMercury > whole thing") openInBrowserAfterFailing() } }