Search in sources :

Example 1 with ImageListElement

use of com.thebluealliance.androidclient.listitems.ImageListElement in project the-blue-alliance-android by the-blue-alliance.

the class MatchInfoSubscriberTest method testParsedData.

@Test
public void testParsedData() {
    List<ListItem> data = DatafeedTestDriver.getParsedData(mSubscriber, mData);
    assertEquals(3, data.size());
    assertTrue(data.get(0) instanceof MatchListElement);
    assertTrue(data.get(1) instanceof ImageListElement);
    Media videoItem = ((Match.MatchVideo) mData.match.getVideos().get(0)).asMedia();
    ImageListElement video = (ImageListElement) data.get(1);
    verify(mRenderer).renderFromModel(mData.match, MatchRenderer.RENDER_MATCH_INFO);
    assertTrue(video.equals(mMediaRenderer.renderFromModel(videoItem, null)));
}
Also used : ImageListElement(com.thebluealliance.androidclient.listitems.ImageListElement) MatchListElement(com.thebluealliance.androidclient.listitems.MatchListElement) Media(com.thebluealliance.androidclient.models.Media) ListItem(com.thebluealliance.androidclient.listitems.ListItem) Test(org.junit.Test)

Example 2 with ImageListElement

use of com.thebluealliance.androidclient.listitems.ImageListElement in project the-blue-alliance-android by the-blue-alliance.

the class MediaRendererTest method testRenderFromModel.

@Test
public void testRenderFromModel() {
    ImageListElement listItem = mRenderer.renderFromModel(mMedia, null);
    assertNotNull(listItem);
    assertEquals(listItem.isVideo, mMediaType.isVideo());
    assertEquals(listItem.linkUrl, String.format(mMediaType.getLinkUrlPattern(), mMedia.getForeignKey()));
    if (mMediaType != MediaType.CD_PHOTO_THREAD) {
        assertEquals(listItem.imageUrl, String.format(mMediaType.getImageUrlPattern(), mMedia.getForeignKey()));
    } else {
        assertEquals(listItem.imageUrl, "https://www.chiefdelphi" + ".com/media/img/fe3/fe38d320428adf4f51ac969efb3db32c_m.jpg");
    }
}
Also used : ImageListElement(com.thebluealliance.androidclient.listitems.ImageListElement) Test(org.junit.Test)

Example 3 with ImageListElement

use of com.thebluealliance.androidclient.listitems.ImageListElement 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

ImageListElement (com.thebluealliance.androidclient.listitems.ImageListElement)3 Test (org.junit.Test)2 Nullable (androidx.annotation.Nullable)1 JsonObject (com.google.gson.JsonObject)1 ListItem (com.thebluealliance.androidclient.listitems.ListItem)1 MatchListElement (com.thebluealliance.androidclient.listitems.MatchListElement)1 Media (com.thebluealliance.androidclient.models.Media)1 MediaType (com.thebluealliance.androidclient.types.MediaType)1 Matcher (java.util.regex.Matcher)1