@Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    int uriType = ContentDescriptor.uriMatcher.match(uri);
    String tableName = ContentDescriptor.getTableName(uriType);

    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int result = db.delete(tableName, selection, selectionArgs);
    getContext().getContentResolver().notifyChange(uri, null);
    return result;
  }
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String orderBy) {
    int uriType = ContentDescriptor.uriMatcher.match(uri);
    String tableName = ContentDescriptor.getTableName(uriType);

    SQLiteDatabase db = dbHelper.getReadableDatabase();
    Cursor cursor = db.query(tableName, projection, selection, selectionArgs, null, null, orderBy);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
  }
  @Override
  public int update(
      Uri uri, ContentValues contentValues, String selection, String[] selectionArgs) {
    int uriType = ContentDescriptor.uriMatcher.match(uri);
    String tableName = ContentDescriptor.getTableName(uriType);

    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int result;
    try {
      result = db.update(tableName, contentValues, selection, selectionArgs);
    } catch (Throwable e) {
      Log.e(MyContentProvider.class.getSimpleName(), "Unable to update SQLiteDatabase");
      result = 0;
    }

    return result;
  }
  @Override
  public Uri insert(Uri uri, ContentValues contentValues) {
    int uriType = ContentDescriptor.uriMatcher.match(uri);
    String tableName = ContentDescriptor.getTableName(uriType);

    SQLiteDatabase db = dbHelper.getWritableDatabase();
    long id =
        db.insertWithOnConflict(tableName, null, contentValues, SQLiteDatabase.CONFLICT_IGNORE);

    getContext().getContentResolver().notifyChange(uri, null);

    if (TextUtils.equals(tableName, ContentDescriptor.Toys.TABLE_NAME)) {
      return Uri.parse(ContentDescriptor.Toys.TABLE_URI + "/" + id);
    } else {
      return null;
    }
  }