예제 #1
0
        public async Task StartLocationAsync()
        {
            var message = new StartLongRunningTaskMessage();

            MessagingCenter.Send(message, "StartLongRunningTaskMessage");

            var toastMessage = new ToastMessage("Location tracking activated");

            toastMessage.ShowToast();
            mainViewModel.StrLocationOnOff = "Location tracking is on";
        }
예제 #2
0
        async void Sensor_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            List <Sensor> sensorsInDb = (List <Sensor>) await App.DatabaseContext.GetSensorsAsync();

            if (sender is Sensor sensor)
            {
                if (!sensor.IsActive)
                {
                    allSelected = false;

                    foreach (Sensor sensorDb in sensorsInDb)
                    {
                        if (sensor.Uuid == sensorDb.Uuid)
                        {
                            Sensor sensorToRemove = sensorDb;
                            await App.DatabaseContext.DeleteSensorAsync(sensorToRemove.Id);
                        }
                    }

                    var toastMessage = new ToastMessage(sensor.Name + " deactivated");
                    toastMessage.ShowToast();
                }
                else
                {
                    childViewModel = new DateAndIntervalViewModel(sensor, this);

                    if (sensor.IsActive)
                    {
                        await PopupNavigation.Instance.PushAsync(new DateAndIntervalPopup()
                        {
                            BindingContext = childViewModel
                        });
                    }
                }
            }
        }
        private async void SaveDateAndInterval(object obj)
        {
            bool addSensorToDb = false;

            if (activateAllSensors)
            {
                List <Sensor> sensorsInDb = (List <Sensor>) await App.DatabaseContext.GetSensorsAsync();

                if (sensorsInDb.Count > 0)
                {
                    foreach (Sensor sensorInList in sensorList)
                    {
                        sensorInList.DateAndInterval = new DateAndInterval(
                            DateAndInterval.Interval,
                            DateAndInterval.FromDate,
                            DateAndInterval.ToDate);

                        foreach (Sensor sensorInDb in sensorsInDb)
                        {
                            if (sensorInList.Uuid == sensorInDb.Uuid)
                            {
                                await App.DatabaseContext.UpdateSensorAsync(sensorInDb);

                                addSensorToDb = false;
                                break;
                            }
                            addSensorToDb = true;
                        }
                        if (addSensorToDb)
                        {
                            await App.DatabaseContext.AddSensorAsync(sensorInList);
                        }
                    }
                }
                else
                {
                    foreach (Sensor sensorInList in sensorList)
                    {
                        sensorInList.DateAndInterval = new DateAndInterval(
                            DateAndInterval.Interval,
                            DateAndInterval.FromDate,
                            DateAndInterval.ToDate);

                        await App.DatabaseContext.AddSensorAsync(sensorInList);
                    }
                }

                await PopupNavigation.Instance.PopAllAsync();

                var toastMessage = new ToastMessage("All sensors activated");
                toastMessage.ShowToast();
            }

            else
            {
                sensor.DateAndInterval = dateAndInterval;

                if (updateSensor)
                {
                    await App.DatabaseContext.UpdateSensorAsync(sensor);

                    await PopupNavigation.Instance.PopAllAsync();

                    var toastMessage = new ToastMessage(sensor.Name + " updated");
                    toastMessage.ShowToast();
                }
                else
                {
                    await App.DatabaseContext.AddSensorAsync(sensor);

                    await PopupNavigation.Instance.PopAllAsync();

                    var toastMessage = new ToastMessage(sensor.Name + " activated");
                    toastMessage.ShowToast();
                }
            }
        }