Commit 98f73d4b authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Download Home : Added support for full width image

As per the UX, when there is only one image for a date, the image
should span across the full screen width. Using adjustViewBounds property
of ImageView to readjust the height of the image when in full width mode.

Bug: 868567
Change-Id: Ia6ddf860e3168fda49f5bbf6a1043004e91bd663
Reviewed-on: https://chromium-review.googlesource.com/1162625
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581110}
parent f046d71b
...@@ -9,16 +9,17 @@ ...@@ -9,16 +9,17 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:clickable="true" android:clickable="true"
android:background="@color/modern_primary_color" > android:background="@color/google_grey_100" >
<ImageView <ImageView
android:id="@+id/thumbnail" android:id="@+id/thumbnail"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/download_manager_image_width" android:layout_height="wrap_content"
android:scaleType="centerCrop" android:scaleType="centerCrop"
android:layout_gravity="center" android:layout_gravity="center"
android:adjustViewBounds="true"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<org.chromium.chrome.browser.download.home.view.SelectionView <org.chromium.chrome.browser.download.home.view.SelectionView
......
...@@ -13,6 +13,7 @@ import org.chromium.chrome.browser.download.home.list.ListItem.OfflineItemListIt ...@@ -13,6 +13,7 @@ import org.chromium.chrome.browser.download.home.list.ListItem.OfflineItemListIt
import org.chromium.chrome.browser.download.home.list.ListItem.SectionHeaderListItem; import org.chromium.chrome.browser.download.home.list.ListItem.SectionHeaderListItem;
import org.chromium.chrome.browser.download.home.list.ListItem.SeparatorViewListItem; import org.chromium.chrome.browser.download.home.list.ListItem.SeparatorViewListItem;
import org.chromium.components.offline_items_collection.OfflineItem; import org.chromium.components.offline_items_collection.OfflineItem;
import org.chromium.components.offline_items_collection.OfflineItemFilter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
...@@ -150,8 +151,13 @@ class DateOrderedListMutator implements OfflineItemFilterObserver { ...@@ -150,8 +151,13 @@ class DateOrderedListMutator implements OfflineItemFilterObserver {
} }
// Add the items in the section. // Add the items in the section.
for (OfflineItem item : section.items.values()) { for (OfflineItem offlineItem : section.items.values()) {
listItems.add(new OfflineItemListItem(item)); OfflineItemListItem item = new OfflineItemListItem(offlineItem);
if (section.items.size() == 1
&& offlineItem.filter == OfflineItemFilter.FILTER_IMAGE) {
item.spanFullWidth = true;
}
listItems.add(item);
} }
// Add a section separator if needed. // Add a section separator if needed.
......
...@@ -132,6 +132,7 @@ public abstract class ListItem { ...@@ -132,6 +132,7 @@ public abstract class ListItem {
/** A {@link ListItem} that involves a {@link OfflineItem}. */ /** A {@link ListItem} that involves a {@link OfflineItem}. */
public static class OfflineItemListItem extends DateListItem { public static class OfflineItemListItem extends DateListItem {
public final OfflineItem item; public final OfflineItem item;
public boolean spanFullWidth;
/** Creates an {@link OfflineItemListItem} wrapping {@code item}. */ /** Creates an {@link OfflineItemListItem} wrapping {@code item}. */
public OfflineItemListItem(OfflineItem item) { public OfflineItemListItem(OfflineItem item) {
......
...@@ -120,6 +120,10 @@ public class ListUtils { ...@@ -120,6 +120,10 @@ public class ListUtils {
* @see GridLayoutManager.SpanSizeLookup * @see GridLayoutManager.SpanSizeLookup
*/ */
public static int getSpanSize(ListItem item, int spanCount) { public static int getSpanSize(ListItem item, int spanCount) {
if (item instanceof OfflineItemListItem && ((OfflineItemListItem) item).spanFullWidth) {
return spanCount;
}
return getViewTypeForItem(item) == ViewType.IMAGE ? 1 : spanCount; return getViewTypeForItem(item) == ViewType.IMAGE ? 1 : spanCount;
} }
} }
...@@ -14,8 +14,7 @@ import org.chromium.chrome.browser.modelutil.PropertyModel; ...@@ -14,8 +14,7 @@ import org.chromium.chrome.browser.modelutil.PropertyModel;
/** A {@link RecyclerView.ViewHolder} that holds a {@link View} that is opaque to the holder. */ /** A {@link RecyclerView.ViewHolder} that holds a {@link View} that is opaque to the holder. */
public class CustomViewHolder extends ListItemViewHolder { public class CustomViewHolder extends ListItemViewHolder {
/** Creates a new {@link org.chromium.chrome.browser.download.home.list.holder.CustomViewHolder} /** Creates a new {@link CustomViewHolder} instance. */
* instance. */
public CustomViewHolder(ViewGroup parent) { public CustomViewHolder(ViewGroup parent) {
super(new FrameLayout(parent.getContext())); super(new FrameLayout(parent.getContext()));
itemView.setLayoutParams(new ViewGroup.LayoutParams( itemView.setLayoutParams(new ViewGroup.LayoutParams(
......
...@@ -16,8 +16,7 @@ import org.chromium.chrome.browser.modelutil.PropertyModel; ...@@ -16,8 +16,7 @@ import org.chromium.chrome.browser.modelutil.PropertyModel;
/** A {@link RecyclerView.ViewHolder} specifically meant to display a date header. */ /** A {@link RecyclerView.ViewHolder} specifically meant to display a date header. */
public class DateViewHolder extends ListItemViewHolder { public class DateViewHolder extends ListItemViewHolder {
/** Creates a new {@link org.chromium.chrome.browser.download.home.list.holder.DateViewHolder} /** Creates a new {@link DateViewHolder} instance. */
* instance. */
public static org.chromium.chrome.browser.download.home.list.holder.DateViewHolder create( public static org.chromium.chrome.browser.download.home.list.holder.DateViewHolder create(
ViewGroup parent) { ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext()) View view = LayoutInflater.from(parent.getContext())
......
...@@ -38,16 +38,13 @@ public class GenericViewHolder extends ThumbnailAwareViewHolder { ...@@ -38,16 +38,13 @@ public class GenericViewHolder extends ThumbnailAwareViewHolder {
/** The icon to use when there is no thumbnail. */ /** The icon to use when there is no thumbnail. */
private @DrawableRes int mIconId = INVALID_ID; private @DrawableRes int mIconId = INVALID_ID;
/** Creates a new {@link /** Creates a new {@link GenericViewHolder} instance. */
* org.chromium.chrome.browser.download.home.list.holder.GenericViewHolder} instance. */ public static GenericViewHolder create(ViewGroup parent) {
public static org.chromium.chrome.browser.download.home.list.holder.GenericViewHolder create(
ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext()) View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.download_manager_generic_item, null); .inflate(R.layout.download_manager_generic_item, null);
int imageSize = parent.getContext().getResources().getDimensionPixelSize( int imageSize = parent.getContext().getResources().getDimensionPixelSize(
R.dimen.download_manager_generic_thumbnail_size); R.dimen.download_manager_generic_thumbnail_size);
return new org.chromium.chrome.browser.download.home.list.holder.GenericViewHolder( return new GenericViewHolder(view, imageSize);
view, imageSize);
} }
private GenericViewHolder(View view, int thumbnailSizePx) { private GenericViewHolder(View view, int thumbnailSizePx) {
......
...@@ -16,18 +16,19 @@ import org.chromium.components.offline_items_collection.OfflineItemVisuals; ...@@ -16,18 +16,19 @@ import org.chromium.components.offline_items_collection.OfflineItemVisuals;
/** A {@link RecyclerView.ViewHolder} specifically meant to display an image {@code OfflineItem}. */ /** A {@link RecyclerView.ViewHolder} specifically meant to display an image {@code OfflineItem}. */
public class ImageViewHolder extends ThumbnailAwareViewHolder { public class ImageViewHolder extends ThumbnailAwareViewHolder {
public static org.chromium.chrome.browser.download.home.list.holder.ImageViewHolder create( private final int mImageHeightPx;
ViewGroup parent) {
public static ImageViewHolder create(ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext()) View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.download_manager_image_item, null); .inflate(R.layout.download_manager_image_item, null);
int imageSize = parent.getContext().getResources().getDimensionPixelSize( int imageSize = parent.getContext().getResources().getDimensionPixelSize(
R.dimen.download_manager_image_width); R.dimen.download_manager_image_width);
return new org.chromium.chrome.browser.download.home.list.holder.ImageViewHolder( return new ImageViewHolder(view, imageSize);
view, imageSize);
} }
public ImageViewHolder(View view, int thumbnailSizePx) { public ImageViewHolder(View view, int thumbnailSizePx) {
super(view, thumbnailSizePx, thumbnailSizePx); super(view, thumbnailSizePx, thumbnailSizePx);
mImageHeightPx = thumbnailSizePx;
} }
// ThumbnailAwareViewHolder implementation. // ThumbnailAwareViewHolder implementation.
...@@ -37,6 +38,9 @@ public class ImageViewHolder extends ThumbnailAwareViewHolder { ...@@ -37,6 +38,9 @@ public class ImageViewHolder extends ThumbnailAwareViewHolder {
ListItem.OfflineItemListItem offlineItem = (ListItem.OfflineItemListItem) item; ListItem.OfflineItemListItem offlineItem = (ListItem.OfflineItemListItem) item;
View imageView = itemView.findViewById(R.id.thumbnail); View imageView = itemView.findViewById(R.id.thumbnail);
imageView.setContentDescription(offlineItem.item.title); imageView.setContentDescription(offlineItem.item.title);
ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
layoutParams.height =
offlineItem.spanFullWidth ? ViewGroup.LayoutParams.WRAP_CONTENT : mImageHeightPx;
} }
@Override @Override
......
...@@ -18,8 +18,10 @@ import org.chromium.chrome.browser.modelutil.PropertyModel; ...@@ -18,8 +18,10 @@ import org.chromium.chrome.browser.modelutil.PropertyModel;
import org.chromium.chrome.browser.widget.TintedImageButton; import org.chromium.chrome.browser.widget.TintedImageButton;
import org.chromium.components.offline_items_collection.OfflineItemState; import org.chromium.components.offline_items_collection.OfflineItemState;
/** A {@link RecyclerView.ViewHolder} specifically meant to display an in-progress {@code /**
* OfflineItem}. */ * A {@link RecyclerView.ViewHolder} specifically meant to display an in-progress {@code
* OfflineItem}.
*/
public class InProgressViewHolder extends ListItemViewHolder { public class InProgressViewHolder extends ListItemViewHolder {
private final ProgressBar mProgressBar; private final ProgressBar mProgressBar;
private final TextView mTitle; private final TextView mTitle;
...@@ -28,20 +30,15 @@ public class InProgressViewHolder extends ListItemViewHolder { ...@@ -28,20 +30,15 @@ public class InProgressViewHolder extends ListItemViewHolder {
private final TintedImageButton mCancelButton; private final TintedImageButton mCancelButton;
/** /**
* Creates a new {@link * Creates a new {@link InProgressViewHolder} instance.
* org.chromium.chrome.browser.download.home.list.holder.InProgressViewHolder} instance.
*/ */
public static org.chromium.chrome.browser.download.home.list.holder.InProgressViewHolder create( public static InProgressViewHolder create(ViewGroup parent) {
ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext()) View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.download_manager_in_progress_item, null); .inflate(R.layout.download_manager_in_progress_item, null);
return new org.chromium.chrome.browser.download.home.list.holder.InProgressViewHolder(view); return new InProgressViewHolder(view);
} }
/** /** Constructor. */
* Creates a new {@link
* org.chromium.chrome.browser.download.home.list.holder.InProgressViewHolder} instance.
*/
public InProgressViewHolder(View view) { public InProgressViewHolder(View view) {
super(view); super(view);
mProgressBar = view.findViewById(R.id.progress_bar); mProgressBar = view.findViewById(R.id.progress_bar);
......
...@@ -25,17 +25,14 @@ public class PrefetchViewHolder extends ThumbnailAwareViewHolder { ...@@ -25,17 +25,14 @@ public class PrefetchViewHolder extends ThumbnailAwareViewHolder {
private final TextView mTimestamp; private final TextView mTimestamp;
/** /**
* Creates a new instance of a {@link * Creates a new instance of a {@link PrefetchViewHolder}.
* org.chromium.chrome.browser.download.home.list.holder.PrefetchViewHolder}.
*/ */
public static org.chromium.chrome.browser.download.home.list.holder.PrefetchViewHolder create( public static PrefetchViewHolder create(ViewGroup parent) {
ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext()) View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.download_manager_prefetch_item, null); .inflate(R.layout.download_manager_prefetch_item, null);
int imageSize = parent.getContext().getResources().getDimensionPixelSize( int imageSize = parent.getContext().getResources().getDimensionPixelSize(
R.dimen.download_manager_prefetch_thumbnail_size); R.dimen.download_manager_prefetch_thumbnail_size);
return new org.chromium.chrome.browser.download.home.list.holder.PrefetchViewHolder( return new PrefetchViewHolder(view, imageSize);
view, imageSize);
} }
private PrefetchViewHolder(View view, int thumbnailSizePx) { private PrefetchViewHolder(View view, int thumbnailSizePx) {
......
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