Ignore exception when habit is not found

pull/276/head
Alinson S. Xavier 9 years ago
parent 65cc99dbf7
commit 0d6ad26505

@ -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;
} }

@ -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.*;
@ -76,8 +78,15 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
for (int id : ids) for (int id : ids)
{ {
BaseWidget widget = getWidgetFromId(context, id); try
widget.delete(); {
BaseWidget widget = getWidgetFromId(context, id);
widget.delete();
}
catch (HabitNotFoundException e)
{
Log.e("BaseWidgetProvider", e);
}
} }
} }

Loading…
Cancel
Save