@ -143,12 +143,10 @@ public class TaskController extends AbstractController {
return list ;
return list ;
}
}
/** Get identifiers for all tasks */
/ * * Helper method to take a cursor pointing to a list of id ' s and generate
public HashSet < TaskIdentifier > getAllTaskIdentifiers ( ) {
* a hashset * /
private HashSet < TaskIdentifier > createTaskIdentifierSet ( Cursor cursor ) {
HashSet < TaskIdentifier > list = new HashSet < TaskIdentifier > ( ) ;
HashSet < TaskIdentifier > list = new HashSet < TaskIdentifier > ( ) ;
Cursor cursor = database . query ( TASK_TABLE_NAME , new String [ ] { KEY_ROWID } ,
null , null , null , null , null , null ) ;
try {
try {
if ( cursor . getCount ( ) = = 0 )
if ( cursor . getCount ( ) = = 0 )
return list ;
return list ;
@ -165,29 +163,32 @@ public class TaskController extends AbstractController {
}
}
}
}
/** Get identifiers for all tasks */
public HashSet < TaskIdentifier > getAllTaskIdentifiers ( ) {
Cursor cursor = database . query ( TASK_TABLE_NAME , new String [ ] { KEY_ROWID } ,
null , null , null , null , null , null ) ;
return createTaskIdentifierSet ( cursor ) ;
}
/** Get identifiers for all non-completed tasks */
/** Get identifiers for all non-completed tasks */
public HashSet < TaskIdentifier > getActiveTaskIdentifiers ( ) {
public HashSet < TaskIdentifier > getActiveTaskIdentifiers ( ) {
HashSet < TaskIdentifier > list = new HashSet < TaskIdentifier > ( ) ;
Cursor cursor = database . query ( TASK_TABLE_NAME , new String [ ] { KEY_ROWID } ,
Cursor cursor = database . query ( TASK_TABLE_NAME , new String [ ] { KEY_ROWID } ,
AbstractTaskModel . PROGRESS_PERCENTAGE + " < " +
AbstractTaskModel . PROGRESS_PERCENTAGE + " < " +
AbstractTaskModel . COMPLETE_PERCENTAGE , null , null , null , null , null ) ;
AbstractTaskModel . COMPLETE_PERCENTAGE , null , null , null , null , null ) ;
return createTaskIdentifierSet ( cursor ) ;
}
try {
/** Get identifiers for all non-completed, non-hidden tasks */
if ( cursor . getCount ( ) = = 0 )
public HashSet < TaskIdentifier > getActiveVisibleTaskIdentifiers ( ) {
return list ;
Cursor cursor = database . query ( TASK_TABLE_NAME , new String [ ] { KEY_ROWID } ,
AbstractTaskModel . PROGRESS_PERCENTAGE + " < " +
do {
AbstractTaskModel . COMPLETE_PERCENTAGE + " AND " +
cursor . moveToNext ( ) ;
AbstractTaskModel . HIDDEN_UNTIL + " < " +
list . add ( new TaskIdentifier ( cursor . getInt (
System . currentTimeMillis ( ) , null , null , null , null , null ) ;
cursor . getColumnIndexOrThrow ( KEY_ROWID ) ) ) ) ;
return createTaskIdentifierSet ( cursor ) ;
} while ( ! cursor . isLast ( ) ) ;
return list ;
} finally {
cursor . close ( ) ;
}
}
}
/** Create a weighted list of tasks from the db cursor given */
/** Create a weighted list of tasks from the db cursor given */
public Cursor getTaskListCursorById ( List < TaskIdentifier > idList ) {
public Cursor getTaskListCursorById ( List < TaskIdentifier > idList ) {
@ -521,7 +522,7 @@ public class TaskController extends AbstractController {
* @throws SQLException if the database could be neither opened or created
* @throws SQLException if the database could be neither opened or created
* /
* /
@Override
@Override
public void open ( ) throws SQLException {
public synchronized void open ( ) throws SQLException {
SQLiteOpenHelper databaseHelper = new TaskModelDatabaseHelper (
SQLiteOpenHelper databaseHelper = new TaskModelDatabaseHelper (
context , TASK_TABLE_NAME , TASK_TABLE_NAME ) ;
context , TASK_TABLE_NAME , TASK_TABLE_NAME ) ;
database = databaseHelper . getWritableDatabase ( ) ;
database = databaseHelper . getWritableDatabase ( ) ;