From eb02d1efad6c6bdb919f1e4d11b52c99f0c719a6 Mon Sep 17 00:00:00 2001 From: Amine Bou Date: Tue, 22 May 2018 20:20:39 +0200 Subject: [PATCH] Settings for silent debug. --- .../amine/bou/readerforselfoss/HomeActivity.kt | 10 +++++----- .../amine/bou/readerforselfoss/LoginActivity.kt | 3 ++- .../amine/bou/readerforselfoss/ReaderActivity.kt | 5 +++-- .../bou/readerforselfoss/adapters/ItemsAdapter.kt | 5 +++-- .../readerforselfoss/fragments/ArticleFragment.kt | 15 ++++++++------- .../apps/amine/bou/readerforselfoss/utils/Acra.kt | 12 ++++++++++++ .../bou/readerforselfoss/utils/ItemsUtils.kt | 2 +- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_debug.xml | 10 +++++++++- 9 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/apps/amine/bou/readerforselfoss/utils/Acra.kt diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt index 1467c79..ffb108a 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -40,6 +40,7 @@ import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper import apps.amine.bou.readerforselfoss.utils.drawer.CustomUrlPrimaryDrawerItem import apps.amine.bou.readerforselfoss.utils.flattenTags import apps.amine.bou.readerforselfoss.utils.longHash +import apps.amine.bou.readerforselfoss.utils.maybeHandleSilentException import co.zsmb.materialdrawerkt.builders.accountHeader import co.zsmb.materialdrawerkt.builders.drawer import co.zsmb.materialdrawerkt.builders.footer @@ -64,6 +65,7 @@ import com.mikepenz.materialdrawer.model.DividerDrawerItem import com.mikepenz.materialdrawer.model.PrimaryDrawerItem import com.mikepenz.materialdrawer.model.SecondaryDrawerItem import kotlinx.android.synthetic.main.activity_home.* +import org.acra.ACRA import retrofit2.Call import retrofit2.Callback import retrofit2.Response @@ -162,13 +164,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { handleDrawer() handleSwipeRefreshLayout() - - throw NullPointerException() - } private fun handleGDPRDialog(GDPRShown: Boolean) { if (!GDPRShown) { + val sharedEditor = sharedPref.edit() val alertDialog = AlertDialog.Builder(this).create() alertDialog.setTitle(getString(R.string.gdpr_dialog_title)) alertDialog.setMessage(getString(R.string.gdpr_dialog_message)) @@ -176,8 +176,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { AlertDialog.BUTTON_NEUTRAL, "OK", { dialog, _ -> - editor.putBoolean("GDPR_shown", true) - editor.commit() + sharedEditor.putBoolean("GDPR_shown", true) + sharedEditor.commit() dialog.dismiss() } ) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt index a2468be..5182df3 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt @@ -20,6 +20,7 @@ import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse import apps.amine.bou.readerforselfoss.themes.AppColors import apps.amine.bou.readerforselfoss.utils.Config import apps.amine.bou.readerforselfoss.utils.isBaseUrlValid +import apps.amine.bou.readerforselfoss.utils.maybeHandleSilentException import com.mikepenz.aboutlibraries.Libs import com.mikepenz.aboutlibraries.LibsBuilder import kotlinx.android.synthetic.main.activity_login.* @@ -209,7 +210,7 @@ class LoginActivity : AppCompatActivity() { httpLoginView.error = getString(R.string.wrong_infos) httpPasswordView.error = getString(R.string.wrong_infos) if (logErrors) { - ACRA.getErrorReporter().handleSilentException(t) + ACRA.getErrorReporter().maybeHandleSilentException(t, this@LoginActivity) Toast.makeText( this@LoginActivity, t.message, diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt index f9f4bf9..f44bc12 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt @@ -22,6 +22,7 @@ import apps.amine.bou.readerforselfoss.themes.AppColors import apps.amine.bou.readerforselfoss.themes.Toppings import apps.amine.bou.readerforselfoss.transformers.DepthPageTransformer import apps.amine.bou.readerforselfoss.utils.Config +import apps.amine.bou.readerforselfoss.utils.maybeHandleSilentException import apps.amine.bou.readerforselfoss.utils.succeeded import apps.amine.bou.readerforselfoss.utils.toggleStar import com.ftinc.scoop.Scoop @@ -132,7 +133,7 @@ class ReaderActivity : AppCompatActivity() { "response errorBody: ${response.errorBody()?.string()} " + "body success: ${response.body()?.success} " + "body isSuccess: ${response.body()?.isSuccess}" - ACRA.getErrorReporter().handleSilentException(Exception(message)) + ACRA.getErrorReporter().maybeHandleSilentException(Exception(message), this@ReaderActivity) } } @@ -141,7 +142,7 @@ class ReaderActivity : AppCompatActivity() { t: Throwable ) { if (debugReadingItems) { - ACRA.getErrorReporter().handleSilentException(t) + ACRA.getErrorReporter().maybeHandleSilentException(t, this@ReaderActivity) } } } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemsAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemsAdapter.kt index 142f0bf..6b69283 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemsAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemsAdapter.kt @@ -11,6 +11,7 @@ import apps.amine.bou.readerforselfoss.api.selfoss.Item import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse import apps.amine.bou.readerforselfoss.themes.AppColors +import apps.amine.bou.readerforselfoss.utils.maybeHandleSilentException import apps.amine.bou.readerforselfoss.utils.succeeded import org.acra.ACRA import retrofit2.Call @@ -89,7 +90,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte "response errorBody: ${response.errorBody()?.string()} " + "body success: ${response.body()?.success} " + "body isSuccess: ${response.body()?.isSuccess}" - ACRA.getErrorReporter().handleSilentException(Exception(message)) + ACRA.getErrorReporter().maybeHandleSilentException(Exception(message), app) Toast.makeText(app.baseContext, message, Toast.LENGTH_LONG).show() } doUnmark(i, position) @@ -97,7 +98,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte override fun onFailure(call: Call, t: Throwable) { if (debugReadingItems) { - ACRA.getErrorReporter().handleSilentException(t) + ACRA.getErrorReporter().maybeHandleSilentException(t, app) Toast.makeText(app.baseContext, t.message, Toast.LENGTH_LONG).show() } Toast.makeText( diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt index 59cf4bf..eb95064 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/fragments/ArticleFragment.kt @@ -29,6 +29,7 @@ import apps.amine.bou.readerforselfoss.themes.AppColors import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper import apps.amine.bou.readerforselfoss.utils.isEmptyOrNullOrNullString +import apps.amine.bou.readerforselfoss.utils.maybeHandleSilentException import apps.amine.bou.readerforselfoss.utils.openItemUrl import apps.amine.bou.readerforselfoss.utils.shareLink import apps.amine.bou.readerforselfoss.utils.sourceAndDateText @@ -196,13 +197,13 @@ class ArticleFragment : Fragment() { rootView.titleView.text = response.body()!!.title url = response.body()!!.url } catch (e: Exception) { - ACRA.getErrorReporter().handleSilentException(e) + ACRA.getErrorReporter().maybeHandleSilentException(e, context) } try { htmlToWebview(response.body()!!.content.orEmpty(), prefs, context) } catch (e: Exception) { - ACRA.getErrorReporter().handleSilentException(e) + ACRA.getErrorReporter().maybeHandleSilentException(e, context) } try { @@ -216,13 +217,13 @@ class ArticleFragment : Fragment() { .apply(RequestOptions.fitCenterTransform()) .into(rootView.imageView) } catch (e: Exception) { - ACRA.getErrorReporter().handleSilentException(e) + ACRA.getErrorReporter().maybeHandleSilentException(e, context) } } else { rootView.imageView.visibility = View.GONE } } catch (e: Exception) { - ACRA.getErrorReporter().handleSilentException(e) + ACRA.getErrorReporter().maybeHandleSilentException(e, context) } try { @@ -230,17 +231,17 @@ class ArticleFragment : Fragment() { rootView.progressBar.visibility = View.GONE } catch (e: Exception) { - ACRA.getErrorReporter().handleSilentException(e) + ACRA.getErrorReporter().maybeHandleSilentException(e, context) } } else { try { openInBrowserAfterFailing(customTabsIntent) } catch (e: Exception) { - ACRA.getErrorReporter().handleSilentException(e) + ACRA.getErrorReporter().maybeHandleSilentException(e, context) } } } catch (e: Exception) { - ACRA.getErrorReporter().handleSilentException(e) + ACRA.getErrorReporter().maybeHandleSilentException(e, context) } } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/Acra.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/Acra.kt new file mode 100644 index 0000000..fd04b0c --- /dev/null +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/Acra.kt @@ -0,0 +1,12 @@ +package apps.amine.bou.readerforselfoss.utils + +import android.content.Context +import android.preference.PreferenceManager +import org.acra.ErrorReporter + +fun ErrorReporter.maybeHandleSilentException(throwable: Throwable, ctx: Context) { + val sharedPref = PreferenceManager.getDefaultSharedPreferences(ctx) + if (sharedPref.getBoolean("acra_should_log", false)) { + this.handleSilentException(throwable) + } +} \ No newline at end of file diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt index 363e6be..348147d 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt @@ -14,7 +14,7 @@ fun String.toTextDrawableString(c: Context): String { try { textDrawable.append(s[0]) } catch (e: StringIndexOutOfBoundsException) { - ACRA.getErrorReporter().handleSilentException(e) + ACRA.getErrorReporter().maybeHandleSilentException(e, c) } } return textDrawable.toString() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3edef03..28c5d7b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -168,4 +168,5 @@ Will ask everytime when sending crash reports. Crash reports Debug logging (these will be sent without a dialog) + Enable logging diff --git a/app/src/main/res/xml/pref_debug.xml b/app/src/main/res/xml/pref_debug.xml index 46ffde5..7581abd 100644 --- a/app/src/main/res/xml/pref_debug.xml +++ b/app/src/main/res/xml/pref_debug.xml @@ -15,23 +15,31 @@ android:title="@string/pref_acra_alwaysaccept" /> - + + +