Beispiel #1
0
 public LocationUpdateHandler()
 {
     locationDependencyService = DependencyService.Get <ILocationService>();
     startLocation             = null;
     trackedCoordinateItem     = null;
     trackedPlaceTypeItem      = null;
 }
Beispiel #2
0
 public Task <int> SavePlaceTypeAsync(PlaceTypeItem item)
 {
     if (item.ID != 0)
     {
         return(_database.UpdateAsync(item));
     }
     else
     {
         return(_database.InsertAsync(item));
     }
 }
        async void OnToggle(object sender, ToggledEventArgs e)
        {
            if (_initial)
            {
                return;
            }

            Switch        sw        = sender as Switch;
            PlaceTypeItem placeType = sw.BindingContext as PlaceTypeItem;
            await App.Database.SavePlaceTypeAsync(placeType);
        }
Beispiel #4
0
        private async Task PlaceTypeDetection(Location location)
        {
            PlaceTypeItem foundPTI = await LocationDetails.GetNearbyPlaceTypeItem(location);

            if (foundPTI == null)
            {
                await DisplayAlert("Place Type Detection Results", $"No place types were found near ({location.Latitude}, {location.Longitude}).", "OK");
            }
            else
            {
                await DisplayAlert("Place Type Detection Results", $"The place type named \"{foundPTI.Name}\" was found near ({location.Latitude}, {location.Longitude}).", "OK");
            }
        }
Beispiel #5
0
 public static void AddHistoryItem(PlaceTypeItem placeItem, string action)
 {
     if (action.Equals(Constants.actionEnter))
     {
         _ = AddHistoryItem(placeItem, true);
     }
     else if (action.Equals(Constants.actionExit))
     {
         _ = AddHistoryItem(placeItem, false);
     }
     else
     {
         throw new ArgumentException($"The action must either be Constants.actionEnter: {Constants.actionEnter}, or Constants.actionExit: {Constants.actionExit}.", "action");
     }
 }
Beispiel #6
0
        private async Task TriggerAlert(PlaceTypeItem item, bool action)
        {
            Debug.WriteLine($"Triggered Alter for {item.Name}, {action}");
            int id = await LocationDetails.AddHistoryItem(item, action);

            string notifTitle;
            string notifText;

            if (action)
            {
                notifTitle = $"{Constants.actionEnter} {Constants.placeTypeName}: {item.NameReadable}";
                notifText  = $"Reminder to {item.OnEnterReminder}";
            }
            else
            {
                notifTitle = $"{Constants.actionExit} {Constants.placeTypeName}: {item.NameReadable}";
                notifText  = $"Reminder to {item.OnExitReminder}";
            }

            locationDependencyService.UpdateNotification(notifTitle, notifText, id);
        }
Beispiel #7
0
        public static async Task <int> AddHistoryItem(PlaceTypeItem placeItem, bool action)
        {
            int id = await App.Database.SaveHistoryAsync(new HistoryItem
            {
                OriginID    = placeItem.ID,
                TrackedType = Constants.placeTypeName,
                Name        = placeItem.NameReadable,
                Action      = action ? Constants.actionEnter : Constants.actionExit,
                Reminder    = action ? placeItem.OnEnterReminder : placeItem.OnExitReminder
            });

            if (action)
            {
                Debug.WriteLine($"A history item for {Constants.actionEnter} - {Constants.placeTypeName}: {placeItem.Name}, action: {placeItem.OnEnterReminder}, was created.");
            }
            else
            {
                Debug.WriteLine($"A history item for {Constants.actionExit} - {Constants.placeTypeName}: {placeItem.Name}, action: {placeItem.OnExitReminder}, was created.");
            }

            return(id);
        }
        async void OnAddHistoryButtonClicked(object sender, EventArgs e)
        {
            Button        aButton       = sender as Button;
            PlaceTypeItem placeTypeItem = aButton.BindingContext as PlaceTypeItem;

            string action;

            if (placeTypeItem.OnEnter)
            {
                if (placeTypeItem.OnExit)
                {
                    action = await DisplayActionSheet("Adding manual history activity, select the movement type.", "Cancel", null, Constants.actionEnter, Constants.actionExit);
                }
                else
                {
                    action = await DisplayActionSheet("Adding manual history activity, select the movement type.", "Cancel", null, Constants.actionEnter);
                }
            }
            else if (placeTypeItem.OnExit)
            {
                action = await DisplayActionSheet("Adding manual history activity, select the movement type.", "Cancel", null, Constants.actionExit);
            }
            else
            {
                throw new System.ArgumentException("All place type items must have an on enter and/or an on exit reminder.", "placeTypeItem.OnEnter, placeTypeItem.OnExit");
            }

            if (action == null || action.Equals("Cancel"))
            {
                return;
            }

            LocationDetails.AddHistoryItem(placeTypeItem, action);

            //await DisplayAlert("History Item added", $"A history item for {placeTypeItem.Name} was created.", "OK");
        }
Beispiel #9
0
        /*public async void StartLocationHandler()
         * {
         *
         * }*/

        public async Task UpdateLocation(double latitude, double longitude)
        {
            Location newLocation = new Location(latitude, longitude);

            Debug.WriteLine($"Updated location: ({latitude}, {longitude})");

            if (App.Settings.CoordinateTrackingEnabled)
            {
                if (trackedCoordinateItem != null)
                {
                    if (!LocationDetails.IsInLocation(newLocation, trackedCoordinateItem))
                    {
                        if (trackedCoordinateItem.OnExit)
                        {
                            _ = TriggerAlert(trackedCoordinateItem, false);
                        }
                        trackedCoordinateItem = null;
                    }
                    return;
                }

                CoordinateItem foundCoordinateItem = await App.Database.QueryCoordinatesAsync(newLocation);

                if (foundCoordinateItem != null)
                {
                    trackedCoordinateItem = foundCoordinateItem;
                    if (trackedCoordinateItem.OnEnter)
                    {
                        _ = TriggerAlert(trackedCoordinateItem, true);
                    }
                    return;
                }
            }

            /*else
             * {
             *  trackedCoordinateItem = null;
             * }*/

            if (App.Settings.PlaceTrackingEnabled)
            {
                if (trackedPlaceTypeItem != null)
                {
                    if (!LocationDetails.IsInLocation(newLocation, startLocation, App.Settings.PlaceTypeLeaveRadius))
                    {
                        List <string> foundPlaceTypes = await LocationDetails.GetNearbyPlaceTypes(newLocation);

                        if (foundPlaceTypes.Exists(x => x.Equals(trackedPlaceTypeItem.Name)))
                        {
                            startLocation = newLocation;
                        }
                        else
                        {
                            if (trackedPlaceTypeItem.OnExit)
                            {
                                _ = TriggerAlert(trackedPlaceTypeItem, false);
                            }
                            trackedPlaceTypeItem = null;
                        }
                    }
                    return;
                }
                else
                {
                    List <string> foundPlaceTypes = await LocationDetails.GetNearbyPlaceTypes(newLocation);

                    if (foundPlaceTypes.Any())
                    {
                        PlaceTypeItem foundPlaceTypeItem = await App.Database.QueryPlaceTypes(foundPlaceTypes);

                        if (foundPlaceTypeItem != null)
                        {
                            trackedPlaceTypeItem = foundPlaceTypeItem;
                            if (trackedPlaceTypeItem.OnEnter)
                            {
                                _ = TriggerAlert(trackedPlaceTypeItem, true);
                            }
                            startLocation = newLocation;
                            return;
                        }
                    }
                }
            }

            /*else
             * {
             *  trackedPlaceTypeItem = null;
             * }*/
        }
        async void OnItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (e.Item == null)
            {
                return;
            }

            PlaceTypeItem placeType = e.Item as PlaceTypeItem;

            string placeTypeNameReadable = placeType.NameReadable;
            bool   answer = await DisplayAlert(placeTypeNameReadable, placeType.Details, "EDIT", "OK");

            if (answer)
            {
                string action = await DisplayActionSheet($"Select {placeTypeNameReadable} Action Reminder To Edit", "Cancel", null, Constants.actionEnter, Constants.actionExit);

                if (action == null || action.Equals("Cancel"))
                {
                    return;
                }

                string action2;
                if (action.Equals(Constants.actionEnter))
                {
                    if (placeType.OnExit)
                    {
                        action2 = await DisplayActionSheet($"Setting {placeTypeNameReadable} On Enter Reminder", "Cancel", null, "Clear", Constants.wearMask, Constants.washHands, Constants.washHandsAndWearMask);
                    }
                    else
                    {
                        action2 = await DisplayActionSheet($"Setting {placeTypeNameReadable} On Enter Reminder", "Cancel", null, Constants.wearMask, Constants.washHands, Constants.washHandsAndWearMask);
                    }

                    if (action2 == null || action2.Equals("Cancel"))
                    {
                        return;
                    }

                    if (action2.Equals("Clear"))
                    {
                        placeType.OnEnter         = false;
                        placeType.OnEnterReminder = "";
                    }
                    else
                    {
                        placeType.OnEnter         = true;
                        placeType.OnEnterReminder = action2;
                    }
                }
                else
                {
                    if (placeType.OnEnter)
                    {
                        action2 = await DisplayActionSheet($"Setting {placeTypeNameReadable} On Exit Reminder", "Cancel", null, "Clear", Constants.wearMask, Constants.washHands, Constants.washHandsAndWearMask);
                    }
                    else
                    {
                        action2 = await DisplayActionSheet($"Setting {placeTypeNameReadable} On Exit Reminder", "Cancel", null, Constants.wearMask, Constants.washHands, Constants.washHandsAndWearMask);
                    }

                    if (action2 == null || action2.Equals("Cancel"))
                    {
                        return;
                    }

                    if (action2.Equals("Clear"))
                    {
                        placeType.OnExit         = false;
                        placeType.OnExitReminder = "";
                    }
                    else
                    {
                        placeType.OnExit         = true;
                        placeType.OnExitReminder = action2;
                    }
                }

                await App.Database.SavePlaceTypeAsync(placeType);
            }
        }