diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppManagerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppManagerActivity.java index 2e6bbba04..de5147e99 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppManagerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AppManagerActivity.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.ListIterator; import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.GBApplication; @@ -47,7 +48,6 @@ public class AppManagerActivity extends GBActivity { if (action.equals(GBApplication.ACTION_QUIT)) { finish(); } else if (action.equals(ACTION_REFRESH_APPLIST)) { - appList.clear(); int appCount = intent.getIntExtra("app_count", 0); for (Integer i = 0; i < appCount; i++) { String appName = intent.getStringExtra("app_name" + i.toString()); @@ -55,11 +55,21 @@ public class AppManagerActivity extends GBActivity { UUID uuid = UUID.fromString(intent.getStringExtra("app_uuid" + i.toString())); GBDeviceApp.Type appType = GBDeviceApp.Type.values()[intent.getIntExtra("app_type" + i.toString(), 0)]; - appList.add(new GBDeviceApp(uuid, appName, appCreator, "", appType)); - } - - if (prefs.getBoolean("pebble_force_untested", false)) { - appList.addAll(getSystemApps()); + boolean found = false; + for (final ListIterator iter = appList.listIterator(); iter.hasNext(); ) { + final GBDeviceApp app = iter.next(); + if (app.getUUID().equals(uuid)) { + app.setOnDevice(true); + iter.set(app); + found = true; + break; + } + } + if (!found) { + GBDeviceApp app = new GBDeviceApp(uuid, appName, appCreator, "", appType); + app.setOnDevice(true); + appList.add(app); + } } mGBDeviceAppAdapter.notifyDataSetChanged(); @@ -76,8 +86,10 @@ public class AppManagerActivity extends GBActivity { private List getSystemApps() { List systemApps = new ArrayList<>(); - systemApps.add(new GBDeviceApp(UUID.fromString("4dab81a6-d2fc-458a-992c-7a1f3b96a970"), "Sports (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); - systemApps.add(new GBDeviceApp(UUID.fromString("cf1e816a-9db0-4511-bbb8-f60c48ca8fac"), "Golf (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); + if (prefs.getBoolean("pebble_force_untested", false)) { + systemApps.add(new GBDeviceApp(UUID.fromString("4dab81a6-d2fc-458a-992c-7a1f3b96a970"), "Sports (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); + systemApps.add(new GBDeviceApp(UUID.fromString("cf1e816a-9db0-4511-bbb8-f60c48ca8fac"), "Golf (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); + } if (mGBDevice != null && !"aplite".equals(PebbleUtils.getPlatformName(mGBDevice.getHardwareVersion()))) { systemApps.add(new GBDeviceApp(PebbleProtocol.UUID_PEBBLE_HEALTH, "Health (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM)); } @@ -149,9 +161,7 @@ public class AppManagerActivity extends GBActivity { appList.addAll(getCachedApps()); - if (prefs.getBoolean("pebble_force_untested", false)) { - appList.addAll(getSystemApps()); - } + appList.addAll(getSystemApps()); IntentFilter filter = new IntentFilter(); filter.addAction(GBApplication.ACTION_QUIT); @@ -171,11 +181,13 @@ public class AppManagerActivity extends GBActivity { if (!selectedApp.isInCache()) { menu.removeItem(R.id.appmanager_app_reinstall); + menu.removeItem(R.id.appmanager_app_delete_cache); } if (!PebbleProtocol.UUID_PEBBLE_HEALTH.equals(selectedApp.getUUID())) { menu.removeItem(R.id.appmanager_health_activate); menu.removeItem(R.id.appmanager_health_deactivate); - } else if (PebbleProtocol.UUID_PEBBLE_HEALTH.equals(selectedApp.getUUID())) { + } + if (selectedApp.getType() == GBDeviceApp.Type.APP_SYSTEM) { menu.removeItem(R.id.appmanager_app_delete); } if (!selectedApp.isConfigurable()) { @@ -184,19 +196,45 @@ public class AppManagerActivity extends GBActivity { menu.setHeaderTitle(selectedApp.getName()); } + private void removeAppFromList(UUID uuid) { + for (final ListIterator iter = appList.listIterator(); iter.hasNext(); ) { + final GBDeviceApp app = iter.next(); + if (app.getUUID().equals(uuid)) { + iter.remove(); + mGBDeviceAppAdapter.notifyDataSetChanged(); + break; + } + } + } + @Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.appmanager_health_deactivate: + case R.id.appmanager_app_delete_cache: + File cachedFile = null; + boolean deleteSuccess = true; + try { + cachedFile = new File(FileUtils.getExternalFilesDir().getPath() + "/pbw-cache/" + selectedApp.getUUID() + ".pbw"); + deleteSuccess = cachedFile.delete(); + } catch (IOException e) { + LOG.warn("could not get external dir while trying to access pbw cache."); + } + if (!deleteSuccess) { + LOG.warn("could not delete file from pbw cache: " + cachedFile.toString()); + } + // fall through case R.id.appmanager_app_delete: - GBApplication.deviceService().onAppDelete(selectedApp.getUUID()); + UUID uuid = selectedApp.getUUID(); + GBApplication.deviceService().onAppDelete(uuid); + removeAppFromList(uuid); return true; case R.id.appmanager_app_reinstall: File cachePath; try { cachePath = new File(FileUtils.getExternalFilesDir().getPath() + "/pbw-cache/" + selectedApp.getUUID() + ".pbw"); } catch (IOException e) { - LOG.warn("could not get external dir while reading pbw cache."); + LOG.warn("could not get external dir while trying to access pbw cache."); return true; } GBApplication.deviceService().onInstallApp(Uri.fromFile(cachePath)); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAppAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAppAdapter.java index 5a8137926..d4ae263f3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAppAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/GBDeviceAppAdapter.java @@ -41,7 +41,15 @@ public class GBDeviceAppAdapter extends ArrayAdapter { ImageView deviceImageView = (ImageView) view.findViewById(R.id.item_image); deviceAppVersionAuthorLabel.setText(getContext().getString(R.string.appversion_by_creator, deviceApp.getVersion(), deviceApp.getCreator())); - deviceAppNameLabel.setText(deviceApp.getName()); + + // FIXME: replace with small icons + String appNameLabelText = deviceApp.getName(); + if (deviceApp.isInCache() || deviceApp.isOnDevice()) { + appNameLabelText += " (" + (deviceApp.isInCache() ? "C" : "") + + (deviceApp.isOnDevice() ? "D" : "") + ")"; + } + deviceAppNameLabel.setText(appNameLabelText); + switch (deviceApp.getType()) { case APP_GENERIC: deviceImageView.setImageResource(R.drawable.ic_watchapp); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java index 30becd117..9d66c0dbc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PBWInstallHandler.java @@ -129,10 +129,6 @@ public class PBWInstallHandler implements InstallHandler { return; } - if (!device.getFirmwareVersion().startsWith("v3")) { - return; - } - File destDir; GBDeviceApp app = mPBWReader.getGBDeviceApp(); try { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceApp.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceApp.java index d2280d177..f55876453 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceApp.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceApp.java @@ -12,6 +12,7 @@ public class GBDeviceApp { private final UUID uuid; private final Type type; private final boolean inCache; + private boolean isOnDevice; private final boolean configurable; public GBDeviceApp(UUID uuid, String name, String creator, String version, Type type) { @@ -23,6 +24,7 @@ public class GBDeviceApp { //FIXME: do not assume this.inCache = false; this.configurable = false; + this.isOnDevice = false; } public GBDeviceApp(JSONObject json, boolean configurable) { @@ -52,10 +54,18 @@ public class GBDeviceApp { this.configurable = configurable; } + public void setOnDevice(boolean isOnDevice) { + this.isOnDevice = isOnDevice; + } + public boolean isInCache() { return inCache; } + public boolean isOnDevice() { + return isOnDevice; + } + public String getName() { return name; } diff --git a/app/src/main/res/menu/appmanager_context.xml b/app/src/main/res/menu/appmanager_context.xml index dd5d22c3b..873e0c246 100644 --- a/app/src/main/res/menu/appmanager_context.xml +++ b/app/src/main/res/menu/appmanager_context.xml @@ -6,6 +6,9 @@ + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2e45536c7..7d0a9514d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,6 +17,7 @@ App Manager Delete + Delete and remove from cache Notification Blacklist @@ -255,5 +256,5 @@ Firmware not sent Heart Rate Heart Rate - + Reconnect automatically