Settings for silent debug.

This commit is contained in:
Amine Bou 2018-05-22 20:20:39 +02:00
parent f8d3e1eefb
commit eb02d1efad
9 changed files with 44 additions and 19 deletions

View File

@ -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()
}
)

View File

@ -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,

View File

@ -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)
}
}
}

View File

@ -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<VH : RecyclerView.ViewHolder?> : 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<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
override fun onFailure(call: Call<SuccessResponse>, 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(

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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()

View File

@ -168,4 +168,5 @@
<string name="pref_acra_alwaysaccept_disabled">Will ask everytime when sending crash reports.</string>
<string name="pref_debug_crash_reports">Crash reports</string>
<string name="pref_debug_debug_logs">Debug logging (these will be sent without a dialog)</string>
<string name="acra_login">Enable logging</string>
</resources>

View File

@ -15,23 +15,31 @@
android:title="@string/pref_acra_alwaysaccept" />
</PreferenceCategory>
<PreferenceCategory>
<PreferenceCategory android:title="@string/pref_debug_debug_logs">
<SwitchPreference
android:defaultValue="false"
android:key="acra_should_log"
android:title="@string/acra_login" />
<SwitchPreference
android:defaultValue="false"
android:key="should_log_everything"
android:dependency="acra_should_log"
android:summaryOff="@string/login_everything_off"
android:summaryOn="@string/login_everything_on"
android:title="@string/login_everything_title" />
<SwitchPreference
android:defaultValue="false"
android:key="login_debug"
android:dependency="acra_should_log"
android:summaryOff="@string/login_debug_off"
android:summaryOn="@string/login_debug_on"
android:title="@string/login_debug_title" />
<SwitchPreference
android:defaultValue="false"
android:key="read_debug"
android:dependency="acra_should_log"
android:summaryOff="@string/read_debug_off"
android:summaryOn="@string/read_debug_on"
android:title="@string/read_debug_title" />