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 = -->
<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=".utilities.BackupService"/>

@ -107,6 +107,9 @@ abstract public class AbstractDatabase {
public synchronized final void openForWriting() {
initializeHelper();
if(database != null && !database.isReadOnly() && database.isOpen())
return;
try {
database = helper.getWritableDatabase();
} catch (SQLiteException writeException) {
@ -127,6 +130,8 @@ abstract public class AbstractDatabase {
*/
public synchronized final void openForReading() {
initializeHelper();
if(database != null && database.isOpen())
return;
database = helper.getReadableDatabase();
}
@ -153,9 +158,6 @@ abstract public class AbstractDatabase {
* @return sql database. opens database if not yet open
*/
private synchronized final SQLiteDatabase getDatabase() {
// open database if requested
if(database == null)
openForWriting();
return database;
}
@ -207,6 +209,7 @@ abstract public class AbstractDatabase {
public DatabaseHelper(Context context, String name,
CursorFactory factory, int 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.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.model.Task;
@ -61,6 +62,9 @@ public final class ReminderService {
@Autowired
private TaskDao taskDao;
@Autowired
private Database database;
private AlarmScheduler scheduler = new ReminderAlarmScheduler();
public ReminderService() {
@ -295,6 +299,7 @@ public final class ReminderService {
* @return todoroo cursor. PLEASE CLOSE THIS CURSOR!
*/
private TodorooCursor<Task> getTasksWithReminders(Property<?>... properties) {
database.openForReading();
return taskDao.query(Query.select(properties).where(Criterion.and(TaskCriteria.isActive(),
Task.REMINDER_FLAGS.gt(0))));
}

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

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

Loading…
Cancel
Save