Fix for issue #168

pull/175/head
RegularCoder 9 years ago
parent dc5d7930a6
commit cef8b5fbd0

@ -39,6 +39,9 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
private WidgetPreferences widgetPrefs; private WidgetPreferences widgetPrefs;
//Used to show meaningful message if a habit is deleted
private Boolean habitNotFound = false;
@Override @Override
public void onAppWidgetOptionsChanged(@Nullable Context context, public void onAppWidgetOptionsChanged(@Nullable Context context,
@Nullable AppWidgetManager manager, @Nullable AppWidgetManager manager,
@ -97,7 +100,6 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
for (int id : widgetIds) for (int id : widgetIds)
update(context, manager, id); update(context, manager, id);
}, 500); }, 500);
} }
@NonNull @NonNull
@ -105,7 +107,10 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
{ {
long habitId = widgetPrefs.getHabitIdFromWidgetId(widgetId); long habitId = widgetPrefs.getHabitIdFromWidgetId(widgetId);
Habit habit = habits.getById(habitId); Habit habit = habits.getById(habitId);
if (habit == null) throw new RuntimeException("habit not found"); if (habit == null) {
habitNotFound = true;
throw new RuntimeException("habit not found");
}
return habit; return habit;
} }
@ -119,6 +124,11 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
{ {
RemoteViews errorView = RemoteViews errorView =
new RemoteViews(context.getPackageName(), R.layout.widget_error); new RemoteViews(context.getPackageName(), R.layout.widget_error);
if(habitNotFound) {
errorView.setCharSequence(R.id.label, "setText", context.getString(R.string.habit_not_found));
}
manager.updateAppWidget(widgetId, errorView); manager.updateAppWidget(widgetId, errorView);
} }

@ -102,6 +102,7 @@
<string name="hint_landscape">You can see more days by putting your phone in landscape mode.</string> <string name="hint_landscape">You can see more days by putting your phone in landscape mode.</string>
<string name="delete_habits">Delete Habits</string> <string name="delete_habits">Delete Habits</string>
<string name="delete_habits_message">The habits will be permanently deleted. This action cannot be undone.</string> <string name="delete_habits_message">The habits will be permanently deleted. This action cannot be undone.</string>
<string name="habit_not_found">Habit deleted / not found</string>
<string name="weekends">Weekends</string> <string name="weekends">Weekends</string>
<string name="any_weekday">Monday to Friday</string> <string name="any_weekday">Monday to Friday</string>
<string name="any_day">Any day of the week</string> <string name="any_day">Any day of the week</string>

Loading…
Cancel
Save