mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,7 +61,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
|||||||
}
|
}
|
||||||
catch (RuntimeException e)
|
catch (RuntimeException e)
|
||||||
{
|
{
|
||||||
drawErrorWidget(context, manager, widgetId);
|
drawErrorWidget(context, manager, widgetId, e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ 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) throw new HabitNotFoundException();
|
||||||
return habit;
|
return habit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,10 +115,16 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
|||||||
|
|
||||||
private void drawErrorWidget(Context context,
|
private void drawErrorWidget(Context context,
|
||||||
AppWidgetManager manager,
|
AppWidgetManager manager,
|
||||||
int widgetId)
|
int widgetId,
|
||||||
|
RuntimeException e)
|
||||||
{
|
{
|
||||||
RemoteViews errorView =
|
RemoteViews errorView =
|
||||||
new RemoteViews(context.getPackageName(), R.layout.widget_error);
|
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);
|
manager.updateAppWidget(widgetId, errorView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +147,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
|||||||
}
|
}
|
||||||
catch (RuntimeException e)
|
catch (RuntimeException e)
|
||||||
{
|
{
|
||||||
drawErrorWidget(context, manager, widgetId);
|
drawErrorWidget(context, manager, widgetId, e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user