From 6947743ac051cb269b3c1376e50d2c32d8c12db3 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sat, 3 Dec 2022 21:39:46 +0100 Subject: [PATCH] More details for silent reports. --- .../readerforselfossv2/android/ACRAUtils.kt | 9 ++++++ .../android/HomeActivity.kt | 3 +- .../android/fragments/ArticleFragment.kt | 29 ++++++++++--------- .../android/model/AndroidIModelUtils.kt | 5 ++-- .../android/settings/SettingsActivity.kt | 7 +++-- 5 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ACRAUtils.kt diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ACRAUtils.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ACRAUtils.kt new file mode 100644 index 0000000..9bfb152 --- /dev/null +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ACRAUtils.kt @@ -0,0 +1,9 @@ +package bou.amine.apps.readerforselfossv2.android + +import org.acra.ACRA +import org.acra.ktx.sendSilentlyWithAcra + +fun Throwable.sendSilentlyWithAcraWithName(name: String) { + ACRA.errorReporter.putCustomData("error_source", name) + this.sendSilentlyWithAcra() +} \ No newline at end of file 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 9104969..882fd1c 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 @@ -61,7 +61,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import org.acra.ACRA import org.acra.ktx.sendSilentlyWithAcra -import org.acra.ktx.sendWithAcra import org.kodein.di.DIAware import org.kodein.di.android.closestDI import org.kodein.di.instance @@ -513,7 +512,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar val gdColor = try { Color.parseColor(it.color) } catch (e: IllegalArgumentException) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("color issue " + it.color) resources.getColor(R.color.colorPrimary) } gd.setColor(gdColor) 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 555c384..e52ff45 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 @@ -25,6 +25,7 @@ import bou.amine.apps.readerforselfossv2.android.databinding.FragmentArticleBind import bou.amine.apps.readerforselfossv2.android.model.ParecelableItem import bou.amine.apps.readerforselfossv2.android.model.toModel import bou.amine.apps.readerforselfossv2.android.model.toParcelable +import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName import bou.amine.apps.readerforselfossv2.android.utils.glide.getBitmapInputStream import bou.amine.apps.readerforselfossv2.android.utils.openInBrowserAsNewTask import bou.amine.apps.readerforselfossv2.android.utils.shareLink @@ -114,7 +115,7 @@ class ArticleFragment : Fragment(), DIAware { typeface = try { ResourcesCompat.getFont(requireContext(), resId)!! } catch (e: java.lang.Exception) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("typeface") // Just to be sure null } @@ -220,7 +221,7 @@ class ArticleFragment : Fragment(), DIAware { ) } catch (e: InflateException) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("webview not available") AlertDialog.Builder(requireContext()) .setMessage(requireContext().getString(R.string.webview_dialog_issue_message)) .setTitle(requireContext().getString(R.string.webview_dialog_issue_title)) @@ -269,17 +270,17 @@ class ArticleFragment : Fragment(), DIAware { url = response.data!!.url } catch (e: MalformedURLException) { // Mercury returned a relative url - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("getContentFromMercury > malformedurlexception") } } catch (e: Exception) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("getContentFromMercury > title or typeface") } try { contentText = response.data!!.content.orEmpty() htmlToWebview() } catch (e: Exception) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("getContentFromMercury > contenttext or html") } try { @@ -295,13 +296,13 @@ class ArticleFragment : Fragment(), DIAware { .apply(RequestOptions.fitCenterTransform()) .into(binding.imageView) } catch (e: Exception) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("getContentFromMercury > glide lead image") } } else { binding.imageView.visibility = View.GONE } } catch (e: Exception) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("getContentFromMercury > outside glide lead image") } try { @@ -309,17 +310,17 @@ class ArticleFragment : Fragment(), DIAware { binding.progressBar.visibility = View.GONE } catch (e: Exception) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("getContentFromMercury > scrollview") } } else { try { openInBrowserAfterFailing() } catch (e: Exception) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("getContentFromMercury > open after fail") } } } catch (e: Exception) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("getContentFromMercury > whole thing") } } else { openInBrowserAfterFailing() @@ -364,7 +365,7 @@ class ArticleFragment : Fragment(), DIAware { val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get() return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.JPEG)) } catch ( e : ExecutionException) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("shouldInterceptRequest > jpeg") } } else if (url.lowercase(Locale.US).contains(".png")) { @@ -372,7 +373,7 @@ class ArticleFragment : Fragment(), DIAware { val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get() return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.PNG)) } catch ( e : ExecutionException) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("shouldInterceptRequest > png") } } else if (url.lowercase(Locale.US).contains(".webp")) { @@ -380,7 +381,7 @@ class ArticleFragment : Fragment(), DIAware { val image = Glide.with(view).asBitmap().apply(glideOptions).load(url).submit().get() return WebResourceResponse("image/jpg", "UTF-8", getBitmapInputStream(image, Bitmap.CompressFormat.WEBP)) } catch ( e : ExecutionException) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("shouldInterceptRequest > webp") } } @@ -405,7 +406,7 @@ class ArticleFragment : Fragment(), DIAware { val itemUrl = URL(url) baseUrl = itemUrl.protocol + "://" + itemUrl.host } catch (e: MalformedURLException) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("htmlToWebview > item url") } val fontName = when (font) { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/AndroidIModelUtils.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/AndroidIModelUtils.kt index 618dda2..ab0a8d2 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/AndroidIModelUtils.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/AndroidIModelUtils.kt @@ -2,6 +2,7 @@ package bou.amine.apps.readerforselfossv2.android.model import android.content.Context import android.webkit.URLUtil +import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.utils.getImages import com.bumptech.glide.Glide @@ -24,7 +25,7 @@ fun SelfossModel.Item.preloadImages(context: Context) : Boolean { } } } catch (e : Error) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("preloadImages") return false } @@ -37,7 +38,7 @@ fun String.toTextDrawableString(): String { try { textDrawable.append(s[0]) } catch (e: StringIndexOutOfBoundsException) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("toTextDrawableString") } } return textDrawable.toString() diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt index e3bbe13..e5fc87c 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt @@ -16,6 +16,7 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySettingsBinding +import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName import bou.amine.apps.readerforselfossv2.service.AppSettingsService import org.acra.ktx.sendSilentlyWithAcra import org.acra.ktx.sendWithAcra @@ -124,7 +125,7 @@ class SettingsActivity : AppCompatActivity(), val input: Int = (dest.toString() + source.toString()).toInt() if (input in 1..200) return@InputFilter null } catch (nfe: NumberFormatException) { - nfe.sendSilentlyWithAcra() + nfe.sendSilentlyWithAcraWithName("GeneralPreferenceFragment") Toast.makeText(activity, R.string.items_number_should_be_number, Toast.LENGTH_LONG).show() } "" @@ -148,7 +149,7 @@ class SettingsActivity : AppCompatActivity(), try { editText.textSize = editable.toString().toInt().toFloat() } catch (e: NumberFormatException) { - e.sendSilentlyWithAcra() + e.sendSilentlyWithAcraWithName("ArticleViewerPreferenceFragment > afterTextChanged") } } } } @@ -158,7 +159,7 @@ class SettingsActivity : AppCompatActivity(), val input = (dest.toString() + source.toString()).toInt() if (input > 0) return@InputFilter null } catch (nfe: NumberFormatException) { - nfe.sendSilentlyWithAcra() + nfe.sendSilentlyWithAcraWithName("ArticleViewerPreferenceFragment > filters") } "" }