@Override public Uri insert(Uri uri, ContentValues values) { final int match = MATCHER.match(uri); String table; switch (match) { case NEWS_CODE: table = Constants.Contract.News.TABLE; break; default: throw new UnsupportedOperationException("No uri matched"); } SQLiteDatabase db = mDbHelper.getWritableDatabase(); long insertedId = db.insert(table, null, values); if (insertedId != -1) { Uri insertedUri = ContentUris.withAppendedId(uri, insertedId); getContext().getContentResolver().notifyChange(insertedUri, null); return insertedUri; } return null; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final int match = MATCHER.match(uri); SQLiteQueryBuilder query = new SQLiteQueryBuilder(); switch (match) { case NEWS_CODE: query.setTables(Constants.Contract.News.TABLE); break; case SPECIFIC_NEWS_CODE: query.setTables(Constants.Contract.News.TABLE); query.appendWhere("_id = " + uri.getLastPathSegment()); break; default: throw new UnsupportedOperationException("No matching uri"); } SQLiteDatabase db = mDbHelper.getReadableDatabase(); Cursor cursor = query.query(db, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }