Last active
September 15, 2018 22:28
-
-
Save barmgeat/a7387f5d7996f5387c2ff3a84075ea8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
@Nullable | |
@Override | |
public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) { | |
final int match = uriMatcher.match(uri); | |
switch (match){ | |
case WORDS_CODE : | |
return insertData(uri, contentValues); | |
default: | |
throw new IllegalArgumentException("Valid URI " + uri); | |
} | |
} | |
/** | |
* @param uri : caller should provide the Uri he need | |
* @param content: caller should provide the Data of the inserted Object | |
* @return the new Uri for inserted Object | |
*/ | |
private Uri insertData(Uri uri, ContentValues content) { | |
SQLiteDatabase database = mDbHelper.getWritableDatabase(); | |
long id = database.insert(uri.getPath(), null, content); | |
if (id != -1) { | |
return ContentUris.withAppendedId(uri, id); | |
} | |
else{ | |
return null ; | |
} | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment