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)));
}
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");
}
}
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);
}
Aggregations