Java Code Examples for android.content.ContentProviderOperation.newInsert()

The following are Jave code examples for showing how to use newInsert() of the android.content.ContentProviderOperation class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: iosched-reader   File: SpeakersHandler.java   Source Code and License Vote up 7 votes
private void buildSpeaker(boolean isInsert, Speaker speaker,
                          ArrayList<ContentProviderOperation> list) {
    Uri allSpeakersUri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Speakers.CONTENT_URI);
    Uri thisSpeakerUri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Speakers.buildSpeakerUri(speaker.id));

    ContentProviderOperation.Builder builder;
    if (isInsert) {
        builder = ContentProviderOperation.newInsert(allSpeakersUri);
    } else {
        builder = ContentProviderOperation.newUpdate(thisSpeakerUri);
    }

    list.add(builder.withValue(ScheduleContract.SyncColumns.UPDATED, System.currentTimeMillis())
            .withValue(ScheduleContract.Speakers.SPEAKER_ID, speaker.id)
            .withValue(ScheduleContract.Speakers.SPEAKER_NAME, speaker.name)
            .withValue(ScheduleContract.Speakers.SPEAKER_ABSTRACT, speaker.bio)
            .withValue(ScheduleContract.Speakers.SPEAKER_COMPANY, speaker.company)
            .withValue(ScheduleContract.Speakers.SPEAKER_IMAGE_URL, speaker.thumbnailUrl)
            .withValue(ScheduleContract.Speakers.SPEAKER_PLUSONE_URL, speaker.plusoneUrl)
            .withValue(ScheduleContract.Speakers.SPEAKER_TWITTER_URL, speaker.twitterUrl)
            .withValue(ScheduleContract.Speakers.SPEAKER_IMPORT_HASHCODE,
                    speaker.getImportHashcode())
            .build());
}
 
Example 2
Project: iosched-reader   File: MapPropertyHandler.java   Source Code and License Vote up 6 votes
private void buildMarkers(ArrayList<ContentProviderOperation> list) {
    Uri uri = ScheduleContractHelper
            .setUriAsCalledFromSyncAdapter(ScheduleContract.MapMarkers.CONTENT_URI);

    list.add(ContentProviderOperation.newDelete(uri).build());

    for (String floor : mMarkers.keySet()) {
        for (Marker marker : mMarkers.get(floor)) {
            ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri);
            builder.withValue(ScheduleContract.MapMarkers.MARKER_ID, marker.id);
            builder.withValue(ScheduleContract.MapMarkers.MARKER_FLOOR, floor);
            builder.withValue(ScheduleContract.MapMarkers.MARKER_LABEL, marker.title);
            builder.withValue(ScheduleContract.MapMarkers.MARKER_LATITUDE, marker.lat);
            builder.withValue(ScheduleContract.MapMarkers.MARKER_LONGITUDE, marker.lng);
            builder.withValue(ScheduleContract.MapMarkers.MARKER_TYPE, marker.type);
            list.add(builder.build());
        }
    }
}
 
Example 3
Project: iosched-reader   File: BlocksHandler.java   Source Code and License Vote up 6 votes
private static void outputBlock(Block block, ArrayList<ContentProviderOperation> list) {
    Uri uri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Blocks.CONTENT_URI);
    ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri);
    String title = block.title != null ? block.title : "";
    String meta = block.subtitle != null ? block.subtitle : "";

    String type = block.type;
    if ( ! ScheduleContract.Blocks.isValidBlockType(type)) {
        LOGW(TAG, "block from "+block.start+" to "+block.end+" has unrecognized type ("
                +type+"). Using "+ ScheduleContract.Blocks.BLOCK_TYPE_BREAK +" instead.");
        type = ScheduleContract.Blocks.BLOCK_TYPE_BREAK;
    }

    long startTimeL = ParserUtils.parseTime(block.start);
    long endTimeL = ParserUtils.parseTime(block.end);
    final String blockId = ScheduleContract.Blocks.generateBlockId(startTimeL, endTimeL);
    builder.withValue(ScheduleContract.Blocks.BLOCK_ID, blockId);
    builder.withValue(ScheduleContract.Blocks.BLOCK_TITLE, title);
    builder.withValue(ScheduleContract.Blocks.BLOCK_START, startTimeL);
    builder.withValue(ScheduleContract.Blocks.BLOCK_END, endTimeL);
    builder.withValue(ScheduleContract.Blocks.BLOCK_TYPE, type);
    builder.withValue(ScheduleContract.Blocks.BLOCK_SUBTITLE, meta);
    list.add(builder.build());
}
 
Example 4
Project: iosched-reader   File: TagsHandler.java   Source Code and License Vote up 6 votes
@Override
public void makeContentProviderOperations(ArrayList<ContentProviderOperation> list) {
    Uri uri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Tags.CONTENT_URI);

    // since the number of tags is very small, for simplicity we delete them all and reinsert
    list.add(ContentProviderOperation.newDelete(uri).build());
    for (Tag tag : mTags.values()) {
        ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri);
        builder.withValue(ScheduleContract.Tags.TAG_ID, tag.tag);
        builder.withValue(ScheduleContract.Tags.TAG_CATEGORY, tag.category);
        builder.withValue(ScheduleContract.Tags.TAG_NAME, tag.name);
        builder.withValue(ScheduleContract.Tags.TAG_ORDER_IN_CATEGORY, tag.order_in_category);
        builder.withValue(ScheduleContract.Tags.TAG_ABSTRACT, tag._abstract);
        builder.withValue(ScheduleContract.Tags.TAG_COLOR, tag.color==null ?
                Color.LTGRAY : Color.parseColor(tag.color));
        list.add(builder.build());
    }
}
 
Example 5
Project: iosched-reader   File: HashtagsHandler.java   Source Code and License Vote up 6 votes
@Override
public void makeContentProviderOperations(ArrayList<ContentProviderOperation> list) {
    LOGD(TAG, "makeContentProviderOperations");
    Uri uri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Hashtags.CONTENT_URI);
    // Remove all the current entries
    list.add(ContentProviderOperation.newDelete(uri).build());
    // Insert hashtags
    for (Hashtag hashtag : mHashtags.values()) {
        ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri);
        builder.withValue(ScheduleContract.Hashtags.HASHTAG_NAME, hashtag.name);
        builder.withValue(ScheduleContract.Hashtags.HASHTAG_DESCRIPTION, hashtag.description);
        try {
            builder.withValue(ScheduleContract.Hashtags.HASHTAG_COLOR,
                    Color.parseColor(hashtag.color));
        } catch (IllegalArgumentException e) {
            builder.withValue(ScheduleContract.Hashtags.HASHTAG_COLOR, Color.BLACK);
        }
        builder.withValue(ScheduleContract.Hashtags.HASHTAG_ORDER, hashtag.order);
        list.add(builder.build());
    }
    LOGD(TAG, "Hashtags: " + mHashtags.size());
}
 
Example 6
Project: iosched-reader   File: MapPropertyHandler.java   Source Code and License Vote up 5 votes
private void buildTiles(ArrayList<ContentProviderOperation> list) {
    Uri uri = ScheduleContractHelper
            .setUriAsCalledFromSyncAdapter(ScheduleContract.MapTiles.CONTENT_URI);

    list.add(ContentProviderOperation.newDelete(uri).build());

    for (String floor : mTileOverlays.keySet()) {
        Tile tileOverlay = mTileOverlays.get(floor);
        ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri);
        builder.withValue(ScheduleContract.MapTiles.TILE_FLOOR, floor);
        builder.withValue(ScheduleContract.MapTiles.TILE_FILE, tileOverlay.filename);
        builder.withValue(ScheduleContract.MapTiles.TILE_URL, tileOverlay.url);
        list.add(builder.build());
    }
}
 
Example 7
Project: iosched-reader   File: RoomsHandler.java   Source Code and License Vote up 5 votes
@Override
public void makeContentProviderOperations(ArrayList<ContentProviderOperation> list) {
    Uri uri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Rooms.CONTENT_URI);

    // The list of rooms is not large, so for simplicity we delete all of them and repopulate
    list.add(ContentProviderOperation.newDelete(uri).build());
    for (Room room : mRooms.values()) {
        ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri);
        builder.withValue(ScheduleContract.Rooms.ROOM_ID, room.id);
        builder.withValue(ScheduleContract.Rooms.ROOM_NAME, room.name);
        builder.withValue(ScheduleContract.Rooms.ROOM_FLOOR, room.floor);
        list.add(builder.build());
    }
}
 
Example 8
Project: iosched-reader   File: VideosHandler.java   Source Code and License Vote up 4 votes
private void buildVideo(boolean isInsert, Video video,
                          ArrayList<ContentProviderOperation> list) {
    Uri allVideosUri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Videos.CONTENT_URI);
    Uri thisVideoUri = ScheduleContractHelper.setUriAsCalledFromSyncAdapter(
            ScheduleContract.Videos.buildVideoUri(video.id));

    ContentProviderOperation.Builder builder;
    if (isInsert) {
        builder = ContentProviderOperation.newInsert(allVideosUri);
    } else {
        builder = ContentProviderOperation.newUpdate(thisVideoUri);
    }

    if (TextUtils.isEmpty(video.vid)) {
        LOGW(TAG, "Ignoring video with missing video ID.");
        return;
    }

    String thumbUrl = video.thumbnailUrl;
    if (TextUtils.isEmpty(thumbUrl)) {
        // Oops, missing thumbnail URL. Let's improvise.
        // NOTE: this method of obtaining a thumbnail URL from the video ID
        // is unofficial and might not work in the future; that's why we use
        // it only as a fallback in case we don't get a thumbnail URL in the incoming data.
        thumbUrl = String.format(Locale.US, Config.VIDEO_LIBRARY_FALLBACK_THUMB_URL_FMT, video.vid);
        LOGW(TAG, "Video with missing thumbnail URL: " + video.vid
                + ". Using fallback: " + thumbUrl);
    }

    list.add(builder.withValue(ScheduleContract.Videos.VIDEO_ID, video.id)
            .withValue(ScheduleContract.Videos.VIDEO_YEAR, video.year)
            .withValue(ScheduleContract.Videos.VIDEO_TITLE, video.title.trim())
            .withValue(ScheduleContract.Videos.VIDEO_DESC, video.desc)
            .withValue(ScheduleContract.Videos.VIDEO_VID, video.vid)
            .withValue(ScheduleContract.Videos.VIDEO_TOPIC, video.topic)
            .withValue(ScheduleContract.Videos.VIDEO_SPEAKERS, video.speakers)
            .withValue(ScheduleContract.Videos.VIDEO_THUMBNAIL_URL, thumbUrl)
            .withValue(ScheduleContract.Videos.VIDEO_IMPORT_HASHCODE,
                    video.getImportHashcode())
            .build());
}
 
Example 9
Project: aos-MediaLib   File: EpisodeTags.java   Source Code and License Vote up 4 votes
public void addSaveOperation(ArrayList<ContentProviderOperation> list, Map<String, Long> poster2IdMap) {
    if (list == null) return;

    // create ContentValues for this episode
    ContentValues values = new ContentValues();
    values.put(ScraperStore.Episode.VIDEO_ID, Long.valueOf(mVideoId));
    values.put(ScraperStore.Episode.NAME, mTitle);
    if(mAired != null) {
        values.put(ScraperStore.Episode.AIRED, Long.valueOf(mAired.getTime()));
    }
    values.put(ScraperStore.Episode.RATING, Float.valueOf(mRating));
    values.put(ScraperStore.Episode.PLOT, mPlot);
    values.put(ScraperStore.Episode.SEASON, Integer.valueOf(mSeason));
    values.put(ScraperStore.Episode.NUMBER, Integer.valueOf(mEpisode));
    values.put(ScraperStore.Episode.SHOW, Long.valueOf(mShowId));
    values.put(ScraperStore.Episode.IMDB_ID, mImdbId);
    values.put(ScraperStore.Episode.ONLINE_ID, Long.valueOf(mOnlineId));

    values.put(ScraperStore.Episode.ACTORS_FORMATTED, getActorsFormatted());
    values.put(ScraperStore.Episode.DIRECTORS_FORMATTED, getDirectorsFormatted());

    ScraperImage pic = getEpisodePicture();
    if(pic!=null && pic.getLargeFile()!=null)
        values.put(ScraperStore.Episode.PICTURE, pic.getLargeFile());
    
    File cover = getCover();
    String coverPath = (cover != null) ? cover.getPath() : null;
    if (coverPath != null && !coverPath.isEmpty())
        values.put(ScraperStore.Episode.COVER, coverPath);

    // need to find the poster id in the database
    ScraperImage poster = getDefaultPoster();

    if (poster != null) {
        Long posterId = poster2IdMap.get(poster.getLargeFile());
        values.put(ScraperStore.Episode.POSTER_ID, posterId);
    }

    // build list of operations
    Builder cop = null;

    int firstIndex = list.size();
    // first insert the episode base info - item 0 for backreferences
    cop = ContentProviderOperation.newInsert(ScraperStore.Episode.URI.BASE);
    cop.withValues(values);
    list.add(cop.build());

    // then directors etc
    for(String director: mDirectors) {
        cop = ContentProviderOperation.newInsert(ScraperStore.Director.URI.EPISODE);
        cop.withValue(ScraperStore.Episode.Director.NAME, director);
        cop.withValueBackReference(ScraperStore.Episode.Director.EPISODE, firstIndex);
        list.add(cop.build());
    }

    for(String actorName: mActors.keySet()) {
        cop = ContentProviderOperation.newInsert(ScraperStore.Actor.URI.EPISODE);
        cop.withValue(ScraperStore.Episode.Actor.NAME, actorName);
        cop.withValueBackReference(ScraperStore.Episode.Actor.EPISODE, firstIndex);
        cop.withValue(ScraperStore.Episode.Actor.ROLE, mActors.get(actorName));
        list.add(cop.build());
    }
}