Esempio n. 1
0
        public void btnStartJourney_Tapped(object sender, EventArgs args)
        {
            MessagingCenter.Send <MainPage>(this, "btnStartJourney_Tapped");
            _database = new JourneyDB();
            var journey = _database.GetJourneys();

            JourneysListView.ItemsSource = journey;
        }
Esempio n. 2
0
        //This method will run, when the unit has been changed
        //Update the properties related to statistics
        public void UpdateStatistics()
        {
            IEnumerable <Journey> ahjourney;
            JourneyDB             ahdatabase = new JourneyDB();

            ahjourney = ahdatabase.GetJourneys();
            if (AHSettingsMeasurementUnit == "0")
            {
                AHStatisticsJourneys.ItemsSource = ahjourney;
            }
            else
            {
                foreach (var journey in ahjourney)
                {
                    journey.Distance = journey.Distance * 0.621371;
                }
                AHStatisticsJourneys.ItemsSource = ahjourney;
            }
        }
Esempio n. 3
0
        public MainPage()
        {
            InitializeComponent();

            _database = new JourneyDB();
            var    journey         = _database.GetJourneys();
            string measurementunit = "0";

            MyPage            = this;
            this.SizeChanged += (sender, e) => PageSize_Changed(this);

            MessagingCenter.Subscribe <AppHandler, string>(this, "MeasurementUnit_Changed", (sender, arg) =>
            {
                measurementunit = arg;
                if (measurementunit == "1")
                {
                    journey = _database.GetJourneys();
                    foreach (var item in journey)
                    {
                        item.Distance = item.Distance * 0.621371;
                        item.Unit     = "mi";
                    }
                }
                else
                {
                    journey = _database.GetJourneys();
                    foreach (var item in journey)
                    {
                        item.Unit = "km";
                    }
                }
                JourneysListView.ItemsSource = journey;
            });

            MessagingCenter.Subscribe <AppHandler, ListView>(this, "AHDeviceList_Changed", (sender, arg) =>
            {
                BluetoothDevicesListView.ItemsSource = arg.ItemsSource;
            });

            MessagingCenter.Subscribe <AppHandler, string>(this, "JourneysList_Changed", (sender, arg) =>
            {
                measurementunit = arg;
                if (measurementunit == "1")
                {
                    journey = _database.GetJourneys();
                    foreach (var item in journey)
                    {
                        item.Distance = item.Distance * 0.621371;
                        item.Unit     = "mi";
                    }
                }
                else
                {
                    journey = _database.GetJourneys();
                    foreach (var item in journey)
                    {
                        item.Unit = "km";
                    }
                }
                JourneysListView.ItemsSource = journey;
            });

            MessagingCenter.Subscribe <AppHandler>(this, "AHSettingsWheelRadius_Invalid", (sender) =>
            {
                DisplayAlert("INPUT INVALID", "Only numbers are allowed and the wheel radius has to be bigger than 0", "OK");
            });

            MessagingCenter.Subscribe <AppHandler>(this, "AHBluetooth_isOff", (sender) =>
            {
                DisplayAlert("BLUETOOTH IS OFF", "Turn on bluetooth and try again", "OK");
            });

            MessagingCenter.Subscribe <Model.BluetoothHandler>(this, "AHBluetooth_isOff", (sender) =>
            {
                DisplayAlert("BLUETOOTH IS OFF", "Turn on bluetooth and try again", "OK");
            });

            MessagingCenter.Subscribe <Model.BluetoothHandler>(this, "BHNoDeviceSelected", (sender) =>
            {
                DisplayAlert("NO DEVICE IS SELECTED", "Select a device and try again", "OK");
            });

            MessagingCenter.Subscribe <Model.BluetoothHandler>(this, "BHConnectToDeviceFail", (sender) =>
            {
                DisplayAlert("CONNECTION FAIL", "Can't connect to device", "OK");
            });

            if (measurementunit == "1")
            {
                journey = _database.GetJourneys();
                foreach (var item in journey)
                {
                    item.Distance = item.Distance * 0.621371;
                    item.Unit     = "mi";
                }
            }
            else
            {
                journey = _database.GetJourneys();
                foreach (var item in journey)
                {
                    item.Unit = "km";
                }
            }

            JourneysListView.ItemsSource = journey;
        }