1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

App Manager: Fill out missing app info from cache

This commit is contained in:
José Rebelo 2023-06-15 22:01:16 +01:00
parent 9b7d5eee42
commit 5957f71110

View File

@ -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<UUID, GBDeviceApp> 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<UUID, GBDeviceApp> getCachedAppsMap(final List<UUID> uuids) {
final List<GBDeviceApp> cachedApps = getCachedApps(uuids);
final Map<UUID, GBDeviceApp> cachedAppsMap = new HashMap<>();
for (GBDeviceApp cachedApp : cachedApps) {
cachedAppsMap.put(cachedApp.getUUID(), cachedApp);
}
return cachedAppsMap;
}
protected List<GBDeviceApp> getCachedApps(List<UUID> uuids) {
List<GBDeviceApp> cachedAppList = new ArrayList<>();
File cachePath;