@Override public void onCreate() { widgetSettingsStorage = new WidgetSettingsStorage(context); widgetSettingsStorage.open(); todoItemsStorage = new TodoItemsStorage(context); todoItemsStorage.open(); }
@Override public void onDestroy() { if (widgetSettingsStorage != null) { widgetSettingsStorage.close(); widgetSettingsStorage = null; } if (todoItemsStorage != null) { todoItemsStorage.close(); todoItemsStorage = null; } items = null; }
@Override public void onDataSetChanged() { if (widgetSettingsStorage != null && todoItemsStorage != null && widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { WidgetSettings widgetSettings = widgetSettingsStorage.load(widgetId); int tagID = widgetSettings.tagID; items = new ArrayList<>(); Cursor cursor = todoItemsStorage.getByTagCursor(tagID, widgetSettings.sortingMode); if (cursor.moveToFirst()) { do { TodoItem item = todoItemsStorage.loadTodoItemFromCursor(cursor); if (showItem(item, widgetSettings)) { items.add(item); } } while (cursor.moveToNext()); } cursor.close(); } }