Use card icon image if available

This commit is contained in:
Sylvia van Os
2021-11-23 23:24:36 +01:00
parent 49200fff48
commit f633fb39aa

View File

@@ -1,8 +1,10 @@
package protect.card_locker;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.service.controls.Control;
@@ -43,7 +45,7 @@ public class CardsOnPowerScreenService extends ControlsProviderService {
.setTitle(card.store)
.setDeviceType(DeviceTypes.TYPE_GENERIC_OPEN_CLOSE)
.setSubtitle(card.note)
.setCustomIcon(Icon.createWithBitmap(Utils.generateIcon(this, card.store, card.headerColor).getLetterTile()))
.setCustomIcon(Icon.createWithBitmap(getIcon(this, card)))
.build()
);
}
@@ -71,7 +73,7 @@ public class CardsOnPowerScreenService extends ControlsProviderService {
.setSubtitle(card.note)
.setStatus(Control.STATUS_OK)
.setControlTemplate(new StatelessTemplate(controlId))
.setCustomIcon(Icon.createWithBitmap(Utils.generateIcon(this, card.store, card.headerColor).getLetterTile()))
.setCustomIcon(Icon.createWithBitmap(getIcon(this, card)))
.build();
Log.d(TAG, "Dispatching widget " + controlId);
subscriber.onNext(ret);
@@ -80,6 +82,16 @@ public class CardsOnPowerScreenService extends ControlsProviderService {
};
}
private Bitmap getIcon(Context context, LoyaltyCard loyaltyCard) {
Bitmap cardIcon = Utils.retrieveCardImage(context, loyaltyCard.id, ImageLocationType.icon);
if (cardIcon != null) {
return cardIcon;
}
return Utils.generateIcon(this, loyaltyCard.store, loyaltyCard.headerColor).getLetterTile();
}
private Integer controlIdToCardId(String controlId) {
if (controlId == null)
return null;