From faebfc238c2a13f03f3992630cf3ecae8856fbab Mon Sep 17 00:00:00 2001 From: Amine Date: Wed, 30 Aug 2017 22:11:29 +0200 Subject: [PATCH] Closes #69. --- .github/CONTRIBUTING.md | 3 ++- CHANGELOG.md | 8 ++++++ .../bou/readerforselfoss/HomeActivity.kt | 8 ++++-- .../bou/readerforselfoss/LoginActivity.kt | 3 +++ .../apps/amine/bou/readerforselfoss/MyApp.kt | 12 +++++++++ .../adapters/ItemCardAdapter.kt | 6 ++++- .../adapters/ItemListAdapter.kt | 5 +++- .../settings/SettingsActivity.java | 25 +++++++++++++++++++ app/src/main/res/values-fr/strings.xml | 2 ++ app/src/main/res/values-nl/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_debug.xml | 5 ++++ 12 files changed, 76 insertions(+), 5 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 74980e0..e43235d 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -22,7 +22,8 @@ Always check if the web version of your instance is working. ### Bug reports/Feature request * Always search before reporting an issue or asking for a feature to avoid duplicates. -* Include every usefull details (app version, phone model, Android version and screenshots when possible) +* Include your unique user id. It's displayed on the debug settings page. (You can tap it, it'll be copied to your clipboard) +* Include every other useful details (app version, phone model, Android version and screenshots when possible). * Avoid bumping non-fatal issues, or feature requests. I'll try to fix them as soon as possible, and try to prioritize the requests. (You may wan to use the [reactions](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments) for that) ### Pull requests diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f4fef3..380b13a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +**1.5.2.11** + +- Added a random unique identifier to be used in the logs. + +**1.5.2.08/09/10** + +- Added settable logs for reading articles problems. + **1.5.2.07** - Added the ability to choose the number of items loaded (the maximum value is 200 and is imposed by the selfoss api) 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 7564828..d405cff 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -92,6 +92,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { private var maybeTagFilter: Tag? = null private var maybeSourceFilter: Sources? = null private var maybeSearchFilter: String? = null + private var userIdentifier: String = "" private lateinit var emptyText: TextView private lateinit var recyclerView: RecyclerView @@ -287,6 +288,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { displayAllCount = sharedPref.getBoolean("display_other_count", false) fullHeightCards = sharedPref.getBoolean("full_height_cards", false) itemsNumber = sharedPref.getString("prefer_api_items_number", "200").toInt() + userIdentifier = sharedPref.getString("unique_id", "") } private fun handleDrawer() { @@ -644,7 +646,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { articleViewer, fullHeightCards, appColors, - debugReadingItems) + debugReadingItems, + userIdentifier) } else { mAdapter = ItemListAdapter( @@ -655,7 +658,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { clickBehavior, internalBrowser, articleViewer, - debugReadingItems) + debugReadingItems, + userIdentifier) } recyclerView.adapter = mAdapter mAdapter.notifyDataSetChanged() 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 0e99549..627d921 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt @@ -51,6 +51,7 @@ class LoginActivity : AppCompatActivity() { private lateinit var mPasswordView: EditText private lateinit var mHTTPPasswordView: EditText private lateinit var mLoginFormView: View + private lateinit var userIdentifier: String private var logErrors: Boolean = false @@ -76,6 +77,7 @@ class LoginActivity : AppCompatActivity() { settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE) + userIdentifier = settings.getString("unique_id", "") logErrors = settings.getBoolean("loging_debug", false) editor = settings.edit() @@ -224,6 +226,7 @@ class LoginActivity : AppCompatActivity() { mHTTPLoginView.error = getString(R.string.wrong_infos) mHTTPPasswordView.error = getString(R.string.wrong_infos) if (logErrors) { + Crashlytics.setUserIdentifier(userIdentifier) Crashlytics.log(100, "LOGIN_DEBUG_ERRROR", t.message) Crashlytics.logException(t) Toast.makeText(this@LoginActivity, t.message, Toast.LENGTH_LONG).show() 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 bcd4a52..df83ce2 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt @@ -6,6 +6,7 @@ import android.net.Uri import android.preference.PreferenceManager import android.support.multidex.MultiDexApplication import android.widget.ImageView +import apps.amine.bou.readerforselfoss.utils.Config import com.anupcowkur.reservoir.Reservoir import com.bumptech.glide.Glide import com.crashlytics.android.Crashlytics @@ -15,9 +16,13 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader import com.mikepenz.materialdrawer.util.DrawerImageLoader import io.fabric.sdk.android.Fabric import java.io.IOException +import java.util.UUID.randomUUID + + class MyApp : MultiDexApplication() { + override fun onCreate() { super.onCreate() Fabric.with(this, Crashlytics()) @@ -26,6 +31,13 @@ class MyApp : MultiDexApplication() { initCache() + val prefs = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE) + if (prefs.getString("unique_id", "").isEmpty()) { + val editor = prefs.edit() + editor.putString("unique_id", randomUUID().toString()) + editor.apply() + } + initDrawerImageLoader() initTheme() 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 3c1df25..68c4f25 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 @@ -43,7 +43,8 @@ class ItemCardAdapter(private val app: Activity, private val articleViewer: Boolean, private val fullHeightCards: Boolean, private val appColors: AppColors, - val debugReadingItems: Boolean) : RecyclerView.Adapter() { + val debugReadingItems: Boolean, + val userIdentifier: String) : RecyclerView.Adapter() { private val c: Context = app.baseContext private val generator: ColorGenerator = ColorGenerator.MATERIAL @@ -135,8 +136,10 @@ class ItemCardAdapter(private val app: Activity, "response errorBody: ${response.errorBody()?.string()} " + "body success: ${response.body()?.success} " + "body isSuccess: ${response.body()?.isSuccess}" + Crashlytics.setUserIdentifier(userIdentifier) Crashlytics.log(100, "READ_DEBUG_SUCCESS", message) Crashlytics.logException(Exception("Was success, but did it work ?")) + Toast.makeText(c, message, Toast.LENGTH_LONG).show() } doUnmark(i, position) @@ -144,6 +147,7 @@ class ItemCardAdapter(private val app: Activity, override fun onFailure(call: Call, t: Throwable) { if (debugReadingItems) { + Crashlytics.setUserIdentifier(userIdentifier) Crashlytics.log(100, "READ_DEBUG_ERROR", t.message) Crashlytics.logException(t) Toast.makeText(c, t.message, Toast.LENGTH_LONG).show() 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 df50f9a..fff5628 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 @@ -40,7 +40,8 @@ class ItemListAdapter(private val app: Activity, private val clickBehavior: Boolean, private val internalBrowser: Boolean, private val articleViewer: Boolean, - val debugReadingItems: Boolean) : RecyclerView.Adapter() { + val debugReadingItems: Boolean, + val userIdentifier: String) : RecyclerView.Adapter() { private val generator: ColorGenerator = ColorGenerator.MATERIAL private val c: Context = app.baseContext private val bars: ArrayList = ArrayList(Collections.nCopies(items.size + 1, false)) @@ -144,6 +145,7 @@ class ItemListAdapter(private val app: Activity, "response errorBody: ${response.errorBody()?.string()} " + "body success: ${response.body()?.success} " + "body isSuccess: ${response.body()?.isSuccess}" + Crashlytics.setUserIdentifier(userIdentifier) Crashlytics.log(100, "READ_DEBUG_SUCCESS", message) Crashlytics.logException(Exception("Was success, but did it work ?")) Toast.makeText(c, message, Toast.LENGTH_LONG).show() @@ -154,6 +156,7 @@ class ItemListAdapter(private val app: Activity, override fun onFailure(call: Call, t: Throwable) { if (debugReadingItems) { + Crashlytics.setUserIdentifier(userIdentifier) Crashlytics.log(100, "READ_DEBUG_ERROR", t.message) Crashlytics.logException(t) Toast.makeText(c, t.message, Toast.LENGTH_LONG).show() diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java index b797be4..07df4d4 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/settings/SettingsActivity.java @@ -2,8 +2,11 @@ package apps.amine.bou.readerforselfoss.settings; import android.annotation.TargetApi; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.net.Uri; import android.os.Build; @@ -11,6 +14,7 @@ import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceActivity; import android.preference.SwitchPreference; import android.support.v7.app.ActionBar; @@ -19,10 +23,12 @@ import android.preference.PreferenceManager; import android.text.InputFilter; import android.text.Spanned; import android.view.MenuItem; +import android.widget.Toast; import java.util.List; import apps.amine.bou.readerforselfoss.R; +import apps.amine.bou.readerforselfoss.utils.Config; import com.ftinc.scoop.ui.ScoopSettingsActivity; @@ -184,6 +190,25 @@ public class SettingsActivity extends AppCompatPreferenceActivity { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_debug); setHasOptionsMenu(true); + + SharedPreferences pref = getActivity().getSharedPreferences(Config.Companion.getSettingsName(), Context.MODE_PRIVATE); + final String id = pref.getString("unique_id", "..."); + + final Preference identifier = findPreference("debug_identifier"); + final ClipboardManager clipboard = (ClipboardManager) + getActivity().getSystemService(Context.CLIPBOARD_SERVICE); + + identifier.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + ClipData clip = ClipData.newPlainText("Selfoss unique id", id); + clipboard.setPrimaryClip(clip); + + Toast.makeText(getActivity(), R.string.unique_id_to_clipboard, Toast.LENGTH_LONG).show(); + return true; + } + }); + identifier.setTitle(id); } @Override diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 6e6c052..6ab0ece 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -143,4 +143,6 @@ Des articles lus marqués comme non lus ? Les appels API vont être logués lorsequ\'un article est marqué comme lu Aucun log quand un article est marqué comme lu + Identifiant de debug + Texte copié \ No newline at end of file diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 259a049..56fba18 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -143,4 +143,6 @@ Read articles appearing as unread ? Api calls will be logged when marking an article as read No log when marking an item as read + Debug identifier + Identifier copied to your clipboard \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0630839..cc5b4c6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -145,4 +145,6 @@ Read articles appearing as unread ? No log when marking an item as read Api calls will be logged when marking an article as read + Debug identifier + Identifier copied to your clipboard \ No newline at end of file diff --git a/app/src/main/res/xml/pref_debug.xml b/app/src/main/res/xml/pref_debug.xml index 43291d9..88dd264 100644 --- a/app/src/main/res/xml/pref_debug.xml +++ b/app/src/main/res/xml/pref_debug.xml @@ -15,4 +15,9 @@ android:summaryOff="@string/read_debug_off" android:summaryOn="@string/read_debug_on" android:title="@string/read_debug_title" /> + + \ No newline at end of file