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:
parent
1de6ee019f
commit
659165fa4c
|
@ -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,12 +62,8 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||||
AppManagerActivity.rewriteAppOrderFile(getSortFilename(), uuidList);
|
AppManagerActivity.rewriteAppOrderFile(getSortFilename(), uuidList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private void refreshListFromPebble(Intent intent) {
|
||||||
@Override
|
appList.clear();
|
||||||
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);
|
int appCount = intent.getIntExtra("app_count", 0);
|
||||||
for (Integer i = 0; i < appCount; i++) {
|
for (Integer i = 0; i < appCount; i++) {
|
||||||
String appName = intent.getStringExtra("app_name" + i.toString());
|
String appName = intent.getStringExtra("app_name" + i.toString());
|
||||||
|
@ -76,23 +71,26 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||||
UUID uuid = UUID.fromString(intent.getStringExtra("app_uuid" + 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.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);
|
GBDeviceApp app = new GBDeviceApp(uuid, appName, appCreator, "", appType);
|
||||||
app.setOnDevice(true);
|
app.setOnDevice(true);
|
||||||
|
if (filterApp(app)) {
|
||||||
appList.add(app);
|
appList.add(app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
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")) {
|
||||||
|
LOG.info("got app info from pebble");
|
||||||
|
if (!isCacheManager()) {
|
||||||
|
LOG.info("will refresh list based on data from pebble");
|
||||||
|
refreshListFromPebble(intent);
|
||||||
|
}
|
||||||
|
} 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,21 +204,32 @@ 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);
|
||||||
|
|
||||||
|
if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) < 3) {
|
||||||
GBApplication.deviceService().onAppInfoReq();
|
GBApplication.deviceService().onAppInfoReq();
|
||||||
|
if (isCacheManager()) {
|
||||||
refreshList();
|
refreshList();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
refreshList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
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:
|
||||||
|
if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) >= 3) {
|
||||||
AppManagerActivity.deleteFromAppOrderFile(mGBDevice.getAddress() + ".watchapps", selectedApp.getUUID()); // FIXME: only if successful
|
AppManagerActivity.deleteFromAppOrderFile(mGBDevice.getAddress() + ".watchapps", selectedApp.getUUID()); // FIXME: only if successful
|
||||||
AppManagerActivity.deleteFromAppOrderFile(mGBDevice.getAddress() + ".watchfaces", 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);
|
Intent refreshIntent = new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST);
|
||||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent);
|
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:
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -655,6 +655,7 @@ 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());
|
||||||
|
if (mPebbleProtocol.mFwMajor >= 3) {
|
||||||
String filenameSuffix;
|
String filenameSuffix;
|
||||||
if (mCurrentlyInstallingApp != null) {
|
if (mCurrentlyInstallingApp != null) {
|
||||||
if (mCurrentlyInstallingApp.getType() == GBDeviceApp.Type.WATCHFACE) {
|
if (mCurrentlyInstallingApp.getType() == GBDeviceApp.Type.WATCHFACE) {
|
||||||
|
@ -667,6 +668,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent);
|
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mInstallState = PebbleAppInstallState.UNKNOWN;
|
mInstallState = PebbleAppInstallState.UNKNOWN;
|
||||||
|
|
||||||
if (hadError && mAppInstallToken != -1) {
|
if (hadError && mAppInstallToken != -1) {
|
||||||
|
|
|
@ -29,4 +29,8 @@ public class PebbleUtils {
|
||||||
}
|
}
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getFwMajor(String fwString) {
|
||||||
|
return fwString.charAt(1) - 48;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue