Fix corner case

This commit is contained in:
Mieszko Wrzeszczyński 2019-01-03 20:03:46 +01:00
parent b81e28cd61
commit 8e94d86968

View File

@ -184,25 +184,26 @@ public class BackgroundLocalizationService extends Service {
}
private void changeBackgroundMode() {
if (coordinatesHistory.size() > 4) {
Integer prevInterval = notify_interval;
Boolean shouldExtendTimeInterval = Stream.of(coordinatesHistory)
.map(MapUtils::checkIfCoordinateIsValid).takeWhile(s -> !s).toList().size() == coordinatesHistory.size();
Boolean shouldAbbreviateTimeInterval = Stream.of(coordinatesHistory).
filter(MapUtils::checkIfCoordinateIsValid).toList().size() > 0;
map(MapUtils::checkIfCoordinateIsValid).filter(x -> x).toList().size() > 0;
if (shouldExtendTimeInterval) {
notify_interval = notify_interval_outside_building;
} else if (shouldAbbreviateTimeInterval) {
if (shouldAbbreviateTimeInterval) {
notify_interval = notify_interval_inside_building;
}
if (coordinatesHistory.size() > 4 && shouldExtendTimeInterval) {
notify_interval = notify_interval_outside_building;
}
Integer changedMode = Long.valueOf(prevInterval).compareTo(Long.valueOf(notify_interval));
if (changedMode != 0) {
updateListeners();
}
}
}
@RequiresApi(api = Build.VERSION_CODES.O)