1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-24 17:45:50 +01:00

Disable activity data fetching when not supported

Closes #149
This commit is contained in:
cpfeiffer 2015-10-24 23:28:02 +02:00
parent f287c04ad9
commit 4200e77016
7 changed files with 72 additions and 8 deletions

View File

@ -197,12 +197,13 @@ public class ControlCenter extends Activity {
}
getMenuInflater().inflate(R.menu.controlcenter_context, menu);
if (!selectedDevice.isConnected() || selectedDevice.getType() == DeviceType.PEBBLE) {
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(selectedDevice);
if (!selectedDevice.isConnected() || !coordinator.supportsActivityDataFetching()) {
menu.removeItem(R.id.controlcenter_fetch_activity_data);
menu.removeItem(R.id.controlcenter_configure_alarms);
}
if (!selectedDevice.isConnected() || selectedDevice.getType() == DeviceType.MIBAND) {
if (!selectedDevice.isConnected() || !coordinator.supportsScreenshots()) {
menu.removeItem(R.id.controlcenter_take_screenshot);
}
@ -217,9 +218,14 @@ public class ControlCenter extends Activity {
}
private void enableSwipeRefresh(GBDevice device) {
boolean enable = device != null && device.isInitialized() && !device.isBusy();
if (device == null) {
swipeLayout.setEnabled(false);
} else {
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
boolean enable = coordinator.allowFetchActivityData(device);
swipeLayout.setEnabled(enable);
}
}
private void fetchActivityData() {
if (selectedDevice == null) {

View File

@ -36,8 +36,10 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractFragmentPagerAdapter;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragmentActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class ChartsActivity extends AbstractGBFragmentActivity implements ChartsHost {
@ -109,6 +111,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(REFRESH));
}
}
enableSwipeRefresh(true);
}
@Override
@ -137,6 +140,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
fetchActivityData();
}
});
enableSwipeRefresh(true);
// Set up the ViewPager with the sections adapter.
viewPager = (ViewPager) findViewById(R.id.charts_pager);
@ -241,6 +245,11 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu_charts, menu);
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(mGBDevice);
if (!mGBDevice.isConnected() || !coordinator.supportsActivityDataFetching()) {
menu.removeItem(R.id.charts_fetch_activity_data);
}
return true;
}
@ -258,7 +267,8 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
}
private void enableSwipeRefresh(boolean enable) {
swipeLayout.setEnabled(enable);
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(mGBDevice);
swipeLayout.setEnabled(enable && coordinator.allowFetchActivityData(mGBDevice));
}
private void fetchActivityData() {

View File

@ -0,0 +1,10 @@
package nodomain.freeyourgadget.gadgetbridge.devices;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
public boolean allowFetchActivityData(GBDevice device) {
return device.isInitialized() && !device.isBusy() && supportsActivityDataFetching();
}
}

View File

@ -24,4 +24,10 @@ public interface DeviceCoordinator {
SampleProvider getSampleProvider();
InstallHandler findInstallHandler(Uri uri, Context context);
boolean allowFetchActivityData(GBDevice device);
boolean supportsActivityDataFetching();
boolean supportsScreenshots();
}

View File

@ -10,7 +10,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
public class UnknownDeviceCoordinator implements DeviceCoordinator {
public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator {
private final UnknownSampleProvider sampleProvider;
private static final class UnknownSampleProvider implements SampleProvider {
@ -73,4 +73,14 @@ public class UnknownDeviceCoordinator implements DeviceCoordinator {
public InstallHandler findInstallHandler(Uri uri, Context context) {
return null;
}
@Override
public boolean supportsActivityDataFetching() {
return false;
}
@Override
public boolean supportsScreenshots() {
return false;
}
}

View File

@ -13,6 +13,7 @@ import java.util.Calendar;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
@ -20,7 +21,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
public class MiBandCoordinator implements DeviceCoordinator {
public class MiBandCoordinator extends AbstractDeviceCoordinator {
private static final Logger LOG = LoggerFactory.getLogger(MiBandCoordinator.class);
private final MiBandSampleProvider sampleProvider;
@ -63,6 +64,16 @@ public class MiBandCoordinator implements DeviceCoordinator {
return handler.isValid() ? handler : null;
}
@Override
public boolean supportsActivityDataFetching() {
return true;
}
@Override
public boolean supportsScreenshots() {
return false;
}
public static boolean hasValidUserInfo() {
String dummyMacAddress = MiBandService.MAC_ADDRESS_FILTER + ":00:00:00";
try {

View File

@ -8,6 +8,7 @@ import android.preference.PreferenceManager;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.activities.AppManagerActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
@ -15,7 +16,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
public class PebbleCoordinator implements DeviceCoordinator {
public class PebbleCoordinator extends AbstractDeviceCoordinator {
public PebbleCoordinator() {
}
@ -60,4 +61,14 @@ public class PebbleCoordinator implements DeviceCoordinator {
PBWInstallHandler installHandler = new PBWInstallHandler(uri, context);
return installHandler.isValid() ? installHandler : null;
}
@Override
public boolean supportsActivityDataFetching() {
return false;
}
@Override
public boolean supportsScreenshots() {
return true;
}
}