|
6 | 6 | import android.graphics.Bitmap; |
7 | 7 | import android.graphics.Color; |
8 | 8 | import android.graphics.drawable.Drawable; |
| 9 | +import android.os.Handler; |
| 10 | +import android.os.Looper; |
9 | 11 | import android.util.SparseBooleanArray; |
10 | 12 | import android.util.TypedValue; |
11 | 13 | import android.view.HapticFeedbackConstants; |
@@ -88,9 +90,29 @@ public void onBindViewHolder(LoyaltyCardListItemViewHolder inputHolder, Cursor i |
88 | 90 | inputHolder.mDivider.setVisibility(View.GONE); |
89 | 91 |
|
90 | 92 | LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(inputCursor); |
91 | | - Bitmap icon = Utils.retrieveCardImage(mContext, loyaltyCard.id, ImageLocationType.icon); |
92 | 93 |
|
93 | | - if (mLoyaltyCardListDisplayOptions.showingNameBelowThumbnail() && icon != null) { |
| 94 | + inputHolder.mCardIcon.setContentDescription(loyaltyCard.store); |
| 95 | + |
| 96 | + // Default header at first, real icon will be retrieved asynchronously if it exists to ensure |
| 97 | + // smooth scrolling even on slower devices |
| 98 | + Utils.setIconOrTextWithBackground(mContext, loyaltyCard, null, inputHolder.mCardIcon, inputHolder.mCardText); |
| 99 | + inputHolder.toggleCardStateIcon(loyaltyCard.starStatus != 0, loyaltyCard.archiveStatus != 0, itemSelected(inputCursor.getPosition())); |
| 100 | + boolean hasIcon = Utils.retrieveCardImageAsFile(mContext, loyaltyCard.id, ImageLocationType.icon).exists(); |
| 101 | + if (hasIcon) { |
| 102 | + new Thread() { |
| 103 | + @Override |
| 104 | + public void run() { |
| 105 | + Bitmap icon = Utils.retrieveCardImage(mContext, loyaltyCard.id, ImageLocationType.icon); |
| 106 | + |
| 107 | + new Handler(Looper.getMainLooper()).post(() -> { |
| 108 | + inputHolder.mIconBackgroundColor = Utils.setIconOrTextWithBackground(mContext, loyaltyCard, icon, inputHolder.mCardIcon, inputHolder.mCardText); |
| 109 | + inputHolder.toggleCardStateIcon(loyaltyCard.starStatus != 0, loyaltyCard.archiveStatus != 0, itemSelected(inputHolder.getAdapterPosition())); |
| 110 | + }); |
| 111 | + } |
| 112 | + }.start(); |
| 113 | + } |
| 114 | + |
| 115 | + if (mLoyaltyCardListDisplayOptions.showingNameBelowThumbnail() && hasIcon) { |
94 | 116 | showDivider = true; |
95 | 117 | inputHolder.setStoreField(loyaltyCard.store); |
96 | 118 | } else { |
@@ -122,11 +144,6 @@ public void onBindViewHolder(LoyaltyCardListItemViewHolder inputHolder, Cursor i |
122 | 144 | inputHolder.setExtraField(inputHolder.mExpiryField, null, null, false); |
123 | 145 | } |
124 | 146 |
|
125 | | - inputHolder.mCardIcon.setContentDescription(loyaltyCard.store); |
126 | | - inputHolder.mIconBackgroundColor = Utils.setIconOrTextWithBackground(mContext, loyaltyCard, icon, inputHolder.mCardIcon, inputHolder.mCardText); |
127 | | - |
128 | | - inputHolder.toggleCardStateIcon(loyaltyCard.starStatus != 0, loyaltyCard.archiveStatus != 0, itemSelected(inputCursor.getPosition())); |
129 | | - |
130 | 147 | inputHolder.itemView.setActivated(mSelectedItems.get(inputCursor.getPosition(), false)); |
131 | 148 | applyIconAnimation(inputHolder, inputCursor.getPosition()); |
132 | 149 | applyClickEvents(inputHolder, inputCursor.getPosition()); |
|
0 commit comments