Added login optional debug logs. (#61)

This commit is contained in:
Amine Bou 2017-08-04 08:30:21 +02:00 committed by GitHub
parent b44a200731
commit d768d2232b
16 changed files with 101 additions and 10 deletions

View File

@ -1,3 +1,7 @@
**1.5.2.02**
- Added optional login option.
**1.5.2.01** **1.5.2.01**
- New (Better) Icon ! - New (Better) Icon !

View File

@ -15,10 +15,7 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import android.widget.Button import android.widget.*
import android.widget.EditText
import android.widget.Switch
import android.widget.TextView
import com.google.firebase.analytics.FirebaseAnalytics import com.google.firebase.analytics.FirebaseAnalytics
import com.mikepenz.aboutlibraries.Libs 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.Config
import apps.amine.bou.readerforselfoss.utils.checkAndDisplayStoreApk import apps.amine.bou.readerforselfoss.utils.checkAndDisplayStoreApk
import apps.amine.bou.readerforselfoss.utils.isBaseUrlValid import apps.amine.bou.readerforselfoss.utils.isBaseUrlValid
import com.crashlytics.android.Crashlytics
import com.ftinc.scoop.Scoop import com.ftinc.scoop.Scoop
import io.fabric.sdk.android.Fabric
class LoginActivity : AppCompatActivity() { class LoginActivity : AppCompatActivity() {
@ -42,6 +41,7 @@ class LoginActivity : AppCompatActivity() {
private var isWithHTTPLogin = false private var isWithHTTPLogin = false
private lateinit var settings: SharedPreferences private lateinit var settings: SharedPreferences
private lateinit var editor: SharedPreferences.Editor
private lateinit var mFirebaseAnalytics: FirebaseAnalytics private lateinit var mFirebaseAnalytics: FirebaseAnalytics
private lateinit var mUrlView: EditText private lateinit var mUrlView: EditText
private lateinit var mLoginView: TextView private lateinit var mLoginView: TextView
@ -50,6 +50,7 @@ class LoginActivity : AppCompatActivity() {
private lateinit var mPasswordView: EditText private lateinit var mPasswordView: EditText
private lateinit var mHTTPPasswordView: EditText private lateinit var mHTTPPasswordView: EditText
private lateinit var mLoginFormView: View private lateinit var mLoginFormView: View
private var logErrors: Boolean = false
@ -74,6 +75,10 @@ class LoginActivity : AppCompatActivity() {
settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE) settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
logErrors = settings.getBoolean("loging_debug", false)
editor = settings.edit()
if (settings.getString("url", "").isNotEmpty()) { if (settings.getString("url", "").isNotEmpty()) {
goToMain() goToMain()
} else { } else {
@ -186,7 +191,6 @@ class LoginActivity : AppCompatActivity() {
} else { } else {
showProgress(true) showProgress(true)
val editor = settings.edit()
editor.putString("url", url) editor.putString("url", url)
editor.putString("login", login) editor.putString("login", login)
editor.putString("httpUserName", httpLogin) editor.putString("httpUserName", httpLogin)
@ -196,7 +200,7 @@ class LoginActivity : AppCompatActivity() {
val api = SelfossApi(this, this@LoginActivity) val api = SelfossApi(this, this@LoginActivity)
api.login().enqueue(object : Callback<SuccessResponse> { api.login().enqueue(object : Callback<SuccessResponse> {
private fun preferenceError() { private fun preferenceError(t: Throwable) {
editor.remove("url") editor.remove("url")
editor.remove("login") editor.remove("login")
editor.remove("httpUserName") editor.remove("httpUserName")
@ -208,6 +212,11 @@ class LoginActivity : AppCompatActivity() {
mPasswordView.error = getString(R.string.wrong_infos) mPasswordView.error = getString(R.string.wrong_infos)
mHTTPLoginView.error = getString(R.string.wrong_infos) mHTTPLoginView.error = getString(R.string.wrong_infos)
mHTTPPasswordView.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) showProgress(false)
} }
@ -216,12 +225,12 @@ class LoginActivity : AppCompatActivity() {
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, Bundle()) mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, Bundle())
goToMain() goToMain()
} else { } else {
preferenceError() preferenceError(Exception("No response body..."))
} }
} }
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) { override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
preferenceError() preferenceError(t)
} }
}) })
} }
@ -260,6 +269,7 @@ class LoginActivity : AppCompatActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.login_menu, menu) menuInflater.inflate(R.menu.login_menu, menu)
menu.findItem(R.id.loging_debug).isChecked = logErrors
return true return true
} }
@ -273,6 +283,14 @@ class LoginActivity : AppCompatActivity() {
.start(this) .start(this)
return true 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) else -> return super.onOptionsItemSelected(item)
} }
} }

View File

@ -20,8 +20,7 @@ import java.io.IOException
class MyApp : MultiDexApplication() { class MyApp : MultiDexApplication() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
if (!BuildConfig.DEBUG) Fabric.with(this, Crashlytics())
Fabric.with(this, Crashlytics())
initAmplify() initAmplify()

View File

@ -119,6 +119,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
protected boolean isValidFragment(String fragmentName) { protected boolean isValidFragment(String fragmentName) {
return PreferenceFragment.class.getName().equals(fragmentName) return PreferenceFragment.class.getName().equals(fragmentName)
|| GeneralPreferenceFragment.class.getName().equals(fragmentName) || GeneralPreferenceFragment.class.getName().equals(fragmentName)
|| DebugPreferenceFragment.class.getName().equals(fragmentName)
|| LinksPreferenceFragment.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 * This fragment shows general preferences only. It is used when the
* activity is showing a two-pane settings UI. * activity is showing a two-pane settings UI.

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 B

View File

@ -0,0 +1,11 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>

View File

@ -2,6 +2,14 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/loging_debug"
android:checkable="true"
android:checked="false"
android:icon="@drawable/ic_bug_report"
android:title="@string/login_menu_debug"
app:showAsAction="never" />
<item android:id="@+id/about" <item android:id="@+id/about"
android:title="@string/action_about" android:title="@string/action_about"
android:orderInCategory="102" android:orderInCategory="102"

View File

@ -131,4 +131,9 @@
<string name="blue_amber_dark_theme">Bleu/Ambre/Foncé</string> <string name="blue_amber_dark_theme">Bleu/Ambre/Foncé</string>
<string name="indigo_pink_dark_theme">Indigo/Rose/Foncé</string> <string name="indigo_pink_dark_theme">Indigo/Rose/Foncé</string>
<string name="red_teal_dark_theme">Rouge/Sarcelle/Foncé</string> <string name="red_teal_dark_theme">Rouge/Sarcelle/Foncé</string>
<string name="pref_header_debug">Debug</string>
<string name="login_debug_title">Activez pour loguer toutes les erreurs de conexion</string>
<string name="login_debug_on">Toutes les erreurs de connexion vont être loguées</string>
<string name="login_debug_off">Aucune erreur de connexion ne sera loguée</string>
<string name="login_menu_debug">Debug</string>
</resources> </resources>

View File

@ -131,4 +131,9 @@
<string name="blue_amber_dark_theme">Blue/Amber/Dark</string> <string name="blue_amber_dark_theme">Blue/Amber/Dark</string>
<string name="indigo_pink_dark_theme">Indigo/Pink/Dark</string> <string name="indigo_pink_dark_theme">Indigo/Pink/Dark</string>
<string name="red_teal_dark_theme">Red/Teal/Dark</string> <string name="red_teal_dark_theme">Red/Teal/Dark</string>
<string name="pref_header_debug">Debug</string>
<string name="login_debug_title">Activate to log login errors</string>
<string name="login_debug_on">Any error on the login page will be logged</string>
<string name="login_debug_off">No log on the login page</string>
<string name="login_menu_debug">Debug</string>
</resources> </resources>

View File

@ -133,4 +133,9 @@
<string name="blue_amber_dark_theme">Blue/Amber/Dark</string> <string name="blue_amber_dark_theme">Blue/Amber/Dark</string>
<string name="indigo_pink_dark_theme">Indigo/Pink/Dark</string> <string name="indigo_pink_dark_theme">Indigo/Pink/Dark</string>
<string name="red_teal_dark_theme">Red/Teal/Dark</string> <string name="red_teal_dark_theme">Red/Teal/Dark</string>
<string name="pref_header_debug">Debug</string>
<string name="login_debug_title">Activate to log login errors</string>
<string name="login_debug_on">Any error on the login page will be logged</string>
<string name="login_debug_off">No log on the login page</string>
<string name="login_menu_debug">Debug</string>
</resources> </resources>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
android:defaultValue="false"
android:key="loging_debug"
android:summaryOff="@string/login_debug_off"
android:summaryOn="@string/login_debug_on"
android:title="@string/login_debug_title" />
</PreferenceScreen>

View File

@ -5,6 +5,11 @@
android:icon="@drawable/ic_settings_black_24dp" android:icon="@drawable/ic_settings_black_24dp"
android:title="@string/pref_header_general"/> android:title="@string/pref_header_general"/>
<header
android:fragment="apps.amine.bou.readerforselfoss.settings.SettingsActivity$DebugPreferenceFragment"
android:icon="@drawable/ic_bug_report"
android:title="@string/pref_header_debug"/>
<header <header
android:id="@+id/theme_change" android:id="@+id/theme_change"
android:icon="@drawable/ic_color_lens_black_24dp" android:icon="@drawable/ic_color_lens_black_24dp"