@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: + ".com/media/img/fe3/fe38d320428adf4f51ac969efb3db32c_m.jpg"); } }
@Override public @Nullable ImageListElement renderFromModel(Media media, Void aVoid) { String imageUrl; MediaType mediaType = MediaType.fromString(media.getType()); String foreignKey = media.getForeignKey(); String keyForUrl = foreignKey; 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: 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); }
MediaRenderer implements ModelRenderer<Media, Void> { @Override public @Nullable ImageListElement renderFromModel(Media media, Void aVoid) { String imageUrl; MediaType mediaType = MediaType.fromString(media.getType()); String foreignKey = media.getForeignKey(); String keyForUrl = foreignKey; 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: 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); } }
MediaRenderer implements ModelRenderer<Media, Void> { @Override public @Nullable ImageListElement renderFromModel(Media media, Void aVoid) { String imageUrl; MediaType mediaType = MediaType.fromString(media.getType()); String foreignKey = media.getForeignKey(); String keyForUrl = foreignKey; 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: 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); } @Inject  MediaRenderer(); }
MediaRenderer implements ModelRenderer<Media, Void> { @Override public @Nullable ImageListElement renderFromModel(Media media, Void aVoid) { String imageUrl; MediaType mediaType = MediaType.fromString(media.getType()); String foreignKey = media.getForeignKey(); String keyForUrl = foreignKey; 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: 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); } @Inject  MediaRenderer(); @Override @Nullable ListElement renderFromKey(String key, ModelType type, Void args); @Override @Nullable ImageListElement renderFromModel(Media media, Void aVoid); }
MediaRenderer implements ModelRenderer<Media, Void> { @Override public @Nullable ImageListElement renderFromModel(Media media, Void aVoid) { String imageUrl; MediaType mediaType = MediaType.fromString(media.getType()); String foreignKey = media.getForeignKey(); String keyForUrl = foreignKey; 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: 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); } @Inject  MediaRenderer(); @Override @Nullable ListElement renderFromKey(String key, ModelType type, Void args); @Override @Nullable ImageListElement renderFromModel(Media media, Void aVoid);  }