1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-27 15:30:14 +02:00

Pebble: fix new app manager on 2.x

- properly intert apps reported from pebble into the corresponding tab
- disable tracking of installed apps
- disable drag and drop for apps and watchfaces
- ...
This commit is contained in:
Andreas Shimokawa 2016-06-24 13:39:29 +02:00
parent 1de6ee019f
commit 659165fa4c
6 changed files with 98 additions and 45 deletions

View File

@ -27,7 +27,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import java.util.UUID; import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
@ -47,13 +46,13 @@ public abstract class AbstractAppManagerFragment extends Fragment {
= "nodomain.freeyourgadget.gadgetbridge.appmanager.action.refresh_applist"; = "nodomain.freeyourgadget.gadgetbridge.appmanager.action.refresh_applist";
private static final Logger LOG = LoggerFactory.getLogger(AbstractAppManagerFragment.class); private static final Logger LOG = LoggerFactory.getLogger(AbstractAppManagerFragment.class);
protected abstract void refreshList();
protected void refreshList() { protected abstract String getSortFilename();
}
protected String getSortFilename() { protected abstract boolean isCacheManager();
return null;
} protected abstract boolean filterApp(GBDeviceApp gbDeviceApp);
protected void onChangedAppOrder() { protected void onChangedAppOrder() {
List<UUID> uuidList = new ArrayList<>(); List<UUID> uuidList = new ArrayList<>();
@ -63,36 +62,35 @@ public abstract class AbstractAppManagerFragment extends Fragment {
AppManagerActivity.rewriteAppOrderFile(getSortFilename(), uuidList); AppManagerActivity.rewriteAppOrderFile(getSortFilename(), uuidList);
} }
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);
}
}
}
private final BroadcastReceiver mReceiver = new BroadcastReceiver() { private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
if (action.equals(ACTION_REFRESH_APPLIST)) { if (action.equals(ACTION_REFRESH_APPLIST)) {
if (intent.hasExtra("app_count")) { if (intent.hasExtra("app_count")) {
int appCount = intent.getIntExtra("app_count", 0); LOG.info("got app info from pebble");
for (Integer i = 0; i < appCount; i++) { if (!isCacheManager()) {
String appName = intent.getStringExtra("app_name" + i.toString()); LOG.info("will refresh list based on data from pebble");
String appCreator = intent.getStringExtra("app_creator" + i.toString()); refreshListFromPebble(intent);
UUID uuid = UUID.fromString(intent.getStringExtra("app_uuid" + i.toString()));
GBDeviceApp.Type appType = GBDeviceApp.Type.values()[intent.getIntExtra("app_type" + i.toString(), 0)];
boolean found = false;
for (final ListIterator<GBDeviceApp> 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);
}
} }
} else { } else if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) >= 3 || isCacheManager()) {
refreshList(); refreshList();
} }
mGBDeviceAppAdapter.notifyDataSetChanged(); mGBDeviceAppAdapter.notifyDataSetChanged();
@ -100,6 +98,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
} }
}; };
private DragListView appListView;
protected final List<GBDeviceApp> appList = new ArrayList<>(); protected final List<GBDeviceApp> appList = new ArrayList<>();
private GBDeviceAppAdapter mGBDeviceAppAdapter; private GBDeviceAppAdapter mGBDeviceAppAdapter;
protected GBDevice mGBDevice = null; protected GBDevice mGBDevice = null;
@ -205,13 +204,24 @@ public abstract class AbstractAppManagerFragment extends Fragment {
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
mGBDevice = ((AppManagerActivity) getActivity()).getGBDevice(); mGBDevice = ((AppManagerActivity) getActivity()).getGBDevice();
if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) < 3 && !isCacheManager()) {
appListView.setDragEnabled(false);
}
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_REFRESH_APPLIST); filter.addAction(ACTION_REFRESH_APPLIST);
LocalBroadcastManager.getInstance(getContext()).registerReceiver(mReceiver, filter); LocalBroadcastManager.getInstance(getContext()).registerReceiver(mReceiver, filter);
GBApplication.deviceService().onAppInfoReq(); if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) < 3) {
refreshList(); GBApplication.deviceService().onAppInfoReq();
if (isCacheManager()) {
refreshList();
}
} else {
refreshList();
}
} }
@Override @Override
@ -219,7 +229,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
View rootView = inflater.inflate(R.layout.activity_appmanager, container, false); View rootView = inflater.inflate(R.layout.activity_appmanager, container, false);
DragListView appListView = (DragListView) (rootView.findViewById(R.id.appListView)); appListView = (DragListView) (rootView.findViewById(R.id.appListView));
appListView.setLayoutManager(new LinearLayoutManager(getActivity())); appListView.setLayoutManager(new LinearLayoutManager(getActivity()));
mGBDeviceAppAdapter = new GBDeviceAppAdapter(appList, R.layout.item_with_details, R.id.item_image, this.getContext(), this); mGBDeviceAppAdapter = new GBDeviceAppAdapter(appList, R.layout.item_with_details, R.id.item_image, this.getContext(), this);
appListView.setAdapter(mGBDeviceAppAdapter, false); appListView.setAdapter(mGBDeviceAppAdapter, false);
@ -311,10 +321,12 @@ public abstract class AbstractAppManagerFragment extends Fragment {
AppManagerActivity.deleteFromAppOrderFile("pbwcacheorder.txt", selectedApp.getUUID()); // FIXME: only if successful AppManagerActivity.deleteFromAppOrderFile("pbwcacheorder.txt", selectedApp.getUUID()); // FIXME: only if successful
// fall through // fall through
case R.id.appmanager_app_delete: case R.id.appmanager_app_delete:
AppManagerActivity.deleteFromAppOrderFile(mGBDevice.getAddress() + ".watchapps", selectedApp.getUUID()); // FIXME: only if successful if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) >= 3) {
AppManagerActivity.deleteFromAppOrderFile(mGBDevice.getAddress() + ".watchfaces", selectedApp.getUUID()); // FIXME: only if successful AppManagerActivity.deleteFromAppOrderFile(mGBDevice.getAddress() + ".watchapps", selectedApp.getUUID()); // FIXME: only if successful
Intent refreshIntent = new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST); AppManagerActivity.deleteFromAppOrderFile(mGBDevice.getAddress() + ".watchfaces", selectedApp.getUUID()); // FIXME: only if successful
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent); Intent refreshIntent = new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent);
}
GBApplication.deviceService().onAppDelete(selectedApp.getUUID()); GBApplication.deviceService().onAppDelete(selectedApp.getUUID());
return true; return true;
case R.id.appmanager_app_reinstall: case R.id.appmanager_app_reinstall:

View File

@ -1,5 +1,7 @@
package nodomain.freeyourgadget.gadgetbridge.activities.appmanager; package nodomain.freeyourgadget.gadgetbridge.activities.appmanager;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
public class AppManagerFragmentCache extends AbstractAppManagerFragment { public class AppManagerFragmentCache extends AbstractAppManagerFragment {
@Override @Override
public void refreshList() { public void refreshList() {
@ -7,8 +9,18 @@ public class AppManagerFragmentCache extends AbstractAppManagerFragment {
appList.addAll(getCachedApps(null)); appList.addAll(getCachedApps(null));
} }
@Override
protected boolean isCacheManager() {
return true;
}
@Override @Override
public String getSortFilename() { public String getSortFilename() {
return "pbwcacheorder.txt"; return "pbwcacheorder.txt";
} }
@Override
protected boolean filterApp(GBDeviceApp gbDeviceApp) {
return true;
}
} }

View File

@ -20,6 +20,11 @@ public class AppManagerFragmentInstalledApps extends AbstractAppManagerFragment
} }
} }
@Override
protected boolean isCacheManager() {
return false;
}
@Override @Override
protected String getSortFilename() { protected String getSortFilename() {
return mGBDevice.getAddress() + ".watchapps"; return mGBDevice.getAddress() + ".watchapps";
@ -30,4 +35,9 @@ public class AppManagerFragmentInstalledApps extends AbstractAppManagerFragment
super.onChangedAppOrder(); super.onChangedAppOrder();
sendOrderToDevice(mGBDevice.getAddress() + ".watchfaces"); sendOrderToDevice(mGBDevice.getAddress() + ".watchfaces");
} }
@Override
protected boolean filterApp(GBDeviceApp gbDeviceApp) {
return gbDeviceApp.getType() == GBDeviceApp.Type.APP_ACTIVITYTRACKER || gbDeviceApp.getType() == GBDeviceApp.Type.APP_GENERIC;
}
} }

View File

@ -20,6 +20,11 @@ public class AppManagerFragmentInstalledWatchfaces extends AbstractAppManagerFra
} }
} }
@Override
protected boolean isCacheManager() {
return false;
}
@Override @Override
protected String getSortFilename() { protected String getSortFilename() {
return mGBDevice.getAddress() + ".watchfaces"; return mGBDevice.getAddress() + ".watchfaces";
@ -30,4 +35,12 @@ public class AppManagerFragmentInstalledWatchfaces extends AbstractAppManagerFra
super.onChangedAppOrder(); super.onChangedAppOrder();
sendOrderToDevice(mGBDevice.getAddress() + ".watchapps"); sendOrderToDevice(mGBDevice.getAddress() + ".watchapps");
} }
@Override
protected boolean filterApp(GBDeviceApp gbDeviceApp) {
if (gbDeviceApp.getType() == GBDeviceApp.Type.WATCHFACE) {
return true;
}
return false;
}
} }

View File

@ -655,16 +655,18 @@ public class PebbleIoThread extends GBDeviceIoThread {
GB.updateInstallNotification(getContext().getString(R.string.installation_failed_), false, 0, getContext()); GB.updateInstallNotification(getContext().getString(R.string.installation_failed_), false, 0, getContext());
} else { } else {
GB.updateInstallNotification(getContext().getString(R.string.installation_successful), false, 0, getContext()); GB.updateInstallNotification(getContext().getString(R.string.installation_successful), false, 0, getContext());
String filenameSuffix; if (mPebbleProtocol.mFwMajor >= 3) {
if (mCurrentlyInstallingApp != null) { String filenameSuffix;
if (mCurrentlyInstallingApp.getType() == GBDeviceApp.Type.WATCHFACE) { if (mCurrentlyInstallingApp != null) {
filenameSuffix = ".watchfaces"; if (mCurrentlyInstallingApp.getType() == GBDeviceApp.Type.WATCHFACE) {
} else { filenameSuffix = ".watchfaces";
filenameSuffix = ".watchapps"; } else {
filenameSuffix = ".watchapps";
}
AppManagerActivity.addToAppOrderFile(gbDevice.getAddress() + filenameSuffix, mCurrentlyInstallingApp.getUUID());
Intent refreshIntent = new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent);
} }
AppManagerActivity.addToAppOrderFile(gbDevice.getAddress() + filenameSuffix, mCurrentlyInstallingApp.getUUID());
Intent refreshIntent = new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent);
} }
} }
mInstallState = PebbleAppInstallState.UNKNOWN; mInstallState = PebbleAppInstallState.UNKNOWN;

View File

@ -29,4 +29,8 @@ public class PebbleUtils {
} }
return model; return model;
} }
public static int getFwMajor(String fwString) {
return fwString.charAt(1) - 48;
}
} }