From 499241d5e2f5a99d6d20d11f972a2fb65c61a22b Mon Sep 17 00:00:00 2001 From: oogee Date: Wed, 14 Nov 2018 22:44:00 +0200 Subject: [PATCH] handle OTHER_ERROR on main activity tasks --- .../activities/main/forum/ForumFragment.java | 3 ++ .../main/recent/RecentFragment.java | 3 ++ .../main/unread/UnreadFragment.java | 3 ++ .../activities/topic/TopicActivity.java | 2 +- .../gr/thmmy/mthmmy/utils/CrashReporter.java | 34 +++++++++++++++++++ .../gr/thmmy/mthmmy/utils/NetworkTask.java | 9 +++++ .../mthmmy/utils/parsing/ParseHelpers.java | 22 ++++++++++++ 7 files changed, 75 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java index 782ffb71..d2ddcfb5 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java @@ -176,6 +176,9 @@ public class ForumFragment extends BaseFragment { forumAdapter.notifyParentDataSetChanged(false); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Network error", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Unexpected error," + + " please contact the developers with the details", Toast.LENGTH_LONG).show(); } progressBar.setVisibility(ProgressBar.INVISIBLE); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java index 01f84261..c344213b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java @@ -148,6 +148,9 @@ public class RecentFragment extends BaseFragment { recentAdapter.notifyDataSetChanged(); } else if (resultCode == NetworkResultCodes.NETWORK_ERROR) { Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Network error", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Unexpected error," + + " please contact the developers with the details", Toast.LENGTH_LONG).show(); } progressBar.setVisibility(ProgressBar.INVISIBLE); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java index 76b595dd..7f5ed74a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java @@ -180,6 +180,9 @@ public class UnreadFragment extends BaseFragment { swipeRefreshLayout.setRefreshing(false); if (resultCode == NetworkResultCodes.NETWORK_ERROR) Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Network error", Toast.LENGTH_SHORT).show(); + else + Toast.makeText(BaseApplication.getInstance().getApplicationContext(), "Unexpected error," + + " please contact the developers with the details", Toast.LENGTH_LONG).show(); } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index 6f1935b9..ddf48d9f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -663,7 +663,7 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo progressBar.setVisibility(ProgressBar.GONE); switch (resultCode) { case SUCCESS: - Timber.i("Successfully loaded topic with URL %s", viewModel.getTopicUrl()); + Timber.i("Successfully loaded a topic"); paginationEnabled(true); break; case NETWORK_ERROR: diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java b/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java index 81b06769..8f16fdc4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java @@ -13,6 +13,40 @@ public class CrashReporter { private CrashReporter() {} + public static void reportForumInfo(Document document) { + ParseHelpers.Theme theme = ParseHelpers.parseTheme(document); + ParseHelpers.Language language = ParseHelpers.Language.getLanguage(document); + String themeKey = "forum theme", themeValue = null; + String languageKey = "forum language", languageValue = null; + switch (theme) { + case SCRIBBLES2: + themeValue = "Scribbles2"; + break; + case SMF_DEFAULT: + themeValue = "SMF Default Theme"; + break; + case SMFONE_BLUE: + themeValue = "SMFone_Blue"; + break; + case HELIOS_MULTI: + themeValue = "Helios_Multi"; + break; + case THEME_UNKNOWN: + themeValue = "Unknown theme"; + break; + } + switch (language) { + case GREEK: + languageValue = "Greek"; + break; + case ENGLISH: + languageValue = "English"; + break; + } + Crashlytics.setString(themeKey, themeValue); + Crashlytics.setString(languageKey, languageValue); + } + public static void reportDocument(Document document, String key) { String documentString = document.toString(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java index c61dbb72..524a4033 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java @@ -1,9 +1,14 @@ package gr.thmmy.mthmmy.utils; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import java.io.IOException; +import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.utils.parsing.ParseException; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; @@ -54,6 +59,10 @@ public abstract class NetworkTask extends ExternalAsyncTask return new Parcel<>(resultCode, data); } catch (ParseException pe) { Timber.e(pe); + SharedPreferences settingsPreferences = PreferenceManager.getDefaultSharedPreferences(BaseApplication.getInstance()); + if (settingsPreferences.getBoolean(BaseApplication.getInstance() + .getString(R.string.pref_privacy_crashlytics_enable_key), false)) + CrashReporter.reportForumInfo(Jsoup.parse(responseBodyString)); return new Parcel<>(NetworkResultCodes.PARSE_ERROR, null); } catch (Exception e) { Timber.e(e); diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java index fe5d2ac3..3d694da6 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java @@ -92,6 +92,28 @@ public class ParseHelpers { } } + public enum Theme { + SCRIBBLES2, + SMF_DEFAULT, + SMFONE_BLUE, + HELIOS_MULTI, + THEME_UNKNOWN + } + + public static Theme parseTheme(Document page) { + Element stylesheet = page.select("link[rel=stylesheet]").first(); + if (stylesheet.attr("href").contains("scribbles2")) + return Theme.SCRIBBLES2; + else if (stylesheet.attr("href").contains("helios_multi")) + return Theme.HELIOS_MULTI; + else if (stylesheet.attr("href").contains("smfone")) + return Theme.SMFONE_BLUE; + else if (stylesheet.attr("href").contains("default")) + return Theme.SMF_DEFAULT; + else + return Theme.THEME_UNKNOWN; + } + /** * An enum describing the state of a forum page by defining the types:
    *
  • {@link #UNAUTHORIZED_OR_MISSING}