Browse Source

handle OTHER_ERROR on main activity tasks

pull/61/merge
oogee 6 years ago
parent
commit
499241d5e2
  1. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/main/forum/ForumFragment.java
  2. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/main/recent/RecentFragment.java
  3. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java
  4. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  5. 34
      app/src/main/java/gr/thmmy/mthmmy/utils/CrashReporter.java
  6. 9
      app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java
  7. 22
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java

3
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);

3
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);

3
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();
}
}

2
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:

34
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();

9
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<T> extends ExternalAsyncTask<String, Parcel<T>
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);

22
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:<ul>
* <li>{@link #UNAUTHORIZED_OR_MISSING}</li>

Loading…
Cancel
Save