From 8e94d86968cc22c8d1d0c22989e27da225d9f85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mieszko=20Wrzeszczy=C5=84ski?= Date: Thu, 3 Jan 2019 20:03:46 +0100 Subject: [PATCH] Fix corner case --- .../BackgroundLocalizationService.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java b/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java index 86f4fbd..c05680c 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/service/BackgroundLocalizationService.java @@ -142,7 +142,7 @@ public class BackgroundLocalizationService extends Service { if (!stopService && !PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) { createFusedLocationClient(); - }else if (!stopService && + } else if (!stopService && PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) { mStatusChecker = () -> { try { @@ -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(); + 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; + Boolean shouldAbbreviateTimeInterval = Stream.of(coordinatesHistory). + map(MapUtils::checkIfCoordinateIsValid).filter(x -> x).toList().size() > 0; - if (shouldExtendTimeInterval) { - notify_interval = notify_interval_outside_building; - } else if (shouldAbbreviateTimeInterval) { - notify_interval = notify_interval_inside_building; - } - - Integer changedMode = Long.valueOf(prevInterval).compareTo(Long.valueOf(notify_interval)); - if (changedMode != 0) { - updateListeners(); - } + 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)