mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-25 16:15:55 +01:00
Register autofetch receiver in DeviceCommunicationService
This allows the register to be registered only when the device is connected, and also toggling without completely exiting the application. The logic in the receiver itself was simplified and an explanation added to the preference summary.
This commit is contained in:
parent
2a30e9486c
commit
6807714af3
@ -64,7 +64,6 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.NotificationCollectorMonitorService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBAutoFetchReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
@ -198,10 +197,6 @@ public class GBApplication extends Application {
|
||||
}
|
||||
startService(new Intent(this, NotificationCollectorMonitorService.class));
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("auto_fetch_enabled", false)) {
|
||||
registerReceiver(new GBAutoFetchReceiver(), new IntentFilter("android.intent.action.USER_PRESENT"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,6 +69,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBAutoFetchReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
||||
@ -174,6 +175,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
private BluetoothConnectReceiver mBlueToothConnectReceiver = null;
|
||||
private BluetoothPairingRequestReceiver mBlueToothPairingRequestReceiver = null;
|
||||
private AlarmClockReceiver mAlarmClockReceiver = null;
|
||||
private GBAutoFetchReceiver mGBAutoFetchReceiver = null;
|
||||
|
||||
private AlarmReceiver mAlarmReceiver = null;
|
||||
private CalendarReceiver mCalendarReceiver = null;
|
||||
@ -676,6 +678,11 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
//Nothing wrong, it just means we're not running on omnirom.
|
||||
}
|
||||
}
|
||||
if (GBApplication.getPrefs().getBoolean("auto_fetch_enabled", false) &&
|
||||
coordinator != null && coordinator.supportsActivityDataFetching()) {
|
||||
mGBAutoFetchReceiver = new GBAutoFetchReceiver();
|
||||
registerReceiver(mGBAutoFetchReceiver, new IntentFilter("android.intent.action.USER_PRESENT"));
|
||||
}
|
||||
} else {
|
||||
if (mPhoneCallReceiver != null) {
|
||||
unregisterReceiver(mPhoneCallReceiver);
|
||||
@ -717,6 +724,10 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
if (mOmniJawsObserver != null) {
|
||||
getContentResolver().unregisterContentObserver(mOmniJawsObserver);
|
||||
}
|
||||
if (mGBAutoFetchReceiver != null) {
|
||||
unregisterReceiver(mGBAutoFetchReceiver);
|
||||
mGBAutoFetchReceiver = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,8 @@ import android.content.Intent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
|
||||
|
||||
public class GBAutoFetchReceiver extends BroadcastReceiver {
|
||||
@ -22,18 +17,7 @@ public class GBAutoFetchReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
//LOG.info("User is present!");
|
||||
GBApplication application = (GBApplication) context;
|
||||
List<GBDevice> devices = application.getDeviceManager().getDevices();
|
||||
for (int i = 0; i < devices.size(); i++) {
|
||||
GBDevice device = devices.get(i);
|
||||
// Will show that the device is not connected even when the device is connected
|
||||
if (device.isInitialized()) {
|
||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||
if (coordinator.supportsActivityDataFetching() && !device.isBusy()) {
|
||||
application.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||
}
|
||||
}
|
||||
}
|
||||
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,6 +201,7 @@
|
||||
|
||||
<!-- Auto fetch activity preferences -->
|
||||
<string name="pref_auto_fetch">Auto fetch activity data</string>
|
||||
<string name="pref_auto_fetch_summary">Fetch happens upon screen unlock. Only works if a lock mechanism is set!</string>
|
||||
|
||||
<string name="not_connected">Not connected</string>
|
||||
<string name="connecting">Connecting</string>
|
||||
|
@ -533,7 +533,8 @@
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="auto_fetch_enabled"
|
||||
android:title="@string/pref_auto_fetch" />
|
||||
android:title="@string/pref_auto_fetch"
|
||||
android:summary="@string/pref_auto_fetch_summary"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
Loading…
Reference in New Issue
Block a user