Ignore exception when habit is not found

This commit is contained in:
2017-04-11 21:19:03 -04:00
parent 65cc99dbf7
commit 0d6ad26505
2 changed files with 13 additions and 3 deletions

View File

@@ -23,6 +23,7 @@ import android.content.*;
import android.preference.*; import android.preference.*;
import org.isoron.uhabits.*; import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import javax.inject.*; import javax.inject.*;
@@ -48,7 +49,7 @@ public class WidgetPreferences
public long getHabitIdFromWidgetId(int widgetId) public long getHabitIdFromWidgetId(int widgetId)
{ {
Long habitId = prefs.getLong(getHabitIdKey(widgetId), -1); Long habitId = prefs.getLong(getHabitIdKey(widgetId), -1);
if (habitId < 0) throw new RuntimeException("widget not found"); if (habitId < 0) throw new HabitNotFoundException();
return habitId; return habitId;
} }

View File

@@ -25,6 +25,8 @@ import android.os.*;
import android.support.annotation.*; import android.support.annotation.*;
import android.widget.*; import android.widget.*;
import com.activeandroid.util.*;
import org.isoron.uhabits.*; import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.preferences.*; import org.isoron.uhabits.preferences.*;
@@ -75,10 +77,17 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
updateDependencies(context); updateDependencies(context);
for (int id : ids) for (int id : ids)
{
try
{ {
BaseWidget widget = getWidgetFromId(context, id); BaseWidget widget = getWidgetFromId(context, id);
widget.delete(); widget.delete();
} }
catch (HabitNotFoundException e)
{
Log.e("BaseWidgetProvider", e);
}
}
} }
@Override @Override