From 5957f71110946409f3eed8ea05322b437eba4fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Thu, 15 Jun 2023 22:01:16 +0100 Subject: [PATCH] App Manager: Fill out missing app info from cache --- .../AbstractAppManagerFragment.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java index 6d4860f47..5ebd47526 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java @@ -41,6 +41,7 @@ import android.widget.Toast; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import org.apache.commons.lang3.StringUtils; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -134,6 +135,8 @@ public abstract class AbstractAppManagerFragment extends Fragment { } private void refreshListFromDevice(Intent intent) { + final Map cachedAppsMap = getCachedAppsMap(null); + appList.clear(); int appCount = intent.getIntExtra("app_count", 0); for (int i = 0; i < appCount; i++) { @@ -144,6 +147,22 @@ public abstract class AbstractAppManagerFragment extends Fragment { GBDeviceApp.Type appType = GBDeviceApp.Type.values()[intent.getIntExtra("app_type" + i, 0)]; Bitmap previewImage = getAppPreviewImage(uuid.toString()); + // Fill out information from the cached app if missing + final GBDeviceApp cachedApp = cachedAppsMap.get(uuid); + if (cachedApp != null) { + if (StringUtils.isBlank(appName)) { + appName = cachedApp.getName(); + } + if (StringUtils.isBlank(appCreator)) { + appCreator = cachedApp.getCreator(); + } + } else { + if (StringUtils.isBlank(appName)) { + // If the app does not have a name, fallback to uuid + appName = uuid.toString(); + } + } + GBDeviceApp app = new GBDeviceApp(uuid, appName, appCreator, appVersion, appType, previewImage); app.setOnDevice(true); if (mGBDevice.getType() == DeviceType.FOSSILQHYBRID) { @@ -243,6 +262,15 @@ public abstract class AbstractAppManagerFragment extends Fragment { } }; + protected Map getCachedAppsMap(final List uuids) { + final List cachedApps = getCachedApps(uuids); + final Map cachedAppsMap = new HashMap<>(); + for (GBDeviceApp cachedApp : cachedApps) { + cachedAppsMap.put(cachedApp.getUUID(), cachedApp); + } + return cachedAppsMap; + } + protected List getCachedApps(List uuids) { List cachedAppList = new ArrayList<>(); File cachePath;