mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Allow DeviceService to target a specific device
This commit is contained in:
parent
226d75d366
commit
005276248f
@ -330,6 +330,16 @@ public class GBApplication extends Application {
|
||||
return deviceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the facade for talking to a specific device. Devices are managed by
|
||||
* an Android Service and this facade provides access to its functionality.
|
||||
*
|
||||
* @return the facade for talking to the service/device.
|
||||
*/
|
||||
public static DeviceService deviceService(GBDevice device) {
|
||||
return deviceService.forDevice(device);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the DBHandler instance for reading/writing or throws GBException
|
||||
* when that was not successful
|
||||
|
@ -129,7 +129,7 @@ public class SleepAlarmWidget extends AppWidgetProvider {
|
||||
Alarm alarm = AlarmUtils.createSingleShot(0, true, false, calendar);
|
||||
ArrayList<Alarm> alarms = new ArrayList<>(1);
|
||||
alarms.add(alarm);
|
||||
GBApplication.deviceService().onSetAlarms(alarms);
|
||||
GBApplication.deviceService(deviceForWidget).onSetAlarms(alarms);
|
||||
|
||||
// if (GBApplication.isRunningLollipopOrLater()) {
|
||||
// setAlarmViaAlarmManager(context, calendar.getTimeInMillis());
|
||||
|
@ -181,7 +181,7 @@ public class Widget extends AppWidgetProvider {
|
||||
GB.toast(context,
|
||||
context.getString(R.string.device_not_connected),
|
||||
Toast.LENGTH_SHORT, GB.ERROR);
|
||||
GBApplication.deviceService().connect();
|
||||
GBApplication.deviceService(deviceForWidget).connect();
|
||||
GB.toast(context,
|
||||
context.getString(R.string.connecting),
|
||||
Toast.LENGTH_SHORT, GB.INFO);
|
||||
@ -192,7 +192,7 @@ public class Widget extends AppWidgetProvider {
|
||||
context.getString(R.string.busy_task_fetch_activity_data),
|
||||
Toast.LENGTH_SHORT, GB.INFO);
|
||||
|
||||
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||
GBApplication.deviceService(deviceForWidget).onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||
}
|
||||
|
||||
public void updateWidget() {
|
||||
|
@ -369,7 +369,7 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
||||
|
||||
private void fetchTrackData() {
|
||||
if (mGBDevice.isInitialized() && !mGBDevice.isBusy()) {
|
||||
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_GPS_TRACKS);
|
||||
GBApplication.deviceService(mGBDevice).onFetchRecordedData(RecordedDataTypes.TYPE_GPS_TRACKS);
|
||||
} else {
|
||||
swipeLayout.setRefreshing(false);
|
||||
if (!mGBDevice.isInitialized()) {
|
||||
|
@ -173,7 +173,7 @@ public class ConfigureAlarms extends AbstractGBActivity {
|
||||
}
|
||||
|
||||
private void sendAlarmsToDevice() {
|
||||
GBApplication.deviceService().onSetAlarms(mGBAlarmListAdapter.getAlarmList());
|
||||
GBApplication.deviceService(gbDevice).onSetAlarms(mGBAlarmListAdapter.getAlarmList());
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
|
@ -176,7 +176,7 @@ public class ConfigureReminders extends AbstractGBActivity {
|
||||
|
||||
private void sendRemindersToDevice() {
|
||||
if (gbDevice.isInitialized()) {
|
||||
GBApplication.deviceService().onSetReminders(mGBReminderListAdapter.getReminderList());
|
||||
GBApplication.deviceService(gbDevice).onSetReminders(mGBReminderListAdapter.getReminderList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ public class ConfigureWorldClocks extends AbstractGBActivity {
|
||||
|
||||
private void sendWorldClocksToDevice() {
|
||||
if (gbDevice.isInitialized()) {
|
||||
GBApplication.deviceService().onSetWorldClocks(mGBWorldClockListAdapter.getWorldClockList());
|
||||
GBApplication.deviceService(gbDevice).onSetWorldClocks(mGBWorldClockListAdapter.getWorldClockList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal
|
||||
|
||||
private void connect() {
|
||||
mayConnect = false; // only do that once per #onCreate
|
||||
GBApplication.deviceService().connect(device);
|
||||
GBApplication.deviceService(device).connect();
|
||||
}
|
||||
|
||||
private void validateInstallation() {
|
||||
@ -200,7 +200,7 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal
|
||||
public void onClick(View v) {
|
||||
setInstallEnabled(false);
|
||||
installHandler.onStartInstall(device);
|
||||
GBApplication.deviceService().onInstallApp(uri);
|
||||
GBApplication.deviceService(device).onInstallApp(uri);
|
||||
}
|
||||
});
|
||||
|
||||
@ -231,7 +231,7 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal
|
||||
if (device == null || !device.isConnected()) {
|
||||
connect();
|
||||
} else {
|
||||
GBApplication.deviceService().requestDeviceInfo();
|
||||
GBApplication.deviceService(device).requestDeviceInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class WidgetAlarmsActivity extends Activity implements View.OnClickListen
|
||||
Alarm alarm = AlarmUtils.createSingleShot(0, true, true, calendar);
|
||||
ArrayList<Alarm> alarms = new ArrayList<>(1);
|
||||
alarms.add(alarm);
|
||||
GBApplication.deviceService().onSetAlarms(alarms);
|
||||
GBApplication.deviceService(deviceForWidget).onSetAlarms(alarms);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||
LocalBroadcastManager.getInstance(getContext()).registerReceiver(mReceiver, filter);
|
||||
|
||||
if (mCoordinator.supportsAppListFetching()) {
|
||||
GBApplication.deviceService().onAppInfoReq();
|
||||
GBApplication.deviceService(mGBDevice).onAppInfoReq();
|
||||
if (isCacheManager()) {
|
||||
refreshList();
|
||||
}
|
||||
@ -391,7 +391,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||
ArrayList<UUID> concatUuids = AppManagerActivity.getUuidsFromFile(concatFilename);
|
||||
uuids.addAll(concatUuids);
|
||||
}
|
||||
GBApplication.deviceService().onAppReorder(uuids.toArray(new UUID[uuids.size()]));
|
||||
GBApplication.deviceService(mGBDevice).onAppReorder(uuids.toArray(new UUID[uuids.size()]));
|
||||
}
|
||||
|
||||
public void onItemClick(View view, GBDeviceApp deviceApp) {
|
||||
@ -399,7 +399,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||
openPopupMenu(view, deviceApp);
|
||||
} else {
|
||||
UUID uuid = deviceApp.getUUID();
|
||||
GBApplication.deviceService().onAppStart(uuid, true);
|
||||
GBApplication.deviceService(mGBDevice).onAppStart(uuid, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -506,11 +506,11 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||
refreshIntent = new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST);
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent);
|
||||
}
|
||||
GBApplication.deviceService().onAppDelete(selectedApp.getUUID());
|
||||
GBApplication.deviceService(mGBDevice).onAppDelete(selectedApp.getUUID());
|
||||
return true;
|
||||
case R.id.appmanager_app_reinstall:
|
||||
File cachePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
|
||||
GBApplication.deviceService().onInstallApp(Uri.fromFile(cachePath));
|
||||
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.fromFile(cachePath));
|
||||
return true;
|
||||
case R.id.appmanager_app_share:
|
||||
File origFilePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
|
||||
@ -533,24 +533,24 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||
}
|
||||
return true;
|
||||
case R.id.appmanager_health_activate:
|
||||
GBApplication.deviceService().onInstallApp(Uri.parse("fake://health"));
|
||||
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://health"));
|
||||
return true;
|
||||
case R.id.appmanager_hrm_activate:
|
||||
GBApplication.deviceService().onInstallApp(Uri.parse("fake://hrm"));
|
||||
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://hrm"));
|
||||
return true;
|
||||
case R.id.appmanager_weather_activate:
|
||||
GBApplication.deviceService().onInstallApp(Uri.parse("fake://weather"));
|
||||
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://weather"));
|
||||
return true;
|
||||
case R.id.appmanager_health_deactivate:
|
||||
case R.id.appmanager_hrm_deactivate:
|
||||
case R.id.appmanager_weather_deactivate:
|
||||
GBApplication.deviceService().onAppDelete(selectedApp.getUUID());
|
||||
GBApplication.deviceService(mGBDevice).onAppDelete(selectedApp.getUUID());
|
||||
return true;
|
||||
case R.id.appmanager_weather_install_provider:
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://f-droid.org/app/ru.gelin.android.weather.notification")));
|
||||
return true;
|
||||
case R.id.appmanager_app_configure:
|
||||
GBApplication.deviceService().onAppStart(selectedApp.getUUID(), true);
|
||||
GBApplication.deviceService(mGBDevice).onAppStart(selectedApp.getUUID(), true);
|
||||
|
||||
Intent startIntent = new Intent(getContext().getApplicationContext(), ExternalPebbleJSActivity.class);
|
||||
startIntent.putExtra(DeviceService.EXTRA_APP_UUID, selectedApp.getUUID());
|
||||
|
@ -359,7 +359,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
|
||||
private void fetchActivityData() {
|
||||
if (getDevice().isInitialized()) {
|
||||
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||
GBApplication.deviceService(getDevice()).onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||
} else {
|
||||
swipeLayout.setRefreshing(false);
|
||||
GB.toast(this, getString(R.string.device_not_connected), Toast.LENGTH_SHORT, GB.ERROR);
|
||||
|
@ -210,7 +210,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
|
||||
invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GBApplication.deviceService().onSendConfiguration(preferenceKey);
|
||||
GBApplication.deviceService(device).onSendConfiguration(preferenceKey);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -355,7 +355,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
|
||||
enableHeartrateSleepSupport.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||
GBApplication.deviceService().onEnableHeartRateSleepSupport(Boolean.TRUE.equals(newVal));
|
||||
GBApplication.deviceService(device).onEnableHeartRateSleepSupport(Boolean.TRUE.equals(newVal));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@ -369,7 +369,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
|
||||
|
||||
heartrateMeasurementInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(final Preference preference, final Object newVal) {
|
||||
GBApplication.deviceService().onSetHeartRateMeasurementInterval(Integer.parseInt((String) newVal));
|
||||
GBApplication.deviceService(device).onSetHeartRateMeasurementInterval(Integer.parseInt((String) newVal));
|
||||
|
||||
final boolean isMeasurementIntervalEnabled = !newVal.equals("0");
|
||||
|
||||
@ -720,7 +720,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
|
||||
CannedMessagesSpec cannedMessagesSpec = new CannedMessagesSpec();
|
||||
cannedMessagesSpec.type = CannedMessagesSpec.TYPE_REJECTEDCALLS;
|
||||
cannedMessagesSpec.cannedMessages = messages.toArray(new String[0]);
|
||||
GBApplication.deviceService().onSetCannedMessages(cannedMessagesSpec);
|
||||
GBApplication.deviceService(device).onSetCannedMessages(cannedMessagesSpec);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -285,7 +285,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
showTransientSnackbar(R.string.controlcenter_snackbar_need_longpress);
|
||||
} else {
|
||||
showTransientSnackbar(R.string.controlcenter_snackbar_connecting);
|
||||
GBApplication.deviceService().connect(device);
|
||||
GBApplication.deviceService(device).connect();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -391,7 +391,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
holder.heartRateStatusBox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GBApplication.deviceService().onHeartRateTest();
|
||||
GBApplication.deviceService(device).onHeartRateTest();
|
||||
HeartRateDialog dialog = new HeartRateDialog(context);
|
||||
dialog.show();
|
||||
}
|
||||
@ -422,7 +422,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showTransientSnackbar(R.string.busy_task_fetch_activity_data);
|
||||
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||
GBApplication.deviceService(device).onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||
}
|
||||
}
|
||||
);
|
||||
@ -436,7 +436,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showTransientSnackbar(R.string.controlcenter_snackbar_requested_screenshot);
|
||||
GBApplication.deviceService().onScreenshotReq();
|
||||
GBApplication.deviceService(device).onScreenshotReq();
|
||||
}
|
||||
}
|
||||
);
|
||||
@ -556,16 +556,16 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
context.startActivity(startIntent);
|
||||
return;
|
||||
}
|
||||
GBApplication.deviceService().onFindDevice(true);
|
||||
GBApplication.deviceService(device).onFindDevice(true);
|
||||
Snackbar.make(parent, R.string.control_center_find_lost_device, Snackbar.LENGTH_INDEFINITE).setAction(R.string.find_lost_device_you_found_it, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GBApplication.deviceService().onFindDevice(false);
|
||||
GBApplication.deviceService(device).onFindDevice(false);
|
||||
}
|
||||
}).setCallback(new Snackbar.Callback() {
|
||||
@Override
|
||||
public void onDismissed(Snackbar snackbar, int event) {
|
||||
GBApplication.deviceService().onFindDevice(false);
|
||||
GBApplication.deviceService(device).onFindDevice(false);
|
||||
super.onDismissed(snackbar, event);
|
||||
}
|
||||
}).show();
|
||||
@ -673,7 +673,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
final float frequency = fm_presets[index];
|
||||
device.setExtraInfo("fm_frequency", fm_presets[index]);
|
||||
fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", (float) frequency));
|
||||
GBApplication.deviceService().onSetFmFrequency(frequency);
|
||||
GBApplication.deviceService(device).onSetFmFrequency(frequency);
|
||||
alert[0].dismiss();
|
||||
}
|
||||
});
|
||||
@ -719,7 +719,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
} else {
|
||||
device.setExtraInfo("fm_frequency", frequency);
|
||||
fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", frequency));
|
||||
GBApplication.deviceService().onSetFmFrequency(frequency);
|
||||
GBApplication.deviceService(device).onSetFmFrequency(frequency);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -771,7 +771,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
public void onColorSelected(int dialogId, int color) {
|
||||
ledColor.setColor(color);
|
||||
device.setExtraInfo("led_color", color);
|
||||
GBApplication.deviceService().onSetLedColor(color);
|
||||
GBApplication.deviceService(device).onSetLedColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -796,7 +796,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
.setIcon(R.drawable.ic_power_settings_new)
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int whichButton) {
|
||||
GBApplication.deviceService().onPowerOff();
|
||||
GBApplication.deviceService(device).onPowerOff();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
@ -840,13 +840,13 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
case R.id.controlcenter_device_submenu_connect:
|
||||
if (device.getState() != GBDevice.State.CONNECTED) {
|
||||
showTransientSnackbar(R.string.controlcenter_snackbar_connecting);
|
||||
GBApplication.deviceService().connect(device);
|
||||
GBApplication.deviceService(device).connect();
|
||||
}
|
||||
return true;
|
||||
case R.id.controlcenter_device_submenu_disconnect:
|
||||
if (device.getState() != GBDevice.State.NOT_CONNECTED) {
|
||||
showTransientSnackbar(R.string.controlcenter_snackbar_disconnecting);
|
||||
GBApplication.deviceService().disconnect(device);
|
||||
GBApplication.deviceService(device).disconnect();
|
||||
}
|
||||
return true;
|
||||
case R.id.controlcenter_device_submenu_set_alias:
|
||||
|
@ -94,7 +94,7 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
|
||||
public void deleteDevice(final GBDevice gbDevice) throws GBException {
|
||||
LOG.info("will try to delete device: " + gbDevice.getName());
|
||||
if (gbDevice.isConnected() || gbDevice.isConnecting()) {
|
||||
GBApplication.deviceService().disconnect(gbDevice);
|
||||
GBApplication.deviceService(gbDevice).disconnect();
|
||||
}
|
||||
Prefs prefs = getPrefs();
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class HuamiSettingsCustomizer implements DeviceSpecificSettingsCustomizer
|
||||
tryPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(final Preference preference) {
|
||||
GBApplication.deviceService().onSendConfiguration(tryPrefKey);
|
||||
GBApplication.deviceService(device).onSendConfiguration(tryPrefKey);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -588,11 +588,11 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
||||
final Uri tempAppFileUri = Uri.fromFile(tempFile);
|
||||
if (preview) {
|
||||
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
|
||||
GBApplication.deviceService().onInstallApp(tempAppFileUri);
|
||||
GBApplication.deviceService(mGBDevice).onInstallApp(tempAppFileUri);
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GBApplication.deviceService().onAppDelete(UUID.nameUUIDFromBytes("previewWatchface".getBytes(StandardCharsets.UTF_8)));
|
||||
GBApplication.deviceService(mGBDevice).onAppDelete(UUID.nameUUIDFromBytes("previewWatchface".getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
}, 15000);
|
||||
} else {
|
||||
@ -609,14 +609,14 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
|
||||
GBApplication.deviceService().onInstallApp(tempAppFileUri);
|
||||
GBApplication.deviceService(mGBDevice).onInstallApp(tempAppFileUri);
|
||||
FossilHRInstallHandler.saveAppInCache(fossilFile, selectedBackgroundImage, wfFactory.getPreviewImage(mContext), mCoordinator, HybridHRWatchfaceDesignerActivity.this);
|
||||
}
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
|
||||
GBApplication.deviceService().onInstallApp(tempAppFileUri);
|
||||
GBApplication.deviceService(mGBDevice).onInstallApp(tempAppFileUri);
|
||||
FossilHRInstallHandler.saveAppInCache(fossilFile, selectedBackgroundImage, wfFactory.getPreviewImage(mContext), mCoordinator, HybridHRWatchfaceDesignerActivity.this);
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class BluetoothConnectReceiver extends BroadcastReceiver {
|
||||
return;
|
||||
}
|
||||
LOG.info("Will re-connect to " + gbDevice.getAddress() + "(" + gbDevice.getName() + ")");
|
||||
GBApplication.deviceService().connect(gbDevice);
|
||||
GBApplication.deviceService(gbDevice).connect();
|
||||
}
|
||||
|
||||
private GBDevice getKnownDeviceByAddressOrNull(String deviceAddress){
|
||||
|
@ -200,15 +200,15 @@ public class CalendarReceiver extends BroadcastReceiver {
|
||||
calendarEventSpec.location = calendarEvent.getLocation();
|
||||
calendarEventSpec.type = CalendarEventSpec.TYPE_UNKNOWN;
|
||||
if (syncState == EventState.NEEDS_UPDATE) {
|
||||
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_UNKNOWN, i);
|
||||
GBApplication.deviceService(mGBDevice).onDeleteCalendarEvent(CalendarEventSpec.TYPE_UNKNOWN, i);
|
||||
}
|
||||
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
||||
GBApplication.deviceService(mGBDevice).onAddCalendarEvent(calendarEventSpec);
|
||||
es.setState(EventState.SYNCED);
|
||||
eventState.put(i, es);
|
||||
// update db
|
||||
session.insertOrReplace(new CalendarSyncState(null, deviceId, i, es.event.hashCode()));
|
||||
} else if (syncState == EventState.NEEDS_DELETE) {
|
||||
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_UNKNOWN, i);
|
||||
GBApplication.deviceService(mGBDevice).onDeleteCalendarEvent(CalendarEventSpec.TYPE_UNKNOWN, i);
|
||||
eventState.remove(i);
|
||||
// delete from db for current device only
|
||||
QueryBuilder<CalendarSyncState> qb = session.getCalendarSyncStateDao().queryBuilder();
|
||||
|
@ -53,6 +53,7 @@ import static nodomain.freeyourgadget.gadgetbridge.util.JavaExtensions.coalesce;
|
||||
|
||||
public class GBDeviceService implements DeviceService {
|
||||
protected final Context mContext;
|
||||
private final GBDevice mDevice;
|
||||
private final Class<? extends Service> mServiceClass;
|
||||
public static final String[] transliterationExtras = new String[]{
|
||||
EXTRA_NOTIFICATION_SENDER,
|
||||
@ -69,10 +70,20 @@ public class GBDeviceService implements DeviceService {
|
||||
};
|
||||
|
||||
public GBDeviceService(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public GBDeviceService(Context context, GBDevice device) {
|
||||
mContext = context;
|
||||
mDevice = device;
|
||||
mServiceClass = DeviceCommunicationService.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceService forDevice(final GBDevice device) {
|
||||
return new GBDeviceService(mContext, device);
|
||||
}
|
||||
|
||||
protected Intent createIntent() {
|
||||
return new Intent(mContext, mServiceClass);
|
||||
}
|
||||
@ -87,6 +98,10 @@ public class GBDeviceService implements DeviceService {
|
||||
}
|
||||
}
|
||||
|
||||
if (mDevice != null) {
|
||||
intent.putExtra(GBDevice.EXTRA_DEVICE, mDevice);
|
||||
}
|
||||
|
||||
mContext.startService(intent);
|
||||
}
|
||||
|
||||
@ -102,29 +117,16 @@ public class GBDeviceService implements DeviceService {
|
||||
|
||||
@Override
|
||||
public void connect() {
|
||||
connect(null, false);
|
||||
connect(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(@Nullable GBDevice device) {
|
||||
connect(device, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(@Nullable GBDevice device, boolean firstTime) {
|
||||
public void connect(boolean firstTime) {
|
||||
Intent intent = createIntent().setAction(ACTION_CONNECT)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, device)
|
||||
.putExtra(EXTRA_CONNECT_FIRST_TIME, firstTime);
|
||||
invokeService(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(@Nullable GBDevice device) {
|
||||
Intent intent = createIntent().setAction(ACTION_DISCONNECT)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, device);
|
||||
invokeService(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
Intent intent = createIntent().setAction(ACTION_DISCONNECT);
|
||||
|
@ -150,16 +150,14 @@ public interface DeviceService extends EventHandler {
|
||||
|
||||
void connect();
|
||||
|
||||
void connect(@Nullable GBDevice device);
|
||||
|
||||
void connect(@Nullable GBDevice device, boolean firstTime);
|
||||
|
||||
void disconnect(@Nullable GBDevice device);
|
||||
void connect(boolean firstTime);
|
||||
|
||||
void disconnect();
|
||||
|
||||
void quit();
|
||||
|
||||
DeviceService forDevice(GBDevice device);
|
||||
|
||||
/**
|
||||
* Requests information from the {@link DeviceCommunicationService} about the connection state,
|
||||
* firmware info, etc.
|
||||
|
@ -82,7 +82,7 @@ public class AutoConnectIntervalReceiver extends BroadcastReceiver {
|
||||
for(GBDevice device : devices){
|
||||
if(device.getState() == GBDevice.State.WAITING_FOR_RECONNECT) {
|
||||
LOG.info("Will re-connect to " + device.getAddress() + "(" + device.getName() + ")");
|
||||
GBApplication.deviceService().connect(device);
|
||||
GBApplication.deviceService(device).connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ public class BondingUtil {
|
||||
*/
|
||||
private static void connectToGBDevice(GBDevice device) {
|
||||
if (device != null) {
|
||||
GBApplication.deviceService().connect(device, true);
|
||||
GBApplication.deviceService(device).connect(true);
|
||||
} else {
|
||||
GB.toast("Unable to connect, can't recognize the device type", Toast.LENGTH_LONG, GB.ERROR);
|
||||
}
|
||||
@ -180,8 +180,8 @@ public class BondingUtil {
|
||||
public static void connectThenComplete(BondingInterface bondingInterface, GBDevice device) {
|
||||
toast(bondingInterface.getContext(), bondingInterface.getContext().getString(R.string.discovery_trying_to_connect_to, device.getName()), Toast.LENGTH_SHORT, GB.INFO);
|
||||
// Disconnect when LE Pebble so that the user can manually initiate a connection
|
||||
GBApplication.deviceService().disconnect(device);
|
||||
GBApplication.deviceService().connect(device, true);
|
||||
GBApplication.deviceService(device).disconnect();
|
||||
GBApplication.deviceService(device).connect(true);
|
||||
bondingInterface.onBondingComplete(true);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user