Commit cd6c0632 authored by Sky Malice's avatar Sky Malice Committed by Commit Bot

[Feed] Remap offline and video badge assets.

Bug: 890007
Change-Id: I870130381eb5376ea0a9ecf5c2fc1ab5f8761f18
Reviewed-on: https://chromium-review.googlesource.com/c/1258310Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Sky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596384}
parent 621cef15
...@@ -9,13 +9,16 @@ import android.graphics.Bitmap; ...@@ -9,13 +9,16 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.DrawableRes;
import android.support.v7.content.res.AppCompatResources; import android.support.v7.content.res.AppCompatResources;
import android.text.TextUtils; import android.text.TextUtils;
import com.google.android.libraries.feed.common.functional.Consumer; import com.google.android.libraries.feed.common.functional.Consumer;
import com.google.android.libraries.feed.host.imageloader.BundledAssets;
import com.google.android.libraries.feed.host.imageloader.ImageLoaderApi; import com.google.android.libraries.feed.host.imageloader.ImageLoaderApi;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.suggestions.ThumbnailGradient; import org.chromium.chrome.browser.suggestions.ThumbnailGradient;
...@@ -129,11 +132,27 @@ public class FeedImageLoader implements ImageLoaderApi { ...@@ -129,11 +132,27 @@ public class FeedImageLoader implements ImageLoaderApi {
*/ */
private Drawable getAssetDrawable(String url) { private Drawable getAssetDrawable(String url) {
String resourceName = url.substring(ASSET_PREFIX.length()); String resourceName = url.substring(ASSET_PREFIX.length());
int id = mActivityContext.getResources().getIdentifier( @DrawableRes
resourceName, DRAWABLE_RESOURCE_TYPE, mActivityContext.getPackageName()); int id = lookupDrawableIdenfier(resourceName);
return id == 0 ? null : AppCompatResources.getDrawable(mActivityContext, id); return id == 0 ? null : AppCompatResources.getDrawable(mActivityContext, id);
} }
/**
* @param resourceName The name of the drawable asset.
* @return The id of the drawable asset. May be 0 if it could not be found.
*/
private @DrawableRes int lookupDrawableIdenfier(String resourceName) {
switch (resourceName) {
case BundledAssets.OFFLINE_INDICATOR_BADGE:
return R.drawable.offline_pin_round;
case BundledAssets.VIDEO_INDICATOR_BADGE:
return R.drawable.ic_play_circle_filled_grey;
default:
return mActivityContext.getResources().getIdentifier(
resourceName, DRAWABLE_RESOURCE_TYPE, mActivityContext.getPackageName());
}
}
/** /**
* Returns where the thumbnail is located in the card using the "direction" query param. * Returns where the thumbnail is located in the card using the "direction" query param.
* @param overlayImageUri The URI for the overlay image. * @param overlayImageUri The URI for the overlay image.
......
...@@ -16,6 +16,7 @@ import android.graphics.drawable.Drawable; ...@@ -16,6 +16,7 @@ import android.graphics.drawable.Drawable;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import com.google.android.libraries.feed.common.functional.Consumer; import com.google.android.libraries.feed.common.functional.Consumer;
import com.google.android.libraries.feed.host.imageloader.BundledAssets;
import com.google.android.libraries.feed.host.imageloader.ImageLoaderApi; import com.google.android.libraries.feed.host.imageloader.ImageLoaderApi;
import org.junit.Before; import org.junit.Before;
...@@ -44,19 +45,22 @@ import java.util.Arrays; ...@@ -44,19 +45,22 @@ import java.util.Arrays;
@RunWith(BaseRobolectricTestRunner.class) @RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
public class FeedImageLoaderTest { public class FeedImageLoaderTest {
public static final String HTTP_STRING1 = "http://www.test1.com"; private static final String HTTP_STRING1 = "http://www.test1.com";
public static final String HTTP_STRING2 = "http://www.test2.com"; private static final String HTTP_STRING2 = "http://www.test2.com";
public static final String HTTP_STRING3 = "http://www.test3.com"; private static final String HTTP_STRING3 = "http://www.test3.com";
public static final String ASSET_STRING = "asset://logo_avatar_anonymous";
public static final String BAD_ASSET_STRING = "asset://does_not_exist"; private static final String ASSET_PREFIX = "asset://";
public static final String OVERLAY_IMAGE_START = private static final String ASSET_STRING = ASSET_PREFIX + "logo_avatar_anonymous";
private static final String BAD_ASSET_STRING = ASSET_PREFIX + "does_not_exist";
private static final String OVERLAY_IMAGE_START =
"overlay-image://?direction=start&url=http://www.test1.com"; "overlay-image://?direction=start&url=http://www.test1.com";
public static final String OVERLAY_IMAGE_END = private static final String OVERLAY_IMAGE_END =
"overlay-image://?direction=end&url=http://www.test1.com"; "overlay-image://?direction=end&url=http://www.test1.com";
public static final String OVERLAY_IMAGE_MISSING_URL = "overlay-image://?direction=end"; private static final String OVERLAY_IMAGE_MISSING_URL = "overlay-image://?direction=end";
public static final String OVERLAY_IMAGE_MISSING_DIRECTION = private static final String OVERLAY_IMAGE_MISSING_DIRECTION =
"overlay-image://?url=http://www.test1.com"; "overlay-image://?url=http://www.test1.com";
public static final String OVERLAY_IMAGE_BAD_DIRECTION = private static final String OVERLAY_IMAGE_BAD_DIRECTION =
"overlay-image://?direction=east&url=http://www.test1.com"; "overlay-image://?direction=east&url=http://www.test1.com";
@Rule @Rule
...@@ -226,4 +230,18 @@ public class FeedImageLoaderTest { ...@@ -226,4 +230,18 @@ public class FeedImageLoaderTest {
public void overlayImageTest_BadDirection() { public void overlayImageTest_BadDirection() {
loadDrawable(OVERLAY_IMAGE_BAD_DIRECTION); loadDrawable(OVERLAY_IMAGE_BAD_DIRECTION);
} }
@Test
@SmallTest
public void testLoadOfflineBadge() {
loadDrawable(ASSET_PREFIX + BundledAssets.OFFLINE_INDICATOR_BADGE);
verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));
}
@Test
@SmallTest
public void testLoadVideoBadge() {
loadDrawable(ASSET_PREFIX + BundledAssets.VIDEO_INDICATOR_BADGE);
verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment