Ejemplo n.º 1
0
 public LocationUpdateHandler()
 {
     locationDependencyService = DependencyService.Get <ILocationService>();
     startLocation             = null;
     trackedCoordinateItem     = null;
     trackedPlaceTypeItem      = null;
 }
Ejemplo n.º 2
0
 public static bool IsInLocation(Location locationStart, CoordinateItem coordItem)
 {
     if (Location.CalculateDistance(locationStart, coordItem.Latitude, coordItem.Longitude, DistanceUnits.Kilometers) * 1000 <= coordItem.Radius)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
 public CoordinatesAddPage(CoordinateItem itemToEdit = null)
 {
     editingItem = itemToEdit;
     pickerList  = new List <string>();
     pickerList.Add(Constants.washHands);
     pickerList.Add(Constants.wearMask);
     pickerList.Add(Constants.washHandsAndWearMask);
     InitializeComponent();
 }
Ejemplo n.º 4
0
        async void OnItemToggle(object sender, ToggledEventArgs e)
        {
            if (_initial)
            {
                return;
            }

            Switch         sw             = sender as Switch;
            CoordinateItem coordinateItem = sw.BindingContext as CoordinateItem;
            await App.Database.SaveCoordinateAsync(coordinateItem);
        }
Ejemplo n.º 5
0
        async void OnItemTapped(object sender, ItemTappedEventArgs e)
        {
            CoordinateItem tappedCoordinateItem = e.Item as CoordinateItem;

            bool answer = await DisplayAlert(tappedCoordinateItem.Name, tappedCoordinateItem.Details, "EDIT", "OK");

            if (answer)
            {
                await Navigation.PushAsync(new CoordinatesAddPage(tappedCoordinateItem));
            }
        }
Ejemplo n.º 6
0
 public Task <int> SaveCoordinateAsync(CoordinateItem coordinate)
 {
     if (coordinate.ID != 0)
     {
         return(_database.UpdateAsync(coordinate));
     }
     else
     {
         return(_database.InsertAsync(coordinate));
     }
 }
Ejemplo n.º 7
0
        private async Task CoordinateDetection(Location location)
        {
            CoordinateItem foundCI = await App.Database.QueryCoordinatesAsync(location);

            if (foundCI == null)
            {
                await DisplayAlert("Coordinate Detection Results", $"No coordinates were found near ({location.Latitude}, {location.Longitude}).", "OK");
            }
            else
            {
                await DisplayAlert("Coordinate Detection Results", $"The coordinate named \"{foundCI.Name}\" was found near ({location.Latitude}, {location.Longitude}).", "OK");
            }
        }
Ejemplo n.º 8
0
 public static void AddHistoryItem(CoordinateItem coordItem, string action)
 {
     if (action.Equals(Constants.actionEnter))
     {
         _ = AddHistoryItem(coordItem, true);
     }
     else if (action.Equals(Constants.actionExit))
     {
         _ = AddHistoryItem(coordItem, false);
     }
     else
     {
         throw new ArgumentException($"The action must either be Constants.actionEnter: {Constants.actionEnter}, or Constants.actionExit: {Constants.actionExit}.", "action");
     }
 }
Ejemplo n.º 9
0
        private async Task TriggerAlert(CoordinateItem 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.coordinateName}: {item.Name}";
                notifText  = $"Reminder to {item.OnEnterReminder}";
            }
            else
            {
                notifTitle = $"{Constants.actionExit} {Constants.coordinateName}: {item.Name}";
                notifText  = $"Reminder to {item.OnExitReminder}";
            }

            locationDependencyService.UpdateNotification(notifTitle, notifText, id);
        }
Ejemplo n.º 10
0
        public static async Task <int> AddHistoryItem(CoordinateItem coordItem, bool action)
        {
            int id = await App.Database.SaveHistoryAsync(new HistoryItem
            {
                OriginID    = coordItem.ID,
                TrackedType = Constants.coordinateName,
                Name        = coordItem.Name,
                Action      = action ? Constants.actionEnter : Constants.actionExit,
                Reminder    = action ? coordItem.OnEnterReminder : coordItem.OnExitReminder
            });

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

            return(id);
        }
Ejemplo n.º 11
0
        async void OnAddHistoryButtonClicked(object sender, EventArgs e)
        {
            Button         aButton        = sender as Button;
            CoordinateItem coordinateItem = aButton.BindingContext as CoordinateItem;

            string action;

            if (coordinateItem.OnEnter)
            {
                if (coordinateItem.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 (coordinateItem.OnExit)
            {
                action = await DisplayActionSheet("Adding manual history activity, select the movement type.", "Cancel", null, Constants.actionExit);
            }
            else
            {
                throw new System.ArgumentException("All coordinate Items must have an on enter and/or an on exit reminder.", "coordinateItem.OnEnter, coordinateItem.OnExit");
            }

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

            LocationDetails.AddHistoryItem(coordinateItem, action);

            //await DisplayAlert("History Item added", $"A history item for {coordinateItem.Name} was created.", "OK");
        }
Ejemplo n.º 12
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;
             * }*/
        }
Ejemplo n.º 13
0
 public Task <int> DeleteCoordinateAsync(CoordinateItem coordinate)
 {
     return(_database.DeleteAsync(coordinate));
 }
Ejemplo n.º 14
0
        async void OnAddButtonClicked(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(nameEntry.Text))
            {
                await DisplayAlert("Incomplete Name Entry", "A name entry is required.", "OK");

                return;
            }

            if (string.IsNullOrWhiteSpace(latitudeEntry.Text) || string.IsNullOrWhiteSpace(longitudeEntry.Text))
            {
                await DisplayAlert("Incomplete Latitude or Longitude Entry", "Both a Latitude and Longitude entry is required.", "OK");

                return;
            }

            if (!await LocationDetails.ValidateCoordinates(latitudeEntry.Text, longitudeEntry.Text))
            {
                return;
            }

            // radius
            if (string.IsNullOrWhiteSpace(radiusEntry.Text))
            {
                await DisplayAlert("Incomplete Radius Entry", "A radius entry is required.", "OK");

                return;
            }

            try
            {
                int.Parse(radiusEntry.Text);
            }
            catch
            {
                await DisplayAlert("Invalid Radius Entry", "The radius entry must be a whole number.", "OK");

                return;
            }

            //seconds

            /*if (string.IsNullOrWhiteSpace(secondsEntry.Text))
             * {
             *  await DisplayAlert("Incomplete Seconds Entry", "A seconds entry is required.", "OK");
             *  return;
             * }
             *
             * try
             * {
             *  int.Parse(secondsEntry.Text);
             * }
             * catch
             * {
             *  await DisplayAlert("Invalid Seconds Entry", "The seconds entry must be a whole number.", "OK");
             *  return;
             * }*/

            // reminders
            if (onEnterPicker.SelectedIndex == -1 && onExitPicker.SelectedIndex == -1)
            {
                await DisplayAlert("Incomplete Reminders", "At least one reminder needs to be chosen.", "OK");

                return;
            }

            string onEnterReminder = "";

            if (onEnterPicker.SelectedIndex != -1)
            {
                onEnterReminder = onEnterPicker.SelectedItem.ToString();
            }

            string onExitReminder = "";

            if (onExitPicker.SelectedIndex != -1)
            {
                onExitReminder = onExitPicker.SelectedItem.ToString();
            }

            try
            {
                if (editingItem != null)
                {
                    editingItem.Name      = nameEntry.Text;
                    editingItem.Latitude  = double.Parse(latitudeEntry.Text);
                    editingItem.Longitude = double.Parse(longitudeEntry.Text);
                    editingItem.Radius    = int.Parse(radiusEntry.Text);
                    //editingItem.Seconds = int.Parse(secondsEntry.Text);
                    editingItem.OnEnter         = onEnterPicker.SelectedIndex != -1;
                    editingItem.OnExit          = onExitPicker.SelectedIndex != -1;
                    editingItem.OnEnterReminder = onEnterReminder;
                    editingItem.OnExitReminder  = onExitReminder;
                }
                else
                {
                    editingItem = new CoordinateItem
                    {
                        Name      = nameEntry.Text,
                        Latitude  = double.Parse(latitudeEntry.Text),
                        Longitude = double.Parse(longitudeEntry.Text),
                        Radius    = int.Parse(radiusEntry.Text),
                        //Seconds = int.Parse(secondsEntry.Text),
                        Seconds         = 0,
                        OnEnter         = onEnterPicker.SelectedIndex != -1,
                        OnExit          = onExitPicker.SelectedIndex != -1,
                        OnEnterReminder = onEnterReminder,
                        OnExitReminder  = onExitReminder,
                        IsOn            = false
                    };
                }
            }
            catch
            {
                await DisplayAlert("Invalid Entry", "An entry field contains invalid characters.", "OK");

                return;
            }

            await App.Database.SaveCoordinateAsync(editingItem);

            await Navigation.PopAsync();
        }