private Cursor queryTodoList( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Uri = content://com.mokelab.todo.provider/users/{userId}/todos // pathSegments[0] = users // pathSegments[1] = {userId} // pathSegments[2] = todos String userId = uri.getPathSegments().get(1); Cursor cursor = mTodoDAO.query(userId, projection, selection, selectionArgs, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
private Uri insertLocal(Uri uri, ContentValues contentValues) { // Uri = content://com.mokelab.todo.provider/users/{userId}/todos // pathSegments[0] = users // pathSegments[1] = {userId} // pathSegments[2] = todos String userId = uri.getPathSegments().get(1); String todo = contentValues.getAsString(TodoColumns.TODO); long id = mTodoDAO.insert(userId, "", System.currentTimeMillis(), 0, todo); if (id == -1) { return null; } // notify update Uri notifyUri = Uri.parse("content://" + AUTHORITY + "/users/" + userId + "/todos"); getContext().getContentResolver().notifyChange(notifyUri, null); return Uri.parse("content://" + AUTHORITY + "/users/" + userId + "/todos/" + id); }