Skip to content

Commit

Permalink
plusonelabs#308 Fix for a case when no Tasks or no Calendars are sele…
Browse files Browse the repository at this point in the history
…cted
  • Loading branch information
yvolk committed Aug 4, 2019
1 parent 1c0b065 commit f75fd5a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.andstatus.todoagenda.EventAppWidgetProvider;
import org.andstatus.todoagenda.calendar.CalendarEvent;
import org.andstatus.todoagenda.prefs.ApplicationPreferences;
import org.andstatus.todoagenda.prefs.EventSource;
import org.andstatus.todoagenda.prefs.InstanceSettings;
import org.andstatus.todoagenda.prefs.MockSettingsProvider;
import org.andstatus.todoagenda.util.DateUtil;
Expand All @@ -27,11 +28,11 @@
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;

import static junit.framework.Assert.assertTrue;
import static org.andstatus.todoagenda.prefs.ApplicationPreferences.PREF_WIDGET_ID;
import static org.andstatus.todoagenda.provider.QueryResultsStorage.KEY_SETTINGS;

Expand Down Expand Up @@ -85,8 +86,18 @@ private void setPreferences(Context context) throws JSONException {
if (InstanceSettings.getInstances(context).isEmpty()) {
InstanceSettings.save(context, widgetId.incrementAndGet());
}
InstanceSettings settings = InstanceSettings.fromId(context, widgetId.incrementAndGet());
assertTrue("widgetId:" + getWidgetId(), settings.isJustCreated());

ApplicationPreferences.startEditing(context, widgetId.incrementAndGet());
List<EventSource> sources = new ArrayList<>();
sources.add(new EventSource(EventProviderType.CALENDAR, 1, "", "", 0xFF));
for(int i = 0; i < numberOfOpenTaskSources; i++) {
sources.add(new EventSource(EventProviderType.DMFS_OPEN_TASKS, 2 + i,
getClass().getSimpleName() + ".task" + i, "[email protected]", 0x0FF0000));
}
ApplicationPreferences.setActiveEventSources(context, sources);
ApplicationPreferences.save(context, widgetId.get());

InstanceSettings settings = InstanceSettings.fromId(context, widgetId.get());
JSONObject json = settings.toJson();
JSONArray jsonArray = new JSONArray();
jsonArray.put(json);
Expand Down Expand Up @@ -123,7 +134,7 @@ public Cursor query(Uri uri, String[] projection, String selection, String[] sel

MatrixCursor cursor = new MatrixCursor(projection);
for(int i = 0; i < numberOfOpenTaskSources; i++) {
cursor.addRow(new Object[]{2L + i, getClass().getSimpleName() + ".task" + i, 0x0FF0000,
cursor.addRow(new Object[]{2 + i, getClass().getSimpleName() + ".task" + i, 0x0FF0000,
"[email protected]"});
}
return cursor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

Expand All @@ -41,10 +42,11 @@ public CalendarEventProvider(EventProviderType type, Context context, int widget
super(type, context, widgetId);
}

public List<CalendarEvent> getEvents() {
List<CalendarEvent> getEvents() {
initialiseParameters();
if (PermissionsUtil.isPermissionNeeded(context, type.permission)) {
return new ArrayList<>();
if (PermissionsUtil.isPermissionNeeded(context, type.permission) ||
getSettings().getActiveEventSources(type).isEmpty()) {
return Collections.emptyList();
}
List<CalendarEvent> eventList = getTimeFilteredEventList();
if (getSettings().getShowPastEventsWithDefaultColor()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import android.content.Context;
import android.content.Intent;

import org.andstatus.todoagenda.provider.EventProvider;
import org.andstatus.todoagenda.provider.EventProviderType;
import org.andstatus.todoagenda.util.DateUtil;
import org.andstatus.todoagenda.provider.EventProvider;
import org.andstatus.todoagenda.util.PermissionsUtil;
import org.joda.time.DateTime;

import java.util.Collections;
import java.util.List;

public abstract class AbstractTaskProvider extends EventProvider {
Expand All @@ -25,7 +27,17 @@ protected void initialiseParameters() {
now = DateUtil.now(zone);
}

public abstract List<TaskEvent> getEvents();
public List<TaskEvent> getEvents() {
initialiseParameters();
if (PermissionsUtil.isPermissionNeeded(context, type.permission) ||
getSettings().getActiveEventSources(type).isEmpty()) {
return Collections.emptyList();
}

return queryTasks();
}

public abstract List<TaskEvent> queryTasks();

public abstract Intent createViewEventIntent(TaskEvent event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.andstatus.todoagenda.task.AbstractTaskProvider;
import org.andstatus.todoagenda.task.TaskEvent;
import org.andstatus.todoagenda.util.CalendarIntentUtil;
import org.andstatus.todoagenda.util.PermissionsUtil;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -29,16 +28,7 @@ public DmfsOpenTasksProvider(EventProviderType type, Context context, int widget
}

@Override
public List<TaskEvent> getEvents() {
initialiseParameters();
if (PermissionsUtil.isPermissionNeeded(context, type.permission)) {
return new ArrayList<>();
}

return queryTasks();
}

private List<TaskEvent> queryTasks() {
public List<TaskEvent> queryTasks() {
Uri uri = DmfsOpenTasksContract.Tasks.PROVIDER_URI;
String[] projection = {
DmfsOpenTasksContract.Tasks.COLUMN_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.andstatus.todoagenda.task.AbstractTaskProvider;
import org.andstatus.todoagenda.task.TaskEvent;
import org.andstatus.todoagenda.util.CalendarIntentUtil;
import org.andstatus.todoagenda.util.PermissionsUtil;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -31,16 +30,7 @@ public SamsungTasksProvider(EventProviderType type, Context context, int widgetI
}

@Override
public List<TaskEvent> getEvents() {
initialiseParameters();
if (PermissionsUtil.isPermissionNeeded(context, type.permission)) {
return new ArrayList<>();
}

return queryTasks();
}

private List<TaskEvent> queryTasks() {
public List<TaskEvent> queryTasks() {
Uri uri = SamsungTasksContract.Tasks.PROVIDER_URI;
String[] projection = {
SamsungTasksContract.Tasks.COLUMN_ID,
Expand Down

0 comments on commit f75fd5a

Please sign in to comment.