Fixing various bugs encountered during starting up...

pull/14/head
Tim Su 14 years ago
parent aefbf09ada
commit 542bf22201

@ -196,7 +196,7 @@
</intent-filter>
</receiver>
<activity android:name="com.todoroo.astrid.reminders.NotificationActivity"
android:taskAffinity="reminders" />
android:taskAffinity="astrid.reminders" />
</application>
</manifest>

@ -148,11 +148,12 @@ abstract public class AbstractDatabase {
}
/**
* @return sql database. throws error if database was not opened
* @return sql database. opens database if not yet open
*/
public final SQLiteDatabase getDatabase() {
// open database if requested
if(database == null)
throw new IllegalStateException("Database was not opened!");
openForWriting();
return database;
}

@ -20,6 +20,7 @@ import com.timsu.astrid.data.task.TaskIdentifier;
import com.timsu.astrid.utilities.Constants;
import com.timsu.astrid.utilities.Preferences;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.DateUtilities;
@ -55,6 +56,7 @@ public class Notifications extends BroadcastReceiver {
/** Alarm intent */
public void onReceive(Context context, Intent intent) {
DependencyInjectionService.getInstance().inject(this);
ContextManager.setContext(context);
long id = intent.getLongExtra(ID_KEY, 0);
int type = intent.getIntExtra(TYPE_KEY, 0);
@ -68,7 +70,7 @@ public class Notifications extends BroadcastReceiver {
else
reminder = getRandomReminder(r.getStringArray(R.array.reminders));
if(!showNotification(context, id, type, reminder)) {
if(!showNotification(id, type, reminder)) {
NotificationManager nm = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel((int)id);
@ -95,8 +97,8 @@ public class Notifications extends BroadcastReceiver {
* Schedule a new notification about the given task. Returns false if there was
* some sort of error or the alarm should be disabled.
*/
public boolean showNotification(Context context, long id,
int type, String reminder) {
public boolean showNotification(long id, int type, String reminder) {
Context context = ContextManager.getContext();
Task task;
try {

@ -10,7 +10,6 @@ import android.content.Intent;
import android.util.Log;
import com.timsu.astrid.R;
import com.timsu.astrid.utilities.Constants;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
@ -22,6 +21,7 @@ import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.utility.Preferences;
@ -68,6 +68,7 @@ public final class ReminderService {
* Schedules all alarms
*/
public void scheduleAllAlarms() {
TodorooCursor<Task> cursor = getTasksWithReminders(PROPERTIES);
try {
Task task = new Task();
@ -240,7 +241,7 @@ public final class ReminderService {
* @param properties
* @return todoroo cursor. PLEASE CLOSE THIS CURSOR!
*/
public TodorooCursor<Task> getTasksWithReminders(Property<?>... properties) {
private TodorooCursor<Task> getTasksWithReminders(Property<?>... properties) {
return taskDao.query(Query.select(properties).where(Criterion.and(TaskCriteria.isActive(),
Task.REMINDER_FLAGS.gt(0))));
}

@ -33,7 +33,6 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
import com.flurry.android.FlurryAgent;
import com.timsu.astrid.R;
import com.timsu.astrid.activities.EditPreferences;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
@ -50,6 +49,8 @@ import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.filters.CoreFilterExposer;
import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.reminders.Notifications;
import com.todoroo.astrid.reminders.ReminderService;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.TaskService;
@ -81,6 +82,9 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
private static final int CONTEXT_MENU_DELETE_TASK_ID = Menu.FIRST + 6;
private static final int CONTEXT_MENU_ADDON_INTENT_ID = Menu.FIRST + 7;
/** menu code indicating the end of the context menu */
private static final int CONTEXT_MENU_DEBUG = Menu.FIRST + 8;
// --- constants
public static final String TOKEN_FILTER = "filter"; //$NON-NLS-1$
@ -133,6 +137,8 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
if(database == null)
return;
if(Constants.DEBUG)
filter.title = "[D] " + filter.title; //$NON-NLS-1$
database.openForWriting();
setUpUiComponents();
@ -428,6 +434,13 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
menu.add(id, CONTEXT_MENU_DELETE_TASK_ID, Menu.NONE,
R.string.TAd_contextDeleteTask);
if(Constants.DEBUG) {
menu.add(id, CONTEXT_MENU_DEBUG, Menu.NONE,
"schedule alarm"); //$NON-NLS-1$
menu.add(id, CONTEXT_MENU_DEBUG + 1, Menu.NONE,
"make notification"); //$NON-NLS-1$
}
if(contextMenuItemCache == null)
return;
@ -496,7 +509,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
return true;
}
case CONTEXT_MENU_DELETE_TASK_ID:
case CONTEXT_MENU_DELETE_TASK_ID: {
itemId = item.getGroupId();
Task task = new Task();
task.setId(itemId);
@ -504,6 +517,22 @@ public class TaskListActivity extends ListActivity implements OnScrollListener {
return true;
}
case CONTEXT_MENU_DEBUG: {
itemId = item.getGroupId();
Task task = new Task();
task.setId(itemId);
new ReminderService().scheduleAlarm(task);
return true;
}
case CONTEXT_MENU_DEBUG + 1: {
itemId = item.getGroupId();
new Notifications().showNotification(itemId, 0, "test reminder"); //$NON-NLS-1$
return true;
}
}
return false;
}

@ -35,7 +35,7 @@ public class TaskDao extends GenericDao<Task> {
@Autowired
Database database;
ReminderService reminderService = new ReminderService();
ReminderService reminderService;
public TaskDao() {
super(Task.class);
@ -197,8 +197,11 @@ public class TaskDao extends GenericDao<Task> {
private void afterSave(Task task, ContentValues values, boolean duringSync) {
if(values.containsKey(Task.COMPLETION_DATE.name) && task.isCompleted())
afterComplete(task, values, duringSync);
else
else {
if(reminderService == null)
reminderService = new ReminderService();
reminderService.scheduleAlarm(task);
}
if(duringSync)
return;

@ -92,15 +92,15 @@ public final class Task extends AbstractModel {
/** Flags for when to send reminders */
public static final IntegerProperty REMINDER_FLAGS = new IntegerProperty(
TABLE, "reminderFlags");
TABLE, "notificationFlags");
/** Reminder period, in milliseconds. 0 means disabled */
public static final LongProperty REMINDER_PERIOD = new LongProperty(
TABLE, "reminderPeriod");
TABLE, "notifications");
/** Unixtime the last reminder was triggered */
public static final LongProperty REMINDER_LAST = new LongProperty(
TABLE, "reminderLast");
TABLE, "lastNotified");
public static final IntegerProperty REPEAT = new IntegerProperty(
TABLE, "repeat");

@ -28,4 +28,8 @@ public final class Constants {
*/
public static final long WIDGET_UPDATE_INTERVAL = 30 * 60 * 1000L;
/**
* Whether to turn on debugging logging and UI
*/
public static final boolean DEBUG = true;
}

Loading…
Cancel
Save