From d768d2232bacd6f11092ed72092ebfc9a02f16aa Mon Sep 17 00:00:00 2001 From: Amine Bou Date: Fri, 4 Aug 2017 08:30:21 +0200 Subject: [PATCH] Added login optional debug logs. (#61) --- CHANGELOG.md | 4 +++ .../bou/readerforselfoss/LoginActivity.kt | 34 +++++++++++++----- .../apps/amine/bou/readerforselfoss/MyApp.kt | 3 +- .../settings/SettingsActivity.java | 21 +++++++++++ .../main/res/drawable-hdpi/ic_bug_report.png | Bin 0 -> 271 bytes .../main/res/drawable-mdpi/ic_bug_report.png | Bin 0 -> 212 bytes .../main/res/drawable-xhdpi/ic_bug_report.png | Bin 0 -> 312 bytes .../res/drawable-xxhdpi/ic_bug_report.png | Bin 0 -> 466 bytes .../res/drawable-xxxhdpi/ic_bug_report.png | Bin 0 -> 573 bytes app/src/main/res/layout/switch_item.xml | 11 ++++++ app/src/main/res/menu/login_menu.xml | 8 +++++ app/src/main/res/values-fr/strings.xml | 5 +++ app/src/main/res/values-nl/strings.xml | 5 +++ app/src/main/res/values/strings.xml | 5 +++ app/src/main/res/xml/pref_debug.xml | 10 ++++++ app/src/main/res/xml/pref_headers.xml | 5 +++ 16 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_bug_report.png create mode 100644 app/src/main/res/drawable-mdpi/ic_bug_report.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_bug_report.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_bug_report.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_bug_report.png create mode 100644 app/src/main/res/layout/switch_item.xml create mode 100644 app/src/main/res/xml/pref_debug.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 58f13e2..a3bfc25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +**1.5.2.02** + +- Added optional login option. + **1.5.2.01** - New (Better) Icon ! 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 4614879..ace8d29 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/LoginActivity.kt @@ -15,10 +15,7 @@ import android.view.Menu import android.view.MenuItem import android.view.View import android.view.inputmethod.EditorInfo -import android.widget.Button -import android.widget.EditText -import android.widget.Switch -import android.widget.TextView +import android.widget.* import com.google.firebase.analytics.FirebaseAnalytics import com.mikepenz.aboutlibraries.Libs @@ -32,7 +29,9 @@ import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse import apps.amine.bou.readerforselfoss.utils.Config import apps.amine.bou.readerforselfoss.utils.checkAndDisplayStoreApk import apps.amine.bou.readerforselfoss.utils.isBaseUrlValid +import com.crashlytics.android.Crashlytics import com.ftinc.scoop.Scoop +import io.fabric.sdk.android.Fabric class LoginActivity : AppCompatActivity() { @@ -42,6 +41,7 @@ class LoginActivity : AppCompatActivity() { private var isWithHTTPLogin = false private lateinit var settings: SharedPreferences + private lateinit var editor: SharedPreferences.Editor private lateinit var mFirebaseAnalytics: FirebaseAnalytics private lateinit var mUrlView: EditText private lateinit var mLoginView: TextView @@ -50,6 +50,7 @@ class LoginActivity : AppCompatActivity() { private lateinit var mPasswordView: EditText private lateinit var mHTTPPasswordView: EditText private lateinit var mLoginFormView: View + private var logErrors: Boolean = false @@ -74,6 +75,10 @@ class LoginActivity : AppCompatActivity() { settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE) + logErrors = settings.getBoolean("loging_debug", false) + + editor = settings.edit() + if (settings.getString("url", "").isNotEmpty()) { goToMain() } else { @@ -186,7 +191,6 @@ class LoginActivity : AppCompatActivity() { } else { showProgress(true) - val editor = settings.edit() editor.putString("url", url) editor.putString("login", login) editor.putString("httpUserName", httpLogin) @@ -196,7 +200,7 @@ class LoginActivity : AppCompatActivity() { val api = SelfossApi(this, this@LoginActivity) api.login().enqueue(object : Callback { - private fun preferenceError() { + private fun preferenceError(t: Throwable) { editor.remove("url") editor.remove("login") editor.remove("httpUserName") @@ -208,6 +212,11 @@ class LoginActivity : AppCompatActivity() { mPasswordView.error = getString(R.string.wrong_infos) mHTTPLoginView.error = getString(R.string.wrong_infos) mHTTPPasswordView.error = getString(R.string.wrong_infos) + if (logErrors) { + Crashlytics.log(100, "LOGIN_DEBUG_ERRROR", t.message) + Crashlytics.logException(t) + Toast.makeText(this@LoginActivity, t.message, Toast.LENGTH_LONG).show() + } showProgress(false) } @@ -216,12 +225,12 @@ class LoginActivity : AppCompatActivity() { mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, Bundle()) goToMain() } else { - preferenceError() + preferenceError(Exception("No response body...")) } } override fun onFailure(call: Call, t: Throwable) { - preferenceError() + preferenceError(t) } }) } @@ -260,6 +269,7 @@ class LoginActivity : AppCompatActivity() { override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.login_menu, menu) + menu.findItem(R.id.loging_debug).isChecked = logErrors return true } @@ -273,6 +283,14 @@ class LoginActivity : AppCompatActivity() { .start(this) return true } + R.id.loging_debug -> { + val newState = !item.isChecked + item.isChecked = newState + logErrors = newState + editor.putBoolean("loging_debug", newState) + editor.apply() + return true + } else -> return super.onOptionsItemSelected(item) } } 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 2d1fc51..bcd4a52 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/MyApp.kt @@ -20,8 +20,7 @@ import java.io.IOException class MyApp : MultiDexApplication() { override fun onCreate() { super.onCreate() - if (!BuildConfig.DEBUG) - Fabric.with(this, Crashlytics()) + Fabric.with(this, Crashlytics()) initAmplify() 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 6780bcb..85280c0 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 @@ -119,6 +119,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { protected boolean isValidFragment(String fragmentName) { return PreferenceFragment.class.getName().equals(fragmentName) || GeneralPreferenceFragment.class.getName().equals(fragmentName) + || DebugPreferenceFragment.class.getName().equals(fragmentName) || LinksPreferenceFragment.class.getName().equals(fragmentName); } @@ -157,6 +158,26 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } } + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + public static class DebugPreferenceFragment extends PreferenceFragment { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.pref_debug); + setHasOptionsMenu(true); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == android.R.id.home) { + getActivity().finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + } + /** * This fragment shows general preferences only. It is used when the * activity is showing a two-pane settings UI. diff --git a/app/src/main/res/drawable-hdpi/ic_bug_report.png b/app/src/main/res/drawable-hdpi/ic_bug_report.png new file mode 100644 index 0000000000000000000000000000000000000000..c4e1b0daa3f5702a5deae2b5125bf699797cf4d0 GIT binary patch literal 271 zcmV+q0r38bP)xQY>I#D6ec zz>vsL1B3}c7DQwQ7BAy9YA#eGDx5}|F$@gs42!WEG?#&u6l0heHeode1lIy(i3U|T zjRC>HTfBJpU!v8FVz>6ymwwu*dd?X$RBP|LH$Ye3<=Ee8Qje1&xj@``IkpUOS|6 zRLpc_n_tA&wp!zq;|C#T>$0Q&IUP=!HXQIb@#J`~ooD~&_^OBh9ey>cs84*8`Rhj` z^PDdM4=dTsYF2uR&A1aV)m!kC(;FUEp5>DJm>+7k+5B0?FT}u5X1n#&Ht&`@KxZ;| My85}Sb4q9e0Bi?ToB#j- literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_bug_report.png b/app/src/main/res/drawable-xhdpi/ic_bug_report.png new file mode 100644 index 0000000000000000000000000000000000000000..c00d297f7c3a155d0e1b716ac2009dbe507e72fb GIT binary patch literal 312 zcmV-80muG{P)gVy?r**HT-!WRf{{IP-t6j}x|-775p(BRyVS^4CFJCv>;~0000< KMNUMnLSTZatb%(0 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_bug_report.png b/app/src/main/res/drawable-xxhdpi/ic_bug_report.png new file mode 100644 index 0000000000000000000000000000000000000000..18b0024350c7e39dc8452e26309756d13e60cbeb GIT binary patch literal 466 zcmV;@0WJQCP)S6b0aeLL0@6P!wH=Zz77|!k?YsE9l$kMpq&zf>;Exw7P9vs0gWOLGTF#U36Kh zi8Ic^wx%XCnLAdw=R%=y>3lSk$uI#p91e$*F)Jt{m#Q<56D-nmnuu_gf|N&DbT(;8 ziX*Ee22AEepQI&vj;!(zq%V#lEz^LCZG*@C(!)S`0i_aYtX9| z(6c>IXa)3U4-{DeMGT?^@jApH2DyBe@jCS9K<`#St$)1z=!*>+uR{!CkjrP8%zTEy zL(EW|5N#WSHmMGTuZ%c8-QjQnb#2ZaMk&u>3!49uPs>p+SJKa=Ef**G>W)jkboZEr z!wg~#mpw66tYQGakZEk-05!ab%~wl&2H3|sroiEFI2?QV00_inBspRroB#j-07*qo IM6N<$f?qbwod5s; literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_bug_report.png b/app/src/main/res/drawable-xxxhdpi/ic_bug_report.png new file mode 100644 index 0000000000000000000000000000000000000000..c2d6679197436a40d00268b8d6e1407954358ddb GIT binary patch literal 573 zcmV-D0>b@?P)3_OE&VM7OOZ-&0j2C&U?GB?4GEEkL=$d;x)=+^nnop-s?lrEc372;GenvW z9n+a}<{a`qU(z&9PWn9knaODfAcPP?2qD4gK^BQXE0Z`wmwx>mY?K2eBvBPBuh6Yu z-(oz$lK+}5UHZ!*U;W0ru&6_SOnicENmE5U zYW+^!Nz->Gk65$;hf?*O*;l1%YaRwLfB_6(fZhN%=OLfad-bXMb8ty%KtX+gr8MA4 zeL!7lz^nQITWNsJ00tNrz%wxe7{CAqa6iB^F#{Ozk2W-aeoOhNG~ix+K=!Zwtim%f z0~o*n25>*{owRh(y=ecbk0CEr{|X&ZUo82fZ+yA*>;T3lvcn$M~AKE#e% + + + diff --git a/app/src/main/res/menu/login_menu.xml b/app/src/main/res/menu/login_menu.xml index 8ce2e40..4529433 100644 --- a/app/src/main/res/menu/login_menu.xml +++ b/app/src/main/res/menu/login_menu.xml @@ -2,6 +2,14 @@ + + Bleu/Ambre/Foncé Indigo/Rose/Foncé Rouge/Sarcelle/Foncé + Debug + Activez pour loguer toutes les erreurs de conexion + Toutes les erreurs de connexion vont être loguées + Aucune erreur de connexion ne sera loguée + Debug \ 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 7d010c0..faebaee 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -131,4 +131,9 @@ Blue/Amber/Dark Indigo/Pink/Dark Red/Teal/Dark + Debug + Activate to log login errors + Any error on the login page will be logged + No log on the login page + Debug \ 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 3531a45..3d95ce7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -133,4 +133,9 @@ Blue/Amber/Dark Indigo/Pink/Dark Red/Teal/Dark + Debug + Activate to log login errors + Any error on the login page will be logged + No log on the login page + Debug \ 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 new file mode 100644 index 0000000..aede6d3 --- /dev/null +++ b/app/src/main/res/xml/pref_debug.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_headers.xml b/app/src/main/res/xml/pref_headers.xml index 603ed88..3bcc108 100644 --- a/app/src/main/res/xml/pref_headers.xml +++ b/app/src/main/res/xml/pref_headers.xml @@ -5,6 +5,11 @@ android:icon="@drawable/ic_settings_black_24dp" android:title="@string/pref_header_general"/> +
+