Commit f6210015 authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Download home : Implemented image list item

Implemented image list item for the new download home.

Bug: 850595
Change-Id: Ie82086b6b619a9a9b17a2fc4a6da9d5341fe74dd
Reviewed-on: https://chromium-review.googlesource.com/1123159
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575539}
parent 027b1a7c
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:layout_gravity="center_vertical"
tools:ignore="ContentDescription" />
...@@ -107,7 +107,12 @@ class DateOrderedListView { ...@@ -107,7 +107,12 @@ class DateOrderedListView {
int availableWidth = getWidth() - mImagePaddingPx; int availableWidth = getWidth() - mImagePaddingPx;
int columnWidth = mImageWidthPx - mImagePaddingPx; int columnWidth = mImageWidthPx - mImagePaddingPx;
setSpanCount(Math.max(1, availableWidth / columnWidth));
int easyFitSpan = availableWidth / columnWidth;
double remaining =
((double) (availableWidth - easyFitSpan * columnWidth)) / columnWidth;
if (remaining > 0.5) easyFitSpan++;
setSpanCount(Math.max(1, easyFitSpan));
super.onLayoutChildren(recycler, state); super.onLayoutChildren(recycler, state);
} }
......
...@@ -60,7 +60,7 @@ abstract class ListItemViewHolder extends ViewHolder { ...@@ -60,7 +60,7 @@ abstract class ListItemViewHolder extends ViewHolder {
case ListUtils.ViewType.VIDEO: case ListUtils.ViewType.VIDEO:
return new VideoViewHolder(parent); return new VideoViewHolder(parent);
case ListUtils.ViewType.IMAGE: case ListUtils.ViewType.IMAGE:
return new ImageViewHolder(parent); return ImageViewHolder.create(parent);
case ListUtils.ViewType.CUSTOM_VIEW: case ListUtils.ViewType.CUSTOM_VIEW:
return new CustomViewHolder(parent); return new CustomViewHolder(parent);
case ListUtils.ViewType.PREFETCH: case ListUtils.ViewType.PREFETCH:
...@@ -232,16 +232,34 @@ abstract class ListItemViewHolder extends ViewHolder { ...@@ -232,16 +232,34 @@ abstract class ListItemViewHolder extends ViewHolder {
} }
/** A {@link ViewHolder} specifically meant to display an image {@code OfflineItem}. */ /** A {@link ViewHolder} specifically meant to display an image {@code OfflineItem}. */
public static class ImageViewHolder extends ListItemViewHolder { public static class ImageViewHolder extends ThumbnailAwareViewHolder {
public ImageViewHolder(ViewGroup parent) { public static ImageViewHolder create(ViewGroup parent) {
super(new AppCompatTextView(parent.getContext())); View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.download_manager_image_item, null);
int imageSize = parent.getContext().getResources().getDimensionPixelSize(
R.dimen.download_manager_image_width);
return new ImageViewHolder(view, imageSize);
} }
// ListItemViewHolder implementation. public ImageViewHolder(View view, int thumbnailSizePx) {
super(view, thumbnailSizePx, thumbnailSizePx);
}
// ThumbnailAwareViewHolder implementation.
@Override @Override
public void bind(ListPropertyModel properties, ListItem item) { public void bind(ListPropertyModel properties, ListItem item) {
super.bind(properties, item);
OfflineItemListItem offlineItem = (OfflineItemListItem) item; OfflineItemListItem offlineItem = (OfflineItemListItem) item;
((TextView) itemView).setText(offlineItem.item.title); View imageView = itemView.findViewById(R.id.thumbnail);
imageView.setContentDescription(offlineItem.item.title);
itemView.setOnClickListener(
v -> properties.getOpenCallback().onResult(offlineItem.item));
}
@Override
void onVisualsChanged(ImageView view, OfflineItemVisuals visuals) {
view.setImageBitmap(visuals == null ? null : visuals.icon);
} }
} }
......
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