diff --git a/app/src/main/java/org/isoron/uhabits/models/HabitNotFoundException.java b/app/src/main/java/org/isoron/uhabits/models/HabitNotFoundException.java new file mode 100644 index 000000000..74302e2ad --- /dev/null +++ b/app/src/main/java/org/isoron/uhabits/models/HabitNotFoundException.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2016 Álinson Santos Xavier + * + * This file is part of Loop Habit Tracker. + * + * Loop Habit Tracker is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Loop Habit Tracker is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +package org.isoron.uhabits.models; + +public class HabitNotFoundException extends RuntimeException { + public HabitNotFoundException() { + super(); + } + + public HabitNotFoundException(String message) { + super(message); + } + + public HabitNotFoundException(Throwable cause) { + super(cause); + } + + public HabitNotFoundException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/app/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java b/app/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java index 2256c338c..dfdc49834 100644 --- a/app/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java +++ b/app/src/main/java/org/isoron/uhabits/widgets/BaseWidgetProvider.java @@ -61,7 +61,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider } catch (RuntimeException e) { - drawErrorWidget(context, manager, widgetId); + drawErrorWidget(context, manager, widgetId, e); e.printStackTrace(); } } @@ -105,7 +105,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider { long habitId = widgetPrefs.getHabitIdFromWidgetId(widgetId); Habit habit = habits.getById(habitId); - if (habit == null) throw new RuntimeException("habit not found"); + if (habit == null) throw new HabitNotFoundException(); return habit; } @@ -115,10 +115,16 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider private void drawErrorWidget(Context context, AppWidgetManager manager, - int widgetId) + int widgetId, + RuntimeException e) { RemoteViews errorView = new RemoteViews(context.getPackageName(), R.layout.widget_error); + + if(e instanceof HabitNotFoundException) { + errorView.setCharSequence(R.id.label, "setText", context.getString(R.string.habit_not_found)); + } + manager.updateAppWidget(widgetId, errorView); } @@ -141,7 +147,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider } catch (RuntimeException e) { - drawErrorWidget(context, manager, widgetId); + drawErrorWidget(context, manager, widgetId, e); e.printStackTrace(); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 03ceda6c3..086e22859 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -102,6 +102,7 @@ You can see more days by putting your phone in landscape mode. Delete Habits The habits will be permanently deleted. This action cannot be undone. + Habit deleted / not found Weekends Monday to Friday Any day of the week