Commit 751cd6a7 authored by David Trainor's avatar David Trainor Committed by Commit Bot

Add OfflineItem#ignore_visuals support.

Add a way for OfflineContentProviders to synchronously tell the front
end to ignore high quality visuals for a particular OfflineItem.  This
lets the UI layer optimize around this fact and not show asynchronous
loading images.

This should apply to both notifications and downloads home.

Bug: 1001208

Change-Id: I49fd6b5388b1f9ffe1b87856015a593e1b9ce5a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1786664
Commit-Queue: David Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarCarlos Knippschild <carlosk@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695699}
parent 8479e279
......@@ -32,11 +32,15 @@
style="@style/AsyncImageView"
tools:ignore="ContentDescription" />
<org.chromium.chrome.browser.download.home.view.SelectionView
android:id="@+id/selection"
style="@style/DownloadItemSelectionView"
<!-- Add a spacer so that even if the thumbnail is hidden the other elements
are still spaced correctly. This view matches the padding of the
thumbnail. -->
<Space
android:layout_width="10dp"
android:layout_height="114dp"
app:layout_column="0"
app:layout_row="0"/>
app:layout_row="0"
app:layout_rowSpan="4" />
<Space
android:layout_width="wrap_content"
......@@ -107,4 +111,20 @@
android:paddingTop="12dp"
app:layout_column="3"
app:layout_row="0" />
<!-- Wrap this in a FrameLayout so that if the thumbnail is hidden this view
does not negatively affect layout. The FrameLayout spans the whole
parent so it will not impact the rest of the views. -->
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_gravity="fill"
app:layout_column="0"
app:layout_row="0"
app:layout_columnSpan="4"
app:layout_rowSpan="4">
<org.chromium.chrome.browser.download.home.view.SelectionView
android:id="@+id/selection"
style="@style/DownloadItemSelectionView"/>
</FrameLayout>
</android.support.v7.widget.GridLayout>
......@@ -99,14 +99,20 @@ class OfflineItemViewHolder extends ListItemViewHolder implements ListMenuButton
// Push 'thumbnail' state.
if (mThumbnail != null) {
mThumbnail.setImageResizer(
new BitmapResizer(mThumbnail, Filters.fromOfflineItem(offlineItem)));
mThumbnail.setAsyncImageDrawable((consumer, width, height) -> {
return properties.get(ListProperties.PROVIDER_VISUALS)
.getVisuals(offlineItem, width, height, (id, visuals) -> {
consumer.onResult(onThumbnailRetrieved(visuals));
});
}, offlineItem.id);
if (offlineItem.ignoreVisuals) {
mThumbnail.setVisibility(View.GONE);
mThumbnail.setImageDrawable(null);
} else {
mThumbnail.setVisibility(View.VISIBLE);
mThumbnail.setImageResizer(
new BitmapResizer(mThumbnail, Filters.fromOfflineItem(offlineItem)));
mThumbnail.setAsyncImageDrawable((consumer, width, height) -> {
return properties.get(ListProperties.PROVIDER_VISUALS)
.getVisuals(offlineItem, width, height, (id, visuals) -> {
consumer.onResult(onThumbnailRetrieved(visuals));
});
}, offlineItem.id);
}
}
mCanRename = mRenameCallback != null && offlineItem.canRename;
......
......@@ -182,6 +182,7 @@ public class OfflineContentAggregatorNotificationBridgeUi
}
private boolean needsVisualsForUi(OfflineItem item) {
if (item.ignoreVisuals) return false;
switch (item.state) {
case OfflineItemState.IN_PROGRESS:
case OfflineItemState.PENDING:
......@@ -197,6 +198,7 @@ public class OfflineContentAggregatorNotificationBridgeUi
}
private boolean shouldCacheVisuals(OfflineItem item) {
if (item.ignoreVisuals) return false;
switch (item.state) {
case OfflineItemState.IN_PROGRESS:
case OfflineItemState.PENDING:
......
......@@ -76,6 +76,7 @@ public class OfflineItem implements Cloneable {
public boolean isAccelerated;
public boolean promoteOrigin;
public boolean canRename;
public boolean ignoreVisuals;
// Content Metadata.
public long totalSizeBytes;
......@@ -132,6 +133,7 @@ public class OfflineItem implements Cloneable {
clone.filePath = filePath;
clone.mimeType = mimeType;
clone.canRename = canRename;
clone.ignoreVisuals = ignoreVisuals;
clone.pageUrl = pageUrl;
clone.originalUrl = originalUrl;
clone.isOffTheRecord = isOffTheRecord;
......
......@@ -53,7 +53,7 @@ public final class OfflineItemBridge {
@PendingState int pendingState, boolean isResumable, boolean allowMetered,
long receivedBytes, long progressValue, long progressMax,
@OfflineItemProgressUnit int progressUnit, long timeRemainingMs, boolean isDangerous,
boolean canRename) {
boolean canRename, boolean ignoreVisuals) {
OfflineItem item = new OfflineItem();
item.id.namespace = nameSpace;
item.id.id = id;
......@@ -85,6 +85,7 @@ public final class OfflineItemBridge {
item.timeRemainingMs = timeRemainingMs;
item.isDangerous = isDangerous;
item.canRename = canRename;
item.ignoreVisuals = ignoreVisuals;
if (list != null) list.add(item);
return item;
}
......
......@@ -44,7 +44,8 @@ JNI_OfflineItemBridge_createOfflineItemAndMaybeAddToList(
static_cast<jint>(item.pending_state), item.is_resumable,
item.allow_metered, item.received_bytes, item.progress.value,
item.progress.max.value_or(-1), static_cast<jint>(item.progress.unit),
item.time_remaining_ms, item.is_dangerous, item.can_rename);
item.time_remaining_ms, item.is_dangerous, item.can_rename,
item.ignore_visuals);
}
} // namespace
......
......@@ -45,6 +45,7 @@ OfflineItem::OfflineItem()
is_accelerated(false),
promote_origin(false),
can_rename(false),
ignore_visuals(false),
total_size_bytes(0),
externally_removed(false),
is_openable(false),
......@@ -75,6 +76,7 @@ bool OfflineItem::operator==(const OfflineItem& offline_item) const {
is_accelerated == offline_item.is_accelerated &&
promote_origin == offline_item.promote_origin &&
can_rename == offline_item.can_rename &&
ignore_visuals == offline_item.ignore_visuals &&
total_size_bytes == offline_item.total_size_bytes &&
externally_removed == offline_item.externally_removed &&
creation_time == offline_item.creation_time &&
......
......@@ -122,6 +122,12 @@ struct OfflineItem {
// Whether or not this item can be renamed.
bool can_rename;
// Whether or not to bother querying for visuals. Querying is not guaranteed
// to return anything, but if this is |true| the UI layers can make
// optimizations without waiting for the asynchronous query for visual
// information.
bool ignore_visuals;
// TODO(dtrainor): Build out custom per-item icon support.
// Content Metadata.
......
......@@ -67,6 +67,7 @@ OfflineItem OfflineItemConversions::CreateOfflineItem(
item.description = page.snippet;
item.attribution = page.attribution;
// TODO(carlosk): Set item.ignore_visuals here to the right thing.
return item;
}
......
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