1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-24 01:25:50 +01:00

Deduplicate icon retrieval code

This commit is contained in:
Arjan Schrijver 2023-05-17 14:03:20 +02:00
parent b1a9adadc3
commit 0bba156bec
2 changed files with 6 additions and 4 deletions

View File

@ -80,6 +80,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil;
import nodomain.freeyourgadget.gadgetbridge.util.LimitedQueue;
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
import nodomain.freeyourgadget.gadgetbridge.util.PebbleUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
@ -966,7 +967,7 @@ public class NotificationListener extends NotificationListenerService {
// Otherwise, we go and attempt to find the color from the app icon.
Drawable icon;
try {
icon = getApplicationContext().getPackageManager().getApplicationIcon(appId);
icon = NotificationUtils.getAppIcon(getApplicationContext(), appId);
Objects.requireNonNull(icon);
} catch (Exception ex) {
// If we can't get the icon, we go with the default defined above.

View File

@ -47,6 +47,7 @@ import android.os.Messenger;
import android.os.RemoteException;
import android.widget.Toast;
import androidx.core.content.res.ResourcesCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.json.JSONArray;
@ -156,6 +157,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.workout.WorkoutRequestHandler;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.FactoryResetRequest;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
import nodomain.freeyourgadget.gadgetbridge.util.UriHelper;
@ -1279,11 +1281,10 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
Drawable icon = null;
if (notificationSpec.iconId != 0) {
Context sourcePackageContext = getContext().createPackageContext(sourceAppId, 0);
icon = sourcePackageContext.getResources().getDrawable(notificationSpec.iconId);
icon = ResourcesCompat.getDrawable(sourcePackageContext.getResources(), notificationSpec.iconId, null);
}
if (icon == null) {
PackageManager pm = getContext().getPackageManager();
icon = pm.getApplicationIcon(sourceAppId);
icon = NotificationUtils.getAppIcon(getContext(), sourceAppId);
}
Bitmap iconBitmap = convertDrawableToBitmap(icon);
appIconCache.put(sourceAppId, iconBitmap);