Search in sources :

Example 1 with MediaType

use of com.thebluealliance.androidclient.types.MediaType in project the-blue-alliance-android by the-blue-alliance.

the class TeamInfoSubscriber method parseData.

@Override
public void parseData() {
    mDataToBind = new TeamInfoBinder.Model();
    Map<MediaType, String> socialMediaByType = Utilities.getMapForPlatform(MediaType.class, String.class);
    Team team = mAPIData.team;
    List<Media> socialMedia = mAPIData.socialMedia;
    mDataToBind.teamKey = team.getKey();
    mDataToBind.fullName = team.getName();
    mDataToBind.nickname = team.getNickname();
    mDataToBind.teamNumber = team.getTeamNumber();
    mDataToBind.location = team.getLocation();
    if (team.getWebsite() != null) {
        mDataToBind.website = team.getWebsite();
    } else {
        mDataToBind.website = "";
    }
    if (team.getMotto() != null) {
        mDataToBind.motto = team.getMotto();
    } else {
        mDataToBind.motto = "";
    }
    // Separate social medias by type
    mDataToBind.socialMedia = socialMediaByType;
    for (int i = 0; socialMedia != null && i < socialMedia.size(); i++) {
        Media media = socialMedia.get(i);
        MediaType mediaType = MediaType.fromString(media.getType());
        socialMediaByType.put(mediaType, media.getForeignKey());
    }
    // CMP Pit Location Stuff
    mDataToBind.showPitLocation = PitLocationHelper.shouldShowPitLocation(mAppConfig);
    mDataToBind.pitLocation = PitLocationHelper.getPitLocation(mContext, team.getKey());
}
Also used : TeamInfoBinder(com.thebluealliance.androidclient.binders.TeamInfoBinder) Media(com.thebluealliance.androidclient.models.Media) MediaType(com.thebluealliance.androidclient.types.MediaType) Team(com.thebluealliance.androidclient.models.Team)

Example 2 with MediaType

use of com.thebluealliance.androidclient.types.MediaType in project the-blue-alliance-android by the-blue-alliance.

the class MediaListSubscriber method parseData.

@Override
public void parseData() {
    mDataToBind.clear();
    mPhotos.clear();
    mVideos.clear();
    String encodedAvatar = "";
    for (int i = 0; i < mAPIData.size(); i++) {
        Media media = mAPIData.get(i);
        MediaType mediaType = MediaType.fromString(media.getType());
        if (mediaType.isImage()) {
            mPhotos.children.add(media);
        } else if (mediaType.isVideo()) {
            mVideos.children.add(media);
        } else if (mediaType.isAvatar()) {
            encodedAvatar = media.getBase64Image();
        }
    }
    if (!mPhotos.children.isEmpty()) {
        mDataToBind.add(mPhotos);
    }
    if (!mVideos.children.isEmpty()) {
        mDataToBind.add(mVideos);
    }
    mEventBus.post(new TeamAvatarUpdateEvent(encodedAvatar));
}
Also used : Media(com.thebluealliance.androidclient.models.Media) MediaType(com.thebluealliance.androidclient.types.MediaType) TeamAvatarUpdateEvent(com.thebluealliance.androidclient.eventbus.TeamAvatarUpdateEvent)

Example 3 with MediaType

use of com.thebluealliance.androidclient.types.MediaType in project the-blue-alliance-android by the-blue-alliance.

the class MediaRenderer method renderFromModel.

@Override
@Nullable
public ImageListElement renderFromModel(Media media, Void aVoid) {
    String imageUrl;
    MediaType mediaType = MediaType.fromString(media.getType());
    String foreignKey = media.getForeignKey();
    String keyForUrl = foreignKey;
    /* Build the link of the remote image based on foreign key */
    switch(mediaType) {
        case CD_PHOTO_THREAD:
            JsonObject details = media.getDetailsJson();
            imageUrl = String.format(mediaType.getImageUrlPattern(), details.get("image_partial").getAsString().replace("_l.jpg", "_m.jpg"));
            break;
        case YOUTUBE:
            /* Need to account for timestamps in youtube foreign key
                     * Can be like <key>?start=1h15m3s or <key>?t=time or <key>#t=time
                     * Since foreign key is first param in yt.com/watch?v=blah, others need to be &
                     */
            keyForUrl = foreignKey.replace('?', '&').replace('#', '&');
            Matcher m = YOUTUBE_KEY_PATTERN.matcher(foreignKey);
            String cleanKey = m.find() ? m.group(1) : foreignKey;
            imageUrl = String.format(mediaType.getImageUrlPattern(), cleanKey);
            break;
        case IMGUR:
            imageUrl = String.format(mediaType.getImageUrlPattern(), foreignKey);
            break;
        default:
            imageUrl = "";
    }
    Boolean isVideo = mediaType == MediaType.YOUTUBE;
    String linkUrl = String.format(mediaType.getLinkUrlPattern(), keyForUrl);
    return new ImageListElement(imageUrl, linkUrl, isVideo);
}
Also used : ImageListElement(com.thebluealliance.androidclient.listitems.ImageListElement) Matcher(java.util.regex.Matcher) MediaType(com.thebluealliance.androidclient.types.MediaType) JsonObject(com.google.gson.JsonObject) Nullable(androidx.annotation.Nullable)

Aggregations

MediaType (com.thebluealliance.androidclient.types.MediaType)3 Media (com.thebluealliance.androidclient.models.Media)2 Nullable (androidx.annotation.Nullable)1 JsonObject (com.google.gson.JsonObject)1 TeamInfoBinder (com.thebluealliance.androidclient.binders.TeamInfoBinder)1 TeamAvatarUpdateEvent (com.thebluealliance.androidclient.eventbus.TeamAvatarUpdateEvent)1 ImageListElement (com.thebluealliance.androidclient.listitems.ImageListElement)1 Team (com.thebluealliance.androidclient.models.Team)1 Matcher (java.util.regex.Matcher)1