Permalink
Browse files

Done T0905-QueryAllTasks

  • Loading branch information...
GinaHsu committed Oct 29, 2017
1 parent 776ac27 commit 98744937081fb7f6d4e2b63a481fe4a486dddcc9
@@ -27,8 +27,11 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;
import android.view.View;
import com.example.android.todolist.data.TaskContract;
public class MainActivity extends AppCompatActivity implements
LoaderManager.LoaderCallbacks<Cursor> {
@@ -148,8 +151,17 @@ public Cursor loadInBackground() {
// TODO (5) Query and load all task data in the background; sort by priority
// [Hint] use a try/catch block to catch any errors in loading data
return null;
try{
return getContentResolver().query(TaskContract.TaskEntry.CONTENT_URI,
null,
null,
null,
TaskContract.TaskEntry.COLUMN_PRIORITY);
} catch (Exception e){
Log.e(TAG, "Fail to asynchronously load data");
e.printStackTrace();
return null;
}
}
// deliverResult sends the result of the load, a Cursor, to the registered listener
@@ -121,14 +121,34 @@ public Cursor query(@NonNull Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
// TODO (1) Get access to underlying database (read-only for query)
final SQLiteDatabase db = mTaskDbHelper.getReadableDatabase();
// TODO (2) Write URI match code and set a variable to return a Cursor
int match = sUriMatcher.match(uri);
Cursor myCursor;
// TODO (3) Query for the tasks directory and write a default case
switch (match){
//Query for the tasks directory
case TASKS:
myCursor =db.query(TABLE_NAME,
projection,
selection,
selectionArgs,
null,
null,
sortOrder);
break;
//Default exception
default:
throw new UnsupportedOperationException("Unknow uri: "+ uri);
}
// TODO (4) Set a notification URI on the Cursor and return that Cursor
myCursor.setNotificationUri(getContext().getContentResolver(), uri);
throw new UnsupportedOperationException("Not yet implemented");
//return the desired cursor
return myCursor;
}

0 comments on commit 9874493

Please sign in to comment.