Add getLiveActivityFragmentPulseInterval() to DeviceCoordinator

This commit is contained in:
René Vögeli 2024-12-31 18:55:50 +01:00 committed by José Rebelo
parent 8bb9a36a68
commit d46a30aaf2
3 changed files with 10 additions and 7 deletions

View File

@ -308,7 +308,7 @@ public class LiveActivityFragment extends AbstractActivityChartFragment<ChartsDa
enableRealtimeTracking(true); enableRealtimeTracking(true);
} }
private ScheduledExecutorService startActivityPulse() { private ScheduledExecutorService startActivityPulse(int interval) {
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
service.scheduleAtFixedRate(new Runnable() { service.scheduleAtFixedRate(new Runnable() {
@Override @Override
@ -323,7 +323,7 @@ public class LiveActivityFragment extends AbstractActivityChartFragment<ChartsDa
}); });
} }
} }
}, 0, getPulseIntervalMillis(), TimeUnit.MILLISECONDS); }, 0, interval, TimeUnit.MILLISECONDS);
return service; return service;
} }
@ -356,10 +356,6 @@ public class LiveActivityFragment extends AbstractActivityChartFragment<ChartsDa
GBApplication.deviceService(getChartsHost().getDevice()).onEnableRealtimeHeartRateMeasurement(true); GBApplication.deviceService(getChartsHost().getDevice()).onEnableRealtimeHeartRateMeasurement(true);
} }
private int getPulseIntervalMillis() {
return 1000;
}
@Override @Override
protected void onMadeVisibleInActivity() { protected void onMadeVisibleInActivity() {
super.onMadeVisibleInActivity(); super.onMadeVisibleInActivity();
@ -385,7 +381,7 @@ public class LiveActivityFragment extends AbstractActivityChartFragment<ChartsDa
if (getActivity() != null) { if (getActivity() != null) {
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} }
pulseScheduler = startActivityPulse(); pulseScheduler = startActivityPulse(getChartsHost().getDevice().getDeviceCoordinator().getLiveActivityFragmentPulseInterval());
} else { } else {
stopActivityPulse(); stopActivityPulse();
if (getActivity() != null) { if (getActivity() != null) {

View File

@ -905,6 +905,11 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
return new AbstractNotificationPattern[0]; return new AbstractNotificationPattern[0];
} }
@Override
public int getLiveActivityFragmentPulseInterval() {
return 1000;
}
@Override @Override
public boolean validateAuthKey(final String authKey) { public boolean validateAuthKey(final String authKey) {
return !(authKey.getBytes().length < 34 || !authKey.startsWith("0x")); return !(authKey.getBytes().length < 34 || !authKey.startsWith("0x"));

View File

@ -177,6 +177,8 @@ public interface DeviceCoordinator {
@Nullable @Nullable
Class<? extends Activity> getCalibrationActivity(); Class<? extends Activity> getCalibrationActivity();
int getLiveActivityFragmentPulseInterval();
/** /**
* Returns true if activity data fetching is supported by the device * Returns true if activity data fetching is supported by the device
* (with this coordinator). * (with this coordinator).