2016-06-14 15:56:38 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities.appmanager;
|
2015-03-25 22:23:45 +01:00
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2016-01-02 12:24:23 +01:00
|
|
|
import android.net.Uri;
|
2015-03-25 22:23:45 +01:00
|
|
|
import android.os.Bundle;
|
2016-06-14 15:56:38 +02:00
|
|
|
import android.support.v4.app.Fragment;
|
2015-03-27 10:56:08 +01:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2016-06-15 19:56:34 +02:00
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
2016-06-20 17:50:19 +02:00
|
|
|
import android.view.HapticFeedbackConstants;
|
2016-06-14 15:56:38 +02:00
|
|
|
import android.view.LayoutInflater;
|
2016-06-15 22:29:30 +02:00
|
|
|
import android.view.Menu;
|
2015-03-26 18:11:47 +01:00
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
2016-06-14 15:56:38 +02:00
|
|
|
import android.view.ViewGroup;
|
2016-06-15 22:29:30 +02:00
|
|
|
import android.widget.PopupMenu;
|
2016-06-15 19:56:34 +02:00
|
|
|
|
|
|
|
import com.woxthebox.draglistview.DragListView;
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2015-12-07 18:15:26 +01:00
|
|
|
import org.json.JSONObject;
|
2015-05-12 06:28:11 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2015-08-11 13:55:35 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2015-05-18 20:56:19 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2016-06-14 15:56:38 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.ExternalPebbleJSActivity;
|
2015-03-25 22:23:45 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter;
|
2016-03-03 11:52:30 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2015-08-11 13:55:35 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
|
2016-06-18 19:00:23 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
2016-01-27 23:00:44 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol;
|
2015-08-11 13:55:35 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
2016-03-08 11:49:08 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.PebbleUtils;
|
2015-03-25 22:23:45 +01:00
|
|
|
|
|
|
|
|
2016-06-14 20:04:54 +02:00
|
|
|
public abstract class AbstractAppManagerFragment extends Fragment {
|
2015-03-25 22:23:45 +01:00
|
|
|
public static final String ACTION_REFRESH_APPLIST
|
2015-07-18 23:38:59 +02:00
|
|
|
= "nodomain.freeyourgadget.gadgetbridge.appmanager.action.refresh_applist";
|
2016-06-14 15:56:38 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(AbstractAppManagerFragment.class);
|
2015-03-27 10:56:08 +01:00
|
|
|
|
2016-11-09 19:20:37 +01:00
|
|
|
protected abstract List<GBDeviceApp> getSystemAppsInCategory();
|
2016-06-15 19:56:34 +02:00
|
|
|
|
2016-06-24 13:39:29 +02:00
|
|
|
protected abstract String getSortFilename();
|
2016-06-15 19:56:34 +02:00
|
|
|
|
2016-06-24 13:39:29 +02:00
|
|
|
protected abstract boolean isCacheManager();
|
|
|
|
|
|
|
|
protected abstract boolean filterApp(GBDeviceApp gbDeviceApp);
|
2016-06-15 19:56:34 +02:00
|
|
|
|
2016-06-17 22:43:06 +02:00
|
|
|
protected void onChangedAppOrder() {
|
|
|
|
List<UUID> uuidList = new ArrayList<>();
|
|
|
|
for (GBDeviceApp gbDeviceApp : mGBDeviceAppAdapter.getItemList()) {
|
|
|
|
uuidList.add(gbDeviceApp.getUUID());
|
|
|
|
}
|
|
|
|
AppManagerActivity.rewriteAppOrderFile(getSortFilename(), uuidList);
|
|
|
|
}
|
|
|
|
|
2016-11-09 19:20:37 +01:00
|
|
|
protected void refreshList() {
|
|
|
|
appList.clear();
|
|
|
|
ArrayList uuids = AppManagerActivity.getUuidsFromFile(getSortFilename());
|
|
|
|
List<GBDeviceApp> systemApps = getSystemAppsInCategory();
|
|
|
|
boolean needsRewrite = false;
|
|
|
|
for (GBDeviceApp systemApp : systemApps) {
|
|
|
|
if (!uuids.contains(systemApp.getUUID())) {
|
|
|
|
uuids.add(systemApp.getUUID());
|
|
|
|
needsRewrite = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (needsRewrite) {
|
|
|
|
AppManagerActivity.rewriteAppOrderFile(getSortFilename(), uuids);
|
|
|
|
}
|
|
|
|
appList.addAll(getCachedApps(uuids));
|
|
|
|
}
|
|
|
|
|
2016-06-24 13:39:29 +02:00
|
|
|
private void refreshListFromPebble(Intent intent) {
|
|
|
|
appList.clear();
|
|
|
|
int appCount = intent.getIntExtra("app_count", 0);
|
|
|
|
for (Integer i = 0; i < appCount; i++) {
|
|
|
|
String appName = intent.getStringExtra("app_name" + i.toString());
|
|
|
|
String appCreator = intent.getStringExtra("app_creator" + i.toString());
|
|
|
|
UUID uuid = UUID.fromString(intent.getStringExtra("app_uuid" + i.toString()));
|
|
|
|
GBDeviceApp.Type appType = GBDeviceApp.Type.values()[intent.getIntExtra("app_type" + i.toString(), 0)];
|
|
|
|
|
|
|
|
GBDeviceApp app = new GBDeviceApp(uuid, appName, appCreator, "", appType);
|
|
|
|
app.setOnDevice(true);
|
|
|
|
if (filterApp(app)) {
|
|
|
|
appList.add(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-23 23:04:46 +01:00
|
|
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
2015-03-25 22:23:45 +01:00
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
2016-06-20 17:42:32 +02:00
|
|
|
if (action.equals(ACTION_REFRESH_APPLIST)) {
|
2016-06-17 22:43:06 +02:00
|
|
|
if (intent.hasExtra("app_count")) {
|
2016-06-24 13:39:29 +02:00
|
|
|
LOG.info("got app info from pebble");
|
|
|
|
if (!isCacheManager()) {
|
|
|
|
LOG.info("will refresh list based on data from pebble");
|
|
|
|
refreshListFromPebble(intent);
|
2016-05-22 22:48:45 +02:00
|
|
|
}
|
2016-06-24 13:39:29 +02:00
|
|
|
} else if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) >= 3 || isCacheManager()) {
|
2016-06-17 22:43:06 +02:00
|
|
|
refreshList();
|
2015-09-10 23:07:42 +02:00
|
|
|
}
|
2015-03-25 22:23:45 +01:00
|
|
|
mGBDeviceAppAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-09-10 23:07:42 +02:00
|
|
|
|
2016-06-24 13:39:29 +02:00
|
|
|
private DragListView appListView;
|
2016-06-14 20:04:54 +02:00
|
|
|
protected final List<GBDeviceApp> appList = new ArrayList<>();
|
2015-03-26 18:11:47 +01:00
|
|
|
private GBDeviceAppAdapter mGBDeviceAppAdapter;
|
2016-06-15 19:56:34 +02:00
|
|
|
protected GBDevice mGBDevice = null;
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2016-06-17 22:43:06 +02:00
|
|
|
protected List<GBDeviceApp> getCachedApps(List<UUID> uuids) {
|
2015-08-11 13:55:35 +02:00
|
|
|
List<GBDeviceApp> cachedAppList = new ArrayList<>();
|
2015-12-07 18:15:26 +01:00
|
|
|
File cachePath;
|
2015-08-11 13:55:35 +02:00
|
|
|
try {
|
2015-12-07 18:15:26 +01:00
|
|
|
cachePath = new File(FileUtils.getExternalFilesDir().getPath() + "/pbw-cache");
|
|
|
|
} catch (IOException e) {
|
|
|
|
LOG.warn("could not get external dir while reading pbw cache.");
|
|
|
|
return cachedAppList;
|
|
|
|
}
|
|
|
|
|
2016-06-17 22:43:06 +02:00
|
|
|
File[] files;
|
|
|
|
if (uuids == null) {
|
|
|
|
files = cachePath.listFiles();
|
|
|
|
} else {
|
|
|
|
files = new File[uuids.size()];
|
|
|
|
int index = 0;
|
|
|
|
for (UUID uuid : uuids) {
|
|
|
|
files[index++] = new File(uuid.toString() + ".pbw");
|
|
|
|
}
|
|
|
|
}
|
2015-12-07 18:15:26 +01:00
|
|
|
if (files != null) {
|
|
|
|
for (File file : files) {
|
|
|
|
if (file.getName().endsWith(".pbw")) {
|
|
|
|
String baseName = file.getName().substring(0, file.getName().length() - 4);
|
2016-03-18 16:47:14 +01:00
|
|
|
//metadata
|
2015-12-07 18:15:26 +01:00
|
|
|
File jsonFile = new File(cachePath, baseName + ".json");
|
2016-03-18 16:47:14 +01:00
|
|
|
//configuration
|
|
|
|
File configFile = new File(cachePath, baseName + "_config.js");
|
2015-12-07 18:15:26 +01:00
|
|
|
try {
|
|
|
|
String jsonstring = FileUtils.getStringFromFile(jsonFile);
|
|
|
|
JSONObject json = new JSONObject(jsonstring);
|
2016-03-18 16:47:14 +01:00
|
|
|
cachedAppList.add(new GBDeviceApp(json, configFile.exists()));
|
2015-12-07 18:15:26 +01:00
|
|
|
} catch (Exception e) {
|
2016-06-17 22:43:06 +02:00
|
|
|
LOG.info("could not read json file for " + baseName);
|
2016-06-19 21:48:07 +02:00
|
|
|
//FIXME: this is really ugly, if we do not find system uuids in pbw cache add them manually. Also duplicated code
|
|
|
|
switch (baseName) {
|
|
|
|
case "8f3c8686-31a1-4f5f-91f5-01600c9bdc59":
|
|
|
|
cachedAppList.add(new GBDeviceApp(UUID.fromString(baseName), "Tic Toc (System)", "Pebble Inc.", "", GBDeviceApp.Type.WATCHFACE_SYSTEM));
|
|
|
|
break;
|
|
|
|
case "1f03293d-47af-4f28-b960-f2b02a6dd757":
|
|
|
|
cachedAppList.add(new GBDeviceApp(UUID.fromString(baseName), "Music (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
|
|
|
|
break;
|
|
|
|
case "b2cae818-10f8-46df-ad2b-98ad2254a3c1":
|
|
|
|
cachedAppList.add(new GBDeviceApp(UUID.fromString(baseName), "Notifications (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
|
|
|
|
break;
|
|
|
|
case "67a32d95-ef69-46d4-a0b9-854cc62f97f9":
|
|
|
|
cachedAppList.add(new GBDeviceApp(UUID.fromString(baseName), "Alarms (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
|
|
|
|
break;
|
|
|
|
case "18e443ce-38fd-47c8-84d5-6d0c775fbe55":
|
|
|
|
cachedAppList.add(new GBDeviceApp(UUID.fromString(baseName), "Watchfaces (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
|
|
|
|
break;
|
2016-06-25 18:08:53 +02:00
|
|
|
case "0863fc6a-66c5-4f62-ab8a-82ed00a98b5d":
|
|
|
|
cachedAppList.add(new GBDeviceApp(UUID.fromString(baseName), "Send Text (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
|
|
|
|
break;
|
2016-06-17 22:43:06 +02:00
|
|
|
}
|
2016-06-19 21:48:07 +02:00
|
|
|
/*
|
|
|
|
else if (baseName.equals("4dab81a6-d2fc-458a-992c-7a1f3b96a970")) {
|
|
|
|
cachedAppList.add(new GBDeviceApp(UUID.fromString("4dab81a6-d2fc-458a-992c-7a1f3b96a970"), "Sports (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
|
|
|
|
} else if (baseName.equals("cf1e816a-9db0-4511-bbb8-f60c48ca8fac")) {
|
|
|
|
cachedAppList.add(new GBDeviceApp(UUID.fromString("cf1e816a-9db0-4511-bbb8-f60c48ca8fac"), "Golf (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
|
2016-06-17 22:43:06 +02:00
|
|
|
}
|
2016-06-19 21:48:07 +02:00
|
|
|
*/
|
2016-11-15 11:56:14 +01:00
|
|
|
if (mGBDevice != null) {
|
|
|
|
if (PebbleUtils.hasHealth(mGBDevice.getModel())) {
|
|
|
|
if (baseName.equals(PebbleProtocol.UUID_PEBBLE_HEALTH.toString())) {
|
|
|
|
cachedAppList.add(new GBDeviceApp(PebbleProtocol.UUID_PEBBLE_HEALTH, "Health (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (PebbleUtils.hasHRM(mGBDevice.getModel())) {
|
|
|
|
if (baseName.equals(PebbleProtocol.UUID_WORKOUT.toString())) {
|
|
|
|
cachedAppList.add(new GBDeviceApp(PebbleProtocol.UUID_WORKOUT, "Workout (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
|
|
|
|
continue;
|
|
|
|
}
|
2016-06-17 22:43:06 +02:00
|
|
|
}
|
2016-11-24 22:09:27 +01:00
|
|
|
if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) >= 4) {
|
|
|
|
if (baseName.equals("3af858c3-16cb-4561-91e7-f1ad2df8725f")) {
|
|
|
|
cachedAppList.add(new GBDeviceApp(UUID.fromString(baseName), "Kickstart (System)", "Pebble Inc.", "", GBDeviceApp.Type.WATCHFACE_SYSTEM));
|
|
|
|
}
|
2016-12-30 20:14:13 +01:00
|
|
|
if (baseName.equals(PebbleProtocol.UUID_WEATHER.toString())) {
|
|
|
|
cachedAppList.add(new GBDeviceApp(PebbleProtocol.UUID_WEATHER, "Weather (System)", "Pebble Inc.", "", GBDeviceApp.Type.APP_SYSTEM));
|
|
|
|
}
|
2016-11-24 22:09:27 +01:00
|
|
|
}
|
2016-06-17 22:43:06 +02:00
|
|
|
}
|
|
|
|
if (uuids == null) {
|
|
|
|
cachedAppList.add(new GBDeviceApp(UUID.fromString(baseName), baseName, "N/A", "", GBDeviceApp.Type.UNKNOWN));
|
|
|
|
}
|
2015-08-13 10:06:32 +02:00
|
|
|
}
|
2015-08-11 13:55:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cachedAppList;
|
|
|
|
}
|
|
|
|
|
2015-03-25 22:23:45 +01:00
|
|
|
@Override
|
2016-06-20 17:42:32 +02:00
|
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
2016-06-14 20:04:54 +02:00
|
|
|
mGBDevice = ((AppManagerActivity) getActivity()).getGBDevice();
|
2016-06-24 13:39:29 +02:00
|
|
|
|
|
|
|
if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) < 3 && !isCacheManager()) {
|
|
|
|
appListView.setDragEnabled(false);
|
|
|
|
}
|
|
|
|
|
2016-06-14 15:56:38 +02:00
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(ACTION_REFRESH_APPLIST);
|
2015-09-10 23:07:42 +02:00
|
|
|
|
2016-06-14 15:56:38 +02:00
|
|
|
LocalBroadcastManager.getInstance(getContext()).registerReceiver(mReceiver, filter);
|
|
|
|
|
2016-06-24 13:39:29 +02:00
|
|
|
if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) < 3) {
|
|
|
|
GBApplication.deviceService().onAppInfoReq();
|
|
|
|
if (isCacheManager()) {
|
|
|
|
refreshList();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
refreshList();
|
|
|
|
}
|
2016-06-14 15:56:38 +02:00
|
|
|
}
|
2015-03-25 22:23:45 +01:00
|
|
|
|
2016-06-14 15:56:38 +02:00
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
View rootView = inflater.inflate(R.layout.activity_appmanager, container, false);
|
|
|
|
|
2016-06-24 13:39:29 +02:00
|
|
|
appListView = (DragListView) (rootView.findViewById(R.id.appListView));
|
2016-06-15 19:56:34 +02:00
|
|
|
appListView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
2016-06-15 22:29:30 +02:00
|
|
|
mGBDeviceAppAdapter = new GBDeviceAppAdapter(appList, R.layout.item_with_details, R.id.item_image, this.getContext(), this);
|
2016-06-15 19:56:34 +02:00
|
|
|
appListView.setAdapter(mGBDeviceAppAdapter, false);
|
2016-06-15 22:29:30 +02:00
|
|
|
appListView.setCanDragHorizontally(false);
|
2016-06-17 22:43:06 +02:00
|
|
|
appListView.setDragListListener(new DragListView.DragListListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemDragStarted(int position) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onItemDragging(int itemPosition, float x, float y) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onItemDragEnded(int fromPosition, int toPosition) {
|
|
|
|
onChangedAppOrder();
|
|
|
|
}
|
|
|
|
});
|
2016-06-14 15:56:38 +02:00
|
|
|
return rootView;
|
2015-03-25 22:23:45 +01:00
|
|
|
}
|
|
|
|
|
2016-06-17 22:43:06 +02:00
|
|
|
protected void sendOrderToDevice(String concatFilename) {
|
2016-06-20 17:42:32 +02:00
|
|
|
ArrayList<UUID> uuids = new ArrayList<>();
|
2016-06-17 22:43:06 +02:00
|
|
|
for (GBDeviceApp gbDeviceApp : mGBDeviceAppAdapter.getItemList()) {
|
|
|
|
uuids.add(gbDeviceApp.getUUID());
|
|
|
|
}
|
|
|
|
if (concatFilename != null) {
|
|
|
|
ArrayList<UUID> concatUuids = AppManagerActivity.getUuidsFromFile(concatFilename);
|
|
|
|
uuids.addAll(concatUuids);
|
|
|
|
}
|
|
|
|
GBApplication.deviceService().onAppReorder(uuids.toArray(new UUID[uuids.size()]));
|
|
|
|
}
|
|
|
|
|
2016-06-15 22:29:30 +02:00
|
|
|
public boolean openPopupMenu(View view, int position) {
|
|
|
|
PopupMenu popupMenu = new PopupMenu(getContext(), view);
|
|
|
|
popupMenu.getMenuInflater().inflate(R.menu.appmanager_context, popupMenu.getMenu());
|
|
|
|
Menu menu = popupMenu.getMenu();
|
|
|
|
final GBDeviceApp selectedApp = appList.get(position);
|
2016-01-02 12:24:23 +01:00
|
|
|
|
2016-02-06 21:23:21 +01:00
|
|
|
if (!selectedApp.isInCache()) {
|
2016-01-02 12:24:23 +01:00
|
|
|
menu.removeItem(R.id.appmanager_app_reinstall);
|
2016-05-22 23:32:25 +02:00
|
|
|
menu.removeItem(R.id.appmanager_app_delete_cache);
|
2016-01-02 12:24:23 +01:00
|
|
|
}
|
2016-02-06 21:23:21 +01:00
|
|
|
if (!PebbleProtocol.UUID_PEBBLE_HEALTH.equals(selectedApp.getUUID())) {
|
|
|
|
menu.removeItem(R.id.appmanager_health_activate);
|
|
|
|
menu.removeItem(R.id.appmanager_health_deactivate);
|
2016-05-22 23:32:25 +02:00
|
|
|
}
|
2016-11-15 12:17:51 +01:00
|
|
|
if (!PebbleProtocol.UUID_WORKOUT.equals(selectedApp.getUUID())) {
|
|
|
|
menu.removeItem(R.id.appmanager_hrm_activate);
|
|
|
|
menu.removeItem(R.id.appmanager_hrm_deactivate);
|
|
|
|
}
|
2016-06-20 17:42:32 +02:00
|
|
|
if (selectedApp.getType() == GBDeviceApp.Type.APP_SYSTEM || selectedApp.getType() == GBDeviceApp.Type.WATCHFACE_SYSTEM) {
|
2016-02-06 21:23:21 +01:00
|
|
|
menu.removeItem(R.id.appmanager_app_delete);
|
|
|
|
}
|
2016-03-18 16:47:14 +01:00
|
|
|
if (!selectedApp.isConfigurable()) {
|
|
|
|
menu.removeItem(R.id.appmanager_app_configure);
|
|
|
|
}
|
2016-10-29 11:41:08 +02:00
|
|
|
switch (selectedApp.getType()) {
|
|
|
|
case WATCHFACE:
|
|
|
|
case APP_GENERIC:
|
|
|
|
case APP_ACTIVITYTRACKER:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
menu.removeItem(R.id.appmanager_app_openinstore);
|
|
|
|
}
|
2016-06-15 22:29:30 +02:00
|
|
|
//menu.setHeaderTitle(selectedApp.getName());
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
return onContextItemSelected(item, selectedApp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2016-06-20 17:50:19 +02:00
|
|
|
|
|
|
|
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
2016-06-15 22:29:30 +02:00
|
|
|
popupMenu.show();
|
2016-06-20 17:50:19 +02:00
|
|
|
return true;
|
2015-03-26 18:11:47 +01:00
|
|
|
}
|
|
|
|
|
2016-06-15 22:29:30 +02:00
|
|
|
public boolean onContextItemSelected(MenuItem item, GBDeviceApp selectedApp) {
|
2015-03-26 18:11:47 +01:00
|
|
|
switch (item.getItemId()) {
|
2016-05-22 23:32:25 +02:00
|
|
|
case R.id.appmanager_app_delete_cache:
|
2016-05-23 23:15:07 +02:00
|
|
|
String baseName;
|
2016-05-22 23:32:25 +02:00
|
|
|
try {
|
2016-05-23 23:15:07 +02:00
|
|
|
baseName = FileUtils.getExternalFilesDir().getPath() + "/pbw-cache/" + selectedApp.getUUID();
|
2016-05-22 23:32:25 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
LOG.warn("could not get external dir while trying to access pbw cache.");
|
2016-05-23 23:15:07 +02:00
|
|
|
return true;
|
2016-05-22 23:32:25 +02:00
|
|
|
}
|
2016-05-23 23:15:07 +02:00
|
|
|
|
2016-06-26 11:55:08 +02:00
|
|
|
String[] suffixToDelete = new String[]{".pbw", ".json", "_config.js", "_preset.json"};
|
2016-05-23 23:15:07 +02:00
|
|
|
|
|
|
|
for (String suffix : suffixToDelete) {
|
|
|
|
File fileToDelete = new File(baseName + suffix);
|
|
|
|
if (!fileToDelete.delete()) {
|
|
|
|
LOG.warn("could not delete file from pbw cache: " + fileToDelete.toString());
|
|
|
|
} else {
|
|
|
|
LOG.info("deleted file: " + fileToDelete.toString());
|
|
|
|
}
|
2016-05-22 23:32:25 +02:00
|
|
|
}
|
2016-06-17 22:43:06 +02:00
|
|
|
AppManagerActivity.deleteFromAppOrderFile("pbwcacheorder.txt", selectedApp.getUUID()); // FIXME: only if successful
|
2016-05-22 23:32:25 +02:00
|
|
|
// fall through
|
2015-03-26 18:11:47 +01:00
|
|
|
case R.id.appmanager_app_delete:
|
2016-06-24 13:39:29 +02:00
|
|
|
if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) >= 3) {
|
|
|
|
AppManagerActivity.deleteFromAppOrderFile(mGBDevice.getAddress() + ".watchapps", selectedApp.getUUID()); // FIXME: only if successful
|
|
|
|
AppManagerActivity.deleteFromAppOrderFile(mGBDevice.getAddress() + ".watchfaces", selectedApp.getUUID()); // FIXME: only if successful
|
|
|
|
Intent refreshIntent = new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST);
|
|
|
|
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent);
|
|
|
|
}
|
2016-05-23 23:46:54 +02:00
|
|
|
GBApplication.deviceService().onAppDelete(selectedApp.getUUID());
|
2016-01-02 12:24:23 +01:00
|
|
|
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) {
|
2016-05-22 23:32:25 +02:00
|
|
|
LOG.warn("could not get external dir while trying to access pbw cache.");
|
2016-01-02 12:24:23 +01:00
|
|
|
return true;
|
2015-03-26 18:11:47 +01:00
|
|
|
}
|
2016-01-02 12:24:23 +01:00
|
|
|
GBApplication.deviceService().onInstallApp(Uri.fromFile(cachePath));
|
2015-03-26 18:11:47 +01:00
|
|
|
return true;
|
2016-02-06 21:23:21 +01:00
|
|
|
case R.id.appmanager_health_activate:
|
|
|
|
GBApplication.deviceService().onInstallApp(Uri.parse("fake://health"));
|
|
|
|
return true;
|
2016-11-15 12:17:51 +01:00
|
|
|
case R.id.appmanager_hrm_activate:
|
|
|
|
GBApplication.deviceService().onInstallApp(Uri.parse("fake://hrm"));
|
|
|
|
return true;
|
2016-12-30 20:14:13 +01:00
|
|
|
case R.id.appmanager_weather_activate:
|
|
|
|
GBApplication.deviceService().onInstallApp(Uri.parse("fake://weather"));
|
|
|
|
return true;
|
2016-11-09 12:06:13 +01:00
|
|
|
case R.id.appmanager_health_deactivate:
|
2016-11-15 12:17:51 +01:00
|
|
|
case R.id.appmanager_hrm_deactivate:
|
2016-12-30 20:14:13 +01:00
|
|
|
case R.id.appmanager_weather_deactivate:
|
2016-11-09 12:06:13 +01:00
|
|
|
GBApplication.deviceService().onAppDelete(selectedApp.getUUID());
|
|
|
|
return true;
|
2016-02-28 22:25:21 +01:00
|
|
|
case R.id.appmanager_app_configure:
|
2016-03-03 14:25:44 +01:00
|
|
|
GBApplication.deviceService().onAppStart(selectedApp.getUUID(), true);
|
2016-03-03 15:47:00 +01:00
|
|
|
|
2016-06-14 15:56:38 +02:00
|
|
|
Intent startIntent = new Intent(getContext().getApplicationContext(), ExternalPebbleJSActivity.class);
|
2016-06-18 19:00:23 +02:00
|
|
|
startIntent.putExtra(DeviceService.EXTRA_APP_UUID, selectedApp.getUUID());
|
2016-03-03 11:52:30 +01:00
|
|
|
startIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice);
|
2016-02-28 22:25:21 +01:00
|
|
|
startActivity(startIntent);
|
|
|
|
return true;
|
2016-10-29 11:41:08 +02:00
|
|
|
case R.id.appmanager_app_openinstore:
|
|
|
|
String url = "https://apps.getpebble.com/en_US/search/" + ((selectedApp.getType() == GBDeviceApp.Type.WATCHFACE) ? "watchfaces" : "watchapps") + "/1?query=" + selectedApp.getName() + "&dev_settings=true";
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse(url));
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
2015-03-26 18:11:47 +01:00
|
|
|
default:
|
|
|
|
return super.onContextItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 22:23:45 +01:00
|
|
|
@Override
|
2016-06-14 15:56:38 +02:00
|
|
|
public void onDestroy() {
|
|
|
|
LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(mReceiver);
|
2015-03-25 22:23:45 +01:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
}
|