fixed up widget so now application starts up without crashing.

pull/14/head
Tim Su 15 years ago
parent 07cccb4214
commit 7841448da3

@ -129,7 +129,7 @@
<!-- ======================================================== Services = --> <!-- ======================================================== Services = -->
<service android:name="com.todoroo.astrid.widget.TasksWidget$UpdateService"></service> <service android:name="com.todoroo.astrid.widget.TasksWidget$UpdateService" />
<service android:name=".sync.SynchronizationService" /> <service android:name=".sync.SynchronizationService" />
<service android:name=".utilities.BackupService"/> <service android:name=".utilities.BackupService"/>

@ -107,6 +107,9 @@ abstract public class AbstractDatabase {
public synchronized final void openForWriting() { public synchronized final void openForWriting() {
initializeHelper(); initializeHelper();
if(database != null && !database.isReadOnly() && database.isOpen())
return;
try { try {
database = helper.getWritableDatabase(); database = helper.getWritableDatabase();
} catch (SQLiteException writeException) { } catch (SQLiteException writeException) {
@ -127,6 +130,8 @@ abstract public class AbstractDatabase {
*/ */
public synchronized final void openForReading() { public synchronized final void openForReading() {
initializeHelper(); initializeHelper();
if(database != null && database.isOpen())
return;
database = helper.getReadableDatabase(); database = helper.getReadableDatabase();
} }
@ -153,9 +158,6 @@ abstract public class AbstractDatabase {
* @return sql database. opens database if not yet open * @return sql database. opens database if not yet open
*/ */
private synchronized final SQLiteDatabase getDatabase() { private synchronized final SQLiteDatabase getDatabase() {
// open database if requested
if(database == null)
openForWriting();
return database; return database;
} }
@ -207,6 +209,7 @@ abstract public class AbstractDatabase {
public DatabaseHelper(Context context, String name, public DatabaseHelper(Context context, String name,
CursorFactory factory, int version) { CursorFactory factory, int version) {
super(context, name, factory, version); super(context, name, factory, version);
Log.e("AYAAA", "NEW DATABASE HLEPER", new Throwable());
} }
/** /**

@ -21,6 +21,7 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
@ -61,6 +62,9 @@ public final class ReminderService {
@Autowired @Autowired
private TaskDao taskDao; private TaskDao taskDao;
@Autowired
private Database database;
private AlarmScheduler scheduler = new ReminderAlarmScheduler(); private AlarmScheduler scheduler = new ReminderAlarmScheduler();
public ReminderService() { public ReminderService() {
@ -295,6 +299,7 @@ public final class ReminderService {
* @return todoroo cursor. PLEASE CLOSE THIS CURSOR! * @return todoroo cursor. PLEASE CLOSE THIS CURSOR!
*/ */
private TodorooCursor<Task> getTasksWithReminders(Property<?>... properties) { private TodorooCursor<Task> getTasksWithReminders(Property<?>... properties) {
database.openForReading();
return taskDao.query(Query.select(properties).where(Criterion.and(TaskCriteria.isActive(), return taskDao.query(Query.select(properties).where(Criterion.and(TaskCriteria.isActive(),
Task.REMINDER_FLAGS.gt(0)))); Task.REMINDER_FLAGS.gt(0))));
} }

@ -17,7 +17,7 @@ import com.todoroo.astrid.model.Task;
* *
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class Database extends AbstractDatabase { public final class Database extends AbstractDatabase {
// --- constants // --- constants

@ -58,13 +58,8 @@ public class TasksWidget extends AppWidgetProvider {
@Override @Override
public void onStart(Intent intent, int startId) { public void onStart(Intent intent, int startId) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
return;
}
RemoteViews updateViews = buildUpdate(this);
ContextManager.setContext(this); ContextManager.setContext(this);
RemoteViews updateViews = buildUpdate(this);
ComponentName thisWidget = new ComponentName(this, ComponentName thisWidget = new ComponentName(this,
TasksWidget.class); TasksWidget.class);
@ -79,6 +74,8 @@ public class TasksWidget extends AppWidgetProvider {
@SuppressWarnings("nls") @SuppressWarnings("nls")
public RemoteViews buildUpdate(Context context) { public RemoteViews buildUpdate(Context context) {
DependencyInjectionService.getInstance().inject(this);
RemoteViews views = null; RemoteViews views = null;
views = new RemoteViews(context.getPackageName(), views = new RemoteViews(context.getPackageName(),
@ -97,7 +94,6 @@ public class TasksWidget extends AppWidgetProvider {
try { try {
Filter inboxFilter = CoreFilterExposer.buildInboxFilter(getResources()); Filter inboxFilter = CoreFilterExposer.buildInboxFilter(getResources());
inboxFilter.sqlQuery += "ORDER BY " + TaskService.defaultTaskOrder() + " LIMIT " + numberOfTasks; inboxFilter.sqlQuery += "ORDER BY " + TaskService.defaultTaskOrder() + " LIMIT " + numberOfTasks;
DependencyInjectionService.getInstance().inject(this);
database.openForReading(); database.openForReading();
cursor = taskService.fetchFiltered(inboxFilter, Task.TITLE, Task.DUE_DATE); cursor = taskService.fetchFiltered(inboxFilter, Task.TITLE, Task.DUE_DATE);

Loading…
Cancel
Save