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
- ...
master
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.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
@ -47,13 +46,13 @@ public abstract class AbstractAppManagerFragment extends Fragment {
= "nodomain.freeyourgadget.gadgetbridge.appmanager.action.refresh_applist";
private static final Logger LOG = LoggerFactory.getLogger(AbstractAppManagerFragment.class);
protected abstract void refreshList();
protected void refreshList() {
}
protected abstract String getSortFilename();
protected String getSortFilename() {
return null;
}
protected abstract boolean isCacheManager();
protected abstract boolean filterApp(GBDeviceApp gbDeviceApp);
protected void onChangedAppOrder() {
List<UUID> uuidList = new ArrayList<>();
@ -63,36 +62,35 @@ public abstract class AbstractAppManagerFragment extends Fragment {
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() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(ACTION_REFRESH_APPLIST)) {
if (intent.hasExtra("app_count")) {
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)];
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);
}
LOG.info("got app info from pebble");
if (!isCacheManager()) {
LOG.info("will refresh list based on data from pebble");
refreshListFromPebble(intent);
}
} else {
} else if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) >= 3 || isCacheManager()) {
refreshList();
}
mGBDeviceAppAdapter.notifyDataSetChanged();
@ -100,6 +98,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
}
};
private DragListView appListView;
protected final List<GBDeviceApp> appList = new ArrayList<>();
private GBDeviceAppAdapter mGBDeviceAppAdapter;
protected GBDevice mGBDevice = null;
@ -205,13 +204,24 @@ public abstract class AbstractAppManagerFragment extends Fragment {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mGBDevice = ((AppManagerActivity) getActivity()).getGBDevice();
if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) < 3 && !isCacheManager()) {
appListView.setDragEnabled(false);
}
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_REFRESH_APPLIST);
LocalBroadcastManager.getInstance(getContext()).registerReceiver(mReceiver, filter);
GBApplication.deviceService().onAppInfoReq();
refreshList();
if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) < 3) {
GBApplication.deviceService().onAppInfoReq();
if (isCacheManager()) {
refreshList();
}
} else {
refreshList();
}
}
@Override
@ -219,7 +229,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
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()));
mGBDeviceAppAdapter = new GBDeviceAppAdapter(appList, R.layout.item_with_details, R.id.item_image, this.getContext(), this);
appListView.setAdapter(mGBDeviceAppAdapter, false);
@ -311,10 +321,12 @@ public abstract class AbstractAppManagerFragment extends Fragment {
AppManagerActivity.deleteFromAppOrderFile("pbwcacheorder.txt", selectedApp.getUUID()); // FIXME: only if successful
// fall through
case R.id.appmanager_app_delete:
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);
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);
}
GBApplication.deviceService().onAppDelete(selectedApp.getUUID());
return true;
case R.id.appmanager_app_reinstall:

View File

@ -1,5 +1,7 @@
package nodomain.freeyourgadget.gadgetbridge.activities.appmanager;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
public class AppManagerFragmentCache extends AbstractAppManagerFragment {
@Override
public void refreshList() {
@ -7,8 +9,18 @@ public class AppManagerFragmentCache extends AbstractAppManagerFragment {
appList.addAll(getCachedApps(null));
}
@Override
protected boolean isCacheManager() {
return true;
}
@Override
public String getSortFilename() {
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
protected String getSortFilename() {
return mGBDevice.getAddress() + ".watchapps";
@ -30,4 +35,9 @@ public class AppManagerFragmentInstalledApps extends AbstractAppManagerFragment
super.onChangedAppOrder();
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
protected String getSortFilename() {
return mGBDevice.getAddress() + ".watchfaces";
@ -30,4 +35,12 @@ public class AppManagerFragmentInstalledWatchfaces extends AbstractAppManagerFra
super.onChangedAppOrder();
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());
} else {
GB.updateInstallNotification(getContext().getString(R.string.installation_successful), false, 0, getContext());
String filenameSuffix;
if (mCurrentlyInstallingApp != null) {
if (mCurrentlyInstallingApp.getType() == GBDeviceApp.Type.WATCHFACE) {
filenameSuffix = ".watchfaces";
} else {
filenameSuffix = ".watchapps";
if (mPebbleProtocol.mFwMajor >= 3) {
String filenameSuffix;
if (mCurrentlyInstallingApp != null) {
if (mCurrentlyInstallingApp.getType() == GBDeviceApp.Type.WATCHFACE) {
filenameSuffix = ".watchfaces";
} 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;

View File

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