Only sync Calendar and Sunrise/Sunset on devices that support it
This commit is contained in:
parent
a28d27839f
commit
7ee20348db
|
@ -227,4 +227,11 @@ public interface DeviceCoordinator {
|
||||||
* @param device
|
* @param device
|
||||||
*/
|
*/
|
||||||
int getBondingStyle(GBDevice device);
|
int getBondingStyle(GBDevice device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the device has some kind of calender we can sync to.
|
||||||
|
* Also used for generated sunrise/sunset events
|
||||||
|
*/
|
||||||
|
boolean supportsCalendarEvents();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,4 +176,9 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator {
|
||||||
public Class<? extends Activity> getAppsManagementActivity() {
|
public Class<? extends Activity> getAppsManagementActivity() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsCalendarEvents() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,11 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
|
||||||
return BONDING_STYLE_NONE;
|
return BONDING_STYLE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsCalendarEvents() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeviceType getDeviceType() {
|
public DeviceType getDeviceType() {
|
||||||
return DeviceType.HPLUS;
|
return DeviceType.HPLUS;
|
||||||
|
|
|
@ -120,6 +120,11 @@ public class LiveviewCoordinator extends AbstractDeviceCoordinator {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsCalendarEvents() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
||||||
// nothing to delete, yet
|
// nothing to delete, yet
|
||||||
|
|
|
@ -171,6 +171,11 @@ public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsCalendarEvents() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean hasValidUserInfo() {
|
public static boolean hasValidUserInfo() {
|
||||||
String dummyMacAddress = MiBandService.MAC_ADDRESS_FILTER_1_1A + ":00:00:00";
|
String dummyMacAddress = MiBandService.MAC_ADDRESS_FILTER_1_1A + ":00:00:00";
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -20,6 +20,7 @@ package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import de.greenrobot.dao.query.QueryBuilder;
|
import de.greenrobot.dao.query.QueryBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
|
@ -46,6 +47,7 @@ public class PebbleCoordinator extends AbstractDeviceCoordinator {
|
||||||
public PebbleCoordinator() {
|
public PebbleCoordinator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
|
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
|
||||||
String name = candidate.getDevice().getName();
|
String name = candidate.getDevice().getName();
|
||||||
|
@ -71,7 +73,7 @@ public class PebbleCoordinator extends AbstractDeviceCoordinator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void deleteDevice(GBDevice gbDevice, Device device, DaoSession session) throws GBException {
|
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
||||||
Long deviceId = device.getId();
|
Long deviceId = device.getId();
|
||||||
QueryBuilder<?> qb = session.getPebbleHealthActivitySampleDao().queryBuilder();
|
QueryBuilder<?> qb = session.getPebbleHealthActivitySampleDao().queryBuilder();
|
||||||
qb.where(PebbleHealthActivitySampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
qb.where(PebbleHealthActivitySampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
||||||
|
@ -154,4 +156,9 @@ public class PebbleCoordinator extends AbstractDeviceCoordinator {
|
||||||
public Class<? extends Activity> getAppsManagementActivity() {
|
public Class<? extends Activity> getAppsManagementActivity() {
|
||||||
return AppManagerActivity.class;
|
return AppManagerActivity.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsCalendarEvents() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,11 @@ public class VibratissimoCoordinator extends AbstractDeviceCoordinator {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsCalendarEvents() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
||||||
// nothing to delete, yet
|
// nothing to delete, yet
|
||||||
|
|
|
@ -41,6 +41,8 @@ import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmClockReceiver;
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmClockReceiver;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver;
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver;
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver;
|
||||||
|
@ -206,7 +208,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||||
if (mGBDevice.equals(device)) {
|
if (mGBDevice.equals(device)) {
|
||||||
mGBDevice = device;
|
mGBDevice = device;
|
||||||
boolean enableReceivers = mDeviceSupport != null && (mDeviceSupport.useAutoConnect() || mGBDevice.isInitialized());
|
boolean enableReceivers = mDeviceSupport != null && (mDeviceSupport.useAutoConnect() || mGBDevice.isInitialized());
|
||||||
setReceiversEnableState(enableReceivers, mGBDevice.isInitialized());
|
setReceiversEnableState(enableReceivers, mGBDevice.isInitialized(), DeviceHelper.getInstance().getCoordinator(device));
|
||||||
GB.updateNotification(mGBDevice.getName() + " " + mGBDevice.getStateString(), mGBDevice.isInitialized(), context);
|
GB.updateNotification(mGBDevice.getName() + " " + mGBDevice.getStateString(), mGBDevice.isInitialized(), context);
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Got ACTION_DEVICE_CHANGED from unexpected device: " + mGBDevice);
|
LOG.error("Got ACTION_DEVICE_CHANGED from unexpected device: " + mGBDevice);
|
||||||
|
@ -397,7 +399,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||||
case ACTION_DISCONNECT: {
|
case ACTION_DISCONNECT: {
|
||||||
mDeviceSupport.dispose();
|
mDeviceSupport.dispose();
|
||||||
if (mGBDevice != null && mGBDevice.getState() == GBDevice.State.WAITING_FOR_RECONNECT) {
|
if (mGBDevice != null && mGBDevice.getState() == GBDevice.State.WAITING_FOR_RECONNECT) {
|
||||||
setReceiversEnableState(false, false);
|
setReceiversEnableState(false, false, null);
|
||||||
mGBDevice.setState(GBDevice.State.NOT_CONNECTED);
|
mGBDevice.setState(GBDevice.State.NOT_CONNECTED);
|
||||||
mGBDevice.sendDeviceUpdateIntent(this);
|
mGBDevice.sendDeviceUpdateIntent(this);
|
||||||
}
|
}
|
||||||
|
@ -575,10 +577,10 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setReceiversEnableState(boolean enable, boolean initialized) {
|
private void setReceiversEnableState(boolean enable, boolean initialized, DeviceCoordinator coordinator) {
|
||||||
LOG.info("Setting broadcast receivers to: " + enable);
|
LOG.info("Setting broadcast receivers to: " + enable);
|
||||||
|
|
||||||
if (enable && initialized) {
|
if (enable && initialized && coordinator != null && coordinator.supportsCalendarEvents()) {
|
||||||
if (mCalendarReceiver == null) {
|
if (mCalendarReceiver == null) {
|
||||||
IntentFilter calendarIntentFilter = new IntentFilter();
|
IntentFilter calendarIntentFilter = new IntentFilter();
|
||||||
calendarIntentFilter.addAction("android.intent.action.PROVIDER_CHANGED");
|
calendarIntentFilter.addAction("android.intent.action.PROVIDER_CHANGED");
|
||||||
|
@ -587,10 +589,20 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||||
mCalendarReceiver = new CalendarReceiver(mGBDevice);
|
mCalendarReceiver = new CalendarReceiver(mGBDevice);
|
||||||
registerReceiver(mCalendarReceiver, calendarIntentFilter);
|
registerReceiver(mCalendarReceiver, calendarIntentFilter);
|
||||||
}
|
}
|
||||||
} else if (mCalendarReceiver != null) {
|
if (mAlarmReceiver == null) {
|
||||||
|
mAlarmReceiver = new AlarmReceiver();
|
||||||
|
registerReceiver(mAlarmReceiver, new IntentFilter("DAILY_ALARM"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (mCalendarReceiver != null) {
|
||||||
unregisterReceiver(mCalendarReceiver);
|
unregisterReceiver(mCalendarReceiver);
|
||||||
mCalendarReceiver = null;
|
mCalendarReceiver = null;
|
||||||
}
|
}
|
||||||
|
if (mAlarmReceiver != null) {
|
||||||
|
unregisterReceiver(mAlarmReceiver);
|
||||||
|
mAlarmReceiver = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
if (mPhoneCallReceiver == null) {
|
if (mPhoneCallReceiver == null) {
|
||||||
|
@ -631,11 +643,6 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||||
mBlueToothPairingRequestReceiver = new BluetoothPairingRequestReceiver(this);
|
mBlueToothPairingRequestReceiver = new BluetoothPairingRequestReceiver(this);
|
||||||
registerReceiver(mBlueToothPairingRequestReceiver, new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST));
|
registerReceiver(mBlueToothPairingRequestReceiver, new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mAlarmReceiver == null) {
|
|
||||||
mAlarmReceiver = new AlarmReceiver();
|
|
||||||
registerReceiver(mAlarmReceiver, new IntentFilter("DAILY_ALARM"));
|
|
||||||
}
|
|
||||||
if (mAlarmClockReceiver == null) {
|
if (mAlarmClockReceiver == null) {
|
||||||
mAlarmClockReceiver = new AlarmClockReceiver();
|
mAlarmClockReceiver = new AlarmClockReceiver();
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
|
@ -673,11 +680,6 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||||
unregisterReceiver(mBlueToothPairingRequestReceiver);
|
unregisterReceiver(mBlueToothPairingRequestReceiver);
|
||||||
mBlueToothPairingRequestReceiver = null;
|
mBlueToothPairingRequestReceiver = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mAlarmReceiver != null) {
|
|
||||||
unregisterReceiver(mAlarmReceiver);
|
|
||||||
mAlarmReceiver = null;
|
|
||||||
}
|
|
||||||
if (mAlarmClockReceiver != null) {
|
if (mAlarmClockReceiver != null) {
|
||||||
unregisterReceiver(mAlarmClockReceiver);
|
unregisterReceiver(mAlarmClockReceiver);
|
||||||
mAlarmClockReceiver = null;
|
mAlarmClockReceiver = null;
|
||||||
|
@ -695,7 +697,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||||
setReceiversEnableState(false, false); // disable BroadcastReceivers
|
setReceiversEnableState(false, false, null); // disable BroadcastReceivers
|
||||||
|
|
||||||
setDeviceSupport(null);
|
setDeviceSupport(null);
|
||||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
Loading…
Reference in New Issue