From 218b8fa84390ca11efd07760e422c86970b30e98 Mon Sep 17 00:00:00 2001 From: Amine Bou Date: Mon, 21 May 2018 21:39:23 +0200 Subject: [PATCH] Replace with ACRA bug reporter. --- app/build.gradle | 8 +++ .../bou/readerforselfoss/HomeActivity.kt | 26 ++++++++-- .../bou/readerforselfoss/LoginActivity.kt | 3 +- .../apps/amine/bou/readerforselfoss/MyApp.kt | 31 +++++++++++ .../bou/readerforselfoss/ReaderActivity.kt | 5 +- .../adapters/ItemCardAdapter.kt | 2 +- .../adapters/ItemListAdapter.kt | 2 +- .../readerforselfoss/adapters/ItemsAdapter.kt | 5 +- .../adapters/SourcesListAdapter.kt | 2 +- .../fragments/ArticleFragment.kt | 15 +++--- .../bou/readerforselfoss/utils/ItemsUtils.kt | 6 ++- app/src/main/res/values/strings.xml | 11 ++++ app/src/main/res/xml/pref_debug.xml | 51 ++++++++++++------- 13 files changed, 129 insertions(+), 38 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 83daa51..5a6f73e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,6 +38,10 @@ repositories { } android { + compileOptions { + sourceCompatibility 1.8 + targetCompatibility 1.8 + } compileSdkVersion 27 buildToolsVersion '27.0.3' defaultConfig { @@ -164,6 +168,10 @@ dependencies { implementation 'androidx.core:core-ktx:0.3' + // Crash + implementation "ch.acra:acra-http:5.1.3" + implementation "ch.acra:acra-dialog:5.1.3" + } 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 6ddcaa2..1467c79 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -1,12 +1,10 @@ package apps.amine.bou.readerforselfoss -import android.app.Activity import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.graphics.Color import android.graphics.drawable.GradientDrawable -import android.net.Uri import android.os.Bundle import android.preference.PreferenceManager import android.support.v4.view.MenuItemCompat @@ -164,6 +162,27 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { handleDrawer() handleSwipeRefreshLayout() + + throw NullPointerException() + + } + + private fun handleGDPRDialog(GDPRShown: Boolean) { + if (!GDPRShown) { + val alertDialog = AlertDialog.Builder(this).create() + alertDialog.setTitle(getString(R.string.gdpr_dialog_title)) + alertDialog.setMessage(getString(R.string.gdpr_dialog_message)) + alertDialog.setButton( + AlertDialog.BUTTON_NEUTRAL, + "OK", + { dialog, _ -> + editor.putBoolean("GDPR_shown", true) + editor.commit() + dialog.dismiss() + } + ) + alertDialog.show() + } } private fun handleSwipeRefreshLayout() { @@ -339,6 +358,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { handleBottomBarActions() getElementsAccordingToTab() + + handleGDPRDialog(sharedPref.getBoolean("GDPR_shown", false)) } override fun onStop() { @@ -417,7 +438,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { ) .theme(R.style.Theme_App_Light) .guestToken(BuildConfig.GITHUB_TOKEN) - .guestEmailRequired(true) .minDescriptionLength(20) .putExtraInfo("Unique ID", settings.getString("unique_id", "")) .putExtraInfo("From github", BuildConfig.GITHUB_VERSION) 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 55c973b..a2468be 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt @@ -23,6 +23,7 @@ import apps.amine.bou.readerforselfoss.utils.isBaseUrlValid import com.mikepenz.aboutlibraries.Libs import com.mikepenz.aboutlibraries.LibsBuilder import kotlinx.android.synthetic.main.activity_login.* +import org.acra.ACRA import retrofit2.Call import retrofit2.Callback import retrofit2.Response @@ -208,7 +209,7 @@ class LoginActivity : AppCompatActivity() { httpLoginView.error = getString(R.string.wrong_infos) httpPasswordView.error = getString(R.string.wrong_infos) if (logErrors) { - // TODO: log + ACRA.getErrorReporter().handleSilentException(t) Toast.makeText( this@LoginActivity, t.message, diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt index b5e590c..6f1d3b6 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt @@ -1,6 +1,7 @@ package apps.amine.bou.readerforselfoss import android.content.Context +import android.content.SharedPreferences import android.graphics.drawable.Drawable import android.net.Uri import android.preference.PreferenceManager @@ -16,9 +17,31 @@ import com.github.stkent.amplify.feedback.GooglePlayStoreFeedbackCollector import com.github.stkent.amplify.tracking.Amplify import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader import com.mikepenz.materialdrawer.util.DrawerImageLoader +import org.acra.ACRA +import org.acra.ReportField +import org.acra.annotation.AcraCore +import org.acra.annotation.AcraDialog +import org.acra.annotation.AcraHttpSender +import org.acra.sender.HttpSender import java.io.IOException import java.util.UUID.randomUUID + +@AcraHttpSender(uri = "http://amine-bou.fr:5984/acra-selfoss/_design/acra-storage/_update/report", + basicAuthLogin = "selfoss", + basicAuthPassword = "selfoss", + httpMethod = HttpSender.Method.PUT) +@AcraDialog(resText = R.string.crash_dialog_text, + resCommentPrompt = R.string.crash_dialog_comment, + resTheme = android.R.style.Theme_DeviceDefault_Dialog) +@AcraCore(reportContent = [ReportField.REPORT_ID, ReportField.INSTALLATION_ID, + ReportField.APP_VERSION_CODE, ReportField.APP_VERSION_NAME, + ReportField.BUILD, ReportField.ANDROID_VERSION, ReportField.BRAND, ReportField.PHONE_MODEL, + ReportField.AVAILABLE_MEM_SIZE, ReportField.TOTAL_MEM_SIZE, + ReportField.STACK_TRACE, ReportField.APPLICATION_LOG, ReportField.LOGCAT, + ReportField.INITIAL_CONFIGURATION, ReportField.CRASH_CONFIGURATION, ReportField.IS_SILENT, + ReportField.USER_APP_START_DATE, ReportField.USER_COMMENT, ReportField.USER_CRASH_DATE, ReportField.USER_EMAIL, ReportField.CUSTOM_DATA], + buildConfigClass = BuildConfig::class) class MyApp : MultiDexApplication() { override fun onCreate() { @@ -42,6 +65,14 @@ class MyApp : MultiDexApplication() { tryToHandleBug() } + override fun attachBaseContext(base: Context?) { + super.attachBaseContext(base) + val prefs = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE) + ACRA.init(this) + ACRA.getErrorReporter().putCustomData("unique_id", prefs.getString("unique_id", "")) + + } + private fun initAmplify() { Amplify.initSharedInstance(this) .setPositiveFeedbackCollectors(GooglePlayStoreFeedbackCollector()) 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 22fa3f9..f9f4bf9 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/ReaderActivity.kt @@ -27,6 +27,7 @@ import apps.amine.bou.readerforselfoss.utils.toggleStar import com.ftinc.scoop.Scoop import kotlinx.android.synthetic.main.activity_reader.* import me.relex.circleindicator.CircleIndicator +import org.acra.ACRA import retrofit2.Call import retrofit2.Callback import retrofit2.Response @@ -131,7 +132,7 @@ class ReaderActivity : AppCompatActivity() { "response errorBody: ${response.errorBody()?.string()} " + "body success: ${response.body()?.success} " + "body isSuccess: ${response.body()?.isSuccess}" - // TODO: logs + ACRA.getErrorReporter().handleSilentException(Exception(message)) } } @@ -140,7 +141,7 @@ class ReaderActivity : AppCompatActivity() { t: Throwable ) { if (debugReadingItems) { - // TODO: logs + ACRA.getErrorReporter().handleSilentException(t) } } } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt index ad9c2f3..c4a6f76 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemCardAdapter.kt @@ -89,7 +89,7 @@ class ItemCardAdapter( TextDrawable .builder() .round() - .build(itm.sourcetitle.toTextDrawableString(), color) + .build(itm.sourcetitle.toTextDrawableString(c), color) holder.mView.sourceImage.setImageDrawable(drawable) } else { c.circularBitmapDrawable(itm.getIcon(c), holder.mView.sourceImage) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt index 5870145..42ebc6f 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/ItemListAdapter.kt @@ -97,7 +97,7 @@ class ItemListAdapter( TextDrawable .builder() .round() - .build(itm.sourcetitle.toTextDrawableString(), color) + .build(itm.sourcetitle.toTextDrawableString(c), color) holder.mView.itemImage.setImageDrawable(drawable) } else { 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 3098730..142f0bf 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 @@ -12,6 +12,7 @@ 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.succeeded +import org.acra.ACRA import retrofit2.Call import retrofit2.Callback import retrofit2.Response @@ -88,7 +89,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte "response errorBody: ${response.errorBody()?.string()} " + "body success: ${response.body()?.success} " + "body isSuccess: ${response.body()?.isSuccess}" - // TODO: logs + ACRA.getErrorReporter().handleSilentException(Exception(message)) Toast.makeText(app.baseContext, message, Toast.LENGTH_LONG).show() } doUnmark(i, position) @@ -96,7 +97,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte override fun onFailure(call: Call, t: Throwable) { if (debugReadingItems) { - // TODO: logs + ACRA.getErrorReporter().handleSilentException(t) Toast.makeText(app.baseContext, t.message, Toast.LENGTH_LONG).show() } Toast.makeText( diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt index 2a3560d..957384c 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/adapters/SourcesListAdapter.kt @@ -48,7 +48,7 @@ class SourcesListAdapter( TextDrawable .builder() .round() - .build(itm.title.toTextDrawableString(), color) + .build(itm.title.toTextDrawableString(c), color) holder.mView.itemImage.setImageDrawable(drawable) } else { c.circularBitmapDrawable(itm.getIcon(c), holder.mView.itemImage) 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 fc41b54..59cf4bf 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 @@ -37,6 +37,7 @@ import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import com.github.rubensousa.floatingtoolbar.FloatingToolbar import kotlinx.android.synthetic.main.fragment_article.view.* +import org.acra.ACRA import retrofit2.Call import retrofit2.Callback import retrofit2.Response @@ -195,13 +196,13 @@ class ArticleFragment : Fragment() { rootView.titleView.text = response.body()!!.title url = response.body()!!.url } catch (e: Exception) { - // TODO: logs + ACRA.getErrorReporter().handleSilentException(e) } try { htmlToWebview(response.body()!!.content.orEmpty(), prefs, context) } catch (e: Exception) { - // TODO: logs + ACRA.getErrorReporter().handleSilentException(e) } try { @@ -215,13 +216,13 @@ class ArticleFragment : Fragment() { .apply(RequestOptions.fitCenterTransform()) .into(rootView.imageView) } catch (e: Exception) { - // TODO: logs + ACRA.getErrorReporter().handleSilentException(e) } } else { rootView.imageView.visibility = View.GONE } } catch (e: Exception) { - // TODO: logs + ACRA.getErrorReporter().handleSilentException(e) } try { @@ -229,17 +230,17 @@ class ArticleFragment : Fragment() { rootView.progressBar.visibility = View.GONE } catch (e: Exception) { - // TODO: logs + ACRA.getErrorReporter().handleSilentException(e) } } else { try { openInBrowserAfterFailing(customTabsIntent) } catch (e: Exception) { - // TODO: logs + ACRA.getErrorReporter().handleSilentException(e) } } } catch (e: Exception) { - // TODO: logs + ACRA.getErrorReporter().handleSilentException(e) } } 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 157af47..363e6be 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 @@ -1,18 +1,20 @@ package apps.amine.bou.readerforselfoss.utils +import android.content.Context import android.text.format.DateUtils import apps.amine.bou.readerforselfoss.api.selfoss.Item +import org.acra.ACRA import java.text.ParseException import java.text.SimpleDateFormat import java.util.* -fun String.toTextDrawableString(): String { +fun String.toTextDrawableString(c: Context): String { val textDrawable = StringBuilder() for (s in this.split(" ".toRegex()).filter { !it.isEmpty() }.toTypedArray()) { try { textDrawable.append(s[0]) } catch (e: StringIndexOutOfBoundsException) { - // TODO: logs + ACRA.getErrorReporter().handleSilentException(e) } } return textDrawable.toString() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e9ec573..3edef03 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -157,4 +157,15 @@ This will mark all the items as read. Mark as read on swipe Don\'t mark articles as read when swiping. + The app does not collect any personal data. Every analytics tools were removed. Crash reports sending is now optional, as is the debug logging. Keep in mind that debugging and crash reports are essential for the app development (You can configure everything in Settings > Debug). + The app does not share any personal data about you. + Something went wrong. Please send the report to the developer. + You can add any helpful details in the comment bellow. + Contact email + Add an email so I can contact you about the crash reports you send. + Automatically send crash reports + Will send crash reports automatically + Will ask everytime when sending crash reports. + Crash reports + Debug logging (these will be sent without a dialog) diff --git a/app/src/main/res/xml/pref_debug.xml b/app/src/main/res/xml/pref_debug.xml index 1501d2c..46ffde5 100644 --- a/app/src/main/res/xml/pref_debug.xml +++ b/app/src/main/res/xml/pref_debug.xml @@ -1,27 +1,42 @@ - + + - + + + + + + + + -