From 56cee50cab348af98b7014acab60bf800d030e57 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Mon, 17 Nov 2014 00:19:50 +0100 Subject: [PATCH] Remove permanent widget current data when error --- .../weather/information/service/PermanentStorage.java | 12 +++--------- .../weather/information/widget/WidgetIntentService.java | 14 ++++++++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/name/gumartinm/weather/information/service/PermanentStorage.java b/app/src/main/java/name/gumartinm/weather/information/service/PermanentStorage.java index 61a5498..59504e7 100644 --- a/app/src/main/java/name/gumartinm/weather/information/service/PermanentStorage.java +++ b/app/src/main/java/name/gumartinm/weather/information/service/PermanentStorage.java @@ -105,11 +105,7 @@ public class PermanentStorage { final String fileName = MessageFormat.format(WIDGET_CURRENT_DATA_FILE, appWidgetId); - try { - this.removeFile(fileName); - } catch (final IOException e) { - Log.e(TAG, "removeWidgetCurrentData exception: ", e); - } + this.removeFile(fileName); } public void saveForecast(final Forecast forecast) { @@ -192,13 +188,11 @@ public class PermanentStorage { } } - private void removeFile(final String fileName) throws IOException { + private void removeFile(final String fileName) { final File filesDir = this.context.getFilesDir(); final File file = new File(filesDir, fileName); - if (!file.delete()) { - throw new IOException("PermanentStorage, remove file error"); - } + file.delete(); } } diff --git a/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java b/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java index 5311017..057ba69 100644 --- a/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java +++ b/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java @@ -33,12 +33,10 @@ import java.net.URISyntaxException; import java.net.URL; import java.text.DecimalFormat; import java.text.NumberFormat; -import java.util.Date; import java.util.Locale; public class WidgetIntentService extends IntentService { private static final String TAG = "WidgetIntentService"; - private static final long UPDATE_TIME_RATE = 86400000L; public WidgetIntentService() { super("WIS-Thread"); @@ -51,7 +49,7 @@ public class WidgetIntentService extends IntentService { final boolean isRefreshAppWidget = intent.getBooleanExtra("refreshAppWidget", false); if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { - // Nothing to do. Something went wrong. Show error. + // Nothing to do. Something went wrong. return; } @@ -62,6 +60,10 @@ public class WidgetIntentService extends IntentService { if (weatherLocation == null) { // Nothing to do. Show error. final RemoteViews view = this.makeErrorView(appWidgetId); + + final PermanentStorage store = new PermanentStorage(this.getApplicationContext()); + store.removeWidgetCurrentData(appWidgetId); + this.updateWidget(view, appWidgetId); return; } @@ -78,21 +80,25 @@ public class WidgetIntentService extends IntentService { } else { // Show error. view = this.makeErrorView(appWidgetId); + + store.removeWidgetCurrentData(appWidgetId); } this.updateWidget(view, appWidgetId); } else { RemoteViews view; + final PermanentStorage store = new PermanentStorage(this.getApplicationContext()); final Current current = this.getRemoteCurrent(weatherLocation); if (current != null) { // Update UI. view = this.makeView(current, weatherLocation, appWidgetId); - final PermanentStorage store = new PermanentStorage(this.getApplicationContext()); store.saveWidgetCurrentData(current, appWidgetId); } else { // Show error. view = this.makeErrorView(appWidgetId); + + store.removeWidgetCurrentData(appWidgetId); } this.updateWidget(view, appWidgetId); } -- 2.1.4