aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorCamil Staps2015-06-10 15:28:24 +0200
committerCamil Staps2015-06-10 15:28:24 +0200
commitbdcf3dc6ef94235cc2c10f99f110ddd5aec9674f (patch)
treed2a72908afd06ddfcb98e18dedf8e6cfa6486c68 /app
parentLess space inbetween cards (diff)
Don't repeat error messages
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/org/rssin/android/Frontend.java27
1 files changed, 24 insertions, 3 deletions
diff --git a/app/src/main/java/org/rssin/android/Frontend.java b/app/src/main/java/org/rssin/android/Frontend.java
index 8730f25..4bafd9a 100644
--- a/app/src/main/java/org/rssin/android/Frontend.java
+++ b/app/src/main/java/org/rssin/android/Frontend.java
@@ -14,6 +14,15 @@ class Frontend {
public static final int WARNING_TIMEOUT = 5000;
public static final int INFO_TIMEOUT = 5000;
+ private static String last_error = "";
+ private static long disable_error_till = 0;
+
+ private static String last_warning = "";
+ private static long disable_warning_till = 0;
+
+ private static String last_info = "";
+ private static long disable_info_till = 0;
+
/**
* Show an error
* @param context The context to show in
@@ -22,7 +31,11 @@ class Frontend {
* @param timeout The time the error should be shown, in ms (since we're using Toast, not accurate)
*/
public static void error(Context context, String message, Exception e, int timeout) {
- Toast.makeText(context, message, timeout > 3000 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
+ if (!message.equals(last_error) || disable_error_till < System.currentTimeMillis()) {
+ Toast.makeText(context, message, timeout > 3000 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
+ last_error = message;
+ disable_error_till = System.currentTimeMillis() + timeout;
+ }
Log.e("FRONTEND", message, e);
}
@@ -70,7 +83,11 @@ class Frontend {
* @param timeout The time the warning should be shown, in ms (since we're using Toast, not accurate)
*/
public static void warning(Context context, String message, Exception e, int timeout) {
- Toast.makeText(context, message, timeout > 3000 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
+ if (!message.equals(last_warning) || disable_warning_till < System.currentTimeMillis()) {
+ Toast.makeText(context, message, timeout > 3000 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
+ last_warning = message;
+ disable_warning_till = System.currentTimeMillis() + timeout;
+ }
Log.w("FRONTEND", message, e);
}
@@ -117,7 +134,11 @@ class Frontend {
* @param timeout The time the info message should be shown, in ms (since we're using Toast, not accurate)
*/
public static void info(Context context, String message, Exception e, int timeout) {
- Toast.makeText(context, message, timeout > 3000 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
+ if (!message.equals(last_info) || disable_info_till < System.currentTimeMillis()) {
+ Toast.makeText(context, message, timeout > 3000 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
+ last_info = message;
+ disable_info_till = System.currentTimeMillis() + timeout;
+ }
Log.i("FRONTEND", message, e);
}