mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-11 12:39:26 +01: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:
parent
1de6ee019f
commit
659165fa4c
@ -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,12 +62,8 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||
AppManagerActivity.rewriteAppOrderFile(getSortFilename(), uuidList);
|
||||
}
|
||||
|
||||
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")) {
|
||||
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());
|
||||
@ -76,23 +71,26 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||
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);
|
||||
if (filterApp(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();
|
||||
}
|
||||
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,21 +204,32 @@ 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);
|
||||
|
||||
if (PebbleUtils.getFwMajor(mGBDevice.getFirmwareVersion()) < 3) {
|
||||
GBApplication.deviceService().onAppInfoReq();
|
||||
if (isCacheManager()) {
|
||||
refreshList();
|
||||
}
|
||||
} else {
|
||||
refreshList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
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:
|
||||
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:
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -655,6 +655,7 @@ 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());
|
||||
if (mPebbleProtocol.mFwMajor >= 3) {
|
||||
String filenameSuffix;
|
||||
if (mCurrentlyInstallingApp != null) {
|
||||
if (mCurrentlyInstallingApp.getType() == GBDeviceApp.Type.WATCHFACE) {
|
||||
@ -667,6 +668,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
mInstallState = PebbleAppInstallState.UNKNOWN;
|
||||
|
||||
if (hadError && mAppInstallToken != -1) {
|
||||
|
@ -29,4 +29,8 @@ public class PebbleUtils {
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
public static int getFwMajor(String fwString) {
|
||||
return fwString.charAt(1) - 48;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user