Commit a4402939 authored by David Trainor's avatar David Trainor Committed by Commit Bot

Clean up the generic item holder for downloads home v2

Address some issues with how the generic item holder was building

- Fix AsyncImageView not properly showing the unavailable drawable
(rebase issue).
- Fix issue with progress.getPercentage() being called on an
indeterminate progress state.
- Make sure we properly show the grey circle around the generic icon.
- Add a way to not wrap a drawable with an animator if there is nothing
to animate.

thumbnails: 
Change-Id: I3bd15451af234e8291d886d4c3df64d696a41ac6
Reviewed-on: https://chromium-review.googlesource.com/c/1258349
Commit-Queue: David Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596501}
parent db5e0106
......@@ -229,7 +229,8 @@ public final class UiUtils {
public static void setProgressForOfflineItem(CircularProgressView view, OfflineItem item) {
Progress progress = item.progress;
final boolean indeterminate = progress != null && progress.isIndeterminate();
final int determinateProgress = progress != null ? progress.getPercentage() : 0;
final int determinateProgress =
progress != null && !indeterminate ? progress.getPercentage() : 0;
final int activeProgress =
indeterminate ? CircularProgressView.INDETERMINATE : determinateProgress;
final int inactiveProgress = indeterminate ? 0 : determinateProgress;
......
......@@ -63,37 +63,43 @@ public class GenericViewHolder extends OfflineItemViewHolder {
if (iconId != mGenericIconId) {
mGenericIconId = iconId;
Drawable icon = DrawableCompat.wrap(
ApiCompatibilityUtils.getDrawable(itemView.getResources(), mGenericIconId));
DrawableCompat.setTintList(icon,
Drawable drawable = DrawableCompat.wrap(
ApiCompatibilityUtils.getDrawable(itemView.getResources(), iconId));
DrawableCompat.setTintList(drawable,
AppCompatResources.getColorStateList(
itemView.getContext(), R.color.dark_mode_tint));
mThumbnail.setUnavailableDrawable(icon);
mThumbnail.setWaitingDrawable(icon);
mThumbnail.setUnavailableDrawable(drawable);
mThumbnail.setWaitingDrawable(drawable);
}
mSelectionView.setVisibility(mSelectionView.isSelected() ? View.VISIBLE : View.INVISIBLE);
mThumbnail.setVisibility(mSelectionView.isSelected() ? View.INVISIBLE : View.VISIBLE);
updateThumbnailBackground(mThumbnail.getDrawable() != null);
}
@Override
protected Drawable onThumbnailRetrieved(OfflineItemVisuals visuals) {
Resources resources = itemView.getResources();
boolean hasThumbnail = visuals != null && visuals.icon != null;
updateThumbnailBackground(hasThumbnail);
RoundedBitmapDrawable drawable = null;
if (hasThumbnail) {
drawable = RoundedBitmapDrawableFactory.create(resources, visuals.icon);
drawable = RoundedBitmapDrawableFactory.create(itemView.getResources(), visuals.icon);
drawable.setCircular(true);
}
return drawable;
}
private void updateThumbnailBackground(boolean hasThumbnail) {
if (hasThumbnail) {
mThumbnail.setBackground(null);
} else {
mThumbnail.setBackgroundResource(R.drawable.list_item_icon_modern_bg);
mThumbnail.getBackground().setLevel(
resources.getInteger(R.integer.list_item_level_default));
} else if (mThumbnail.getBackground() == null) {
Resources resources = itemView.getResources();
Drawable background = ApiCompatibilityUtils.getDrawable(
resources, R.drawable.list_item_icon_modern_bg);
background.setLevel(resources.getInteger(R.integer.list_item_level_default));
mThumbnail.setBackground(background);
}
return drawable;
}
}
......@@ -142,8 +142,8 @@ public class AsyncImageView extends ForegroundRoundedCornerImageView {
mCancelable = null;
mWaitingForResponse = false;
setForegroundDrawableCompat(drawable == null ? mUnavailableDrawable : null);
setImageDrawable(drawable);
setForegroundDrawableCompat(drawable == null ? mUnavailableDrawable : null);
}
private void cancelPreviousDrawableRequest() {
......
......@@ -18,6 +18,8 @@ import android.support.annotation.Nullable;
import android.support.graphics.drawable.Animatable2Compat;
import android.support.v7.graphics.drawable.DrawableWrapper;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* A helper {@link Drawable} that wraps another {@link Drawable} and starts/stops any
* {@link Animatable} {@link Drawable}s in the {@link Drawable} hierarchy when this {@link Drawable}
......@@ -37,7 +39,7 @@ public class AutoAnimatorDrawable extends DrawableWrapper {
* {@code drawable} is {@code null}.
*/
public static Drawable wrap(@Nullable Drawable drawable) {
if (drawable == null) return null;
if (drawable == null || !shouldWrapDrawable(drawable)) return drawable;
return new AutoAnimatorDrawable(drawable);
}
......@@ -70,6 +72,12 @@ public class AutoAnimatorDrawable extends DrawableWrapper {
AutoAnimatorDrawable.animatedDrawableHelper(drawable, animatable -> animatable.stop());
}
private static boolean shouldWrapDrawable(@Nullable Drawable drawable) {
AtomicBoolean found = new AtomicBoolean();
AutoAnimatorDrawable.animatedDrawableHelper(drawable, animatable -> found.set(true));
return found.get();
}
@TargetApi(Build.VERSION_CODES.M)
private static void attachRestartListeners(@Nullable Drawable drawable) {
AutoAnimatorDrawable.animatedDrawableHelper(drawable, animatable -> {
......
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