Beispiel #1
0
        /////////////////////////////////////////////////
        /// Light state for MorningSun to be displayed
        /// in app showing if MorningSun is turned on
        /// or off
        /////////////////////////////////////////////////
        private void LightState()
        {
            string obj = HTTPRequestHandler.CreateGetRequest(LightUri + "newest/").ToString();

            var lightObject = JsonConvert.DeserializeObject <LightObject>(obj);

            if (lightObject.IsOn == true)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    lightStateLabel.Text = "Light is ON";
                });
            }
            else if (lightObject.IsOn == false)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    lightStateLabel.Text = "Light is OFF";
                });
            }
            else
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    lightStateLabel.Text = "Something went much wrong";
                });
            }
        }
Beispiel #2
0
        /////////////////////////////////////////////////
        /// Loads current wake up and sleep time to be
        /// displayed in app
        /////////////////////////////////////////////////
        private void GetWakeUpAndSleepTimes()
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                string obj       = HTTPRequestHandler.CreateGetRequest(PoombaUri + "newest/").ToString();
                var poombaObject = JsonConvert.DeserializeObject <PoombaObject>(obj);

                hhWakeUpEditor.Text = poombaObject.WakeUpTime.Hour.ToString();
                mmWakeUpEditor.Text = poombaObject.WakeUpTime.Minute.ToString();
                hhSleepEditor.Text  = poombaObject.SleepTime.Hour.ToString();
                mmSleepEditor.Text  = poombaObject.SleepTime.Minute.ToString();
            });
        }
Beispiel #3
0
        /////////////////////////////////////////////////
        /// Loads mail status to be displayed in app.
        /// If mail is recieved after Snapbox has been
        /// emptied make nofitication
        /////////////////////////////////////////////////
        private void MailStatus()
        {
            string obj = HTTPRequestHandler.CreateGetRequest(SnapboxUri + "newest/").ToString();

            var snapboxObject = JsonConvert.DeserializeObject <SnapboxObject>(obj);

            Device.BeginInvokeOnMainThread(() =>
            {
                if (snapboxObject.MailReceived == true)
                {
                    mailStatusLbl.Text = "You got mail";
                }
                if (snapboxObject.MailReceived == false)
                {
                    _notificationSent  = false;
                    mailStatusLbl.Text = "Your snapbox is empty";
                }
            });

            if (snapboxObject.MailReceived == true && _notificationSent == false)
            {
                // Make nofitication if mail is received
                _notificationSent = true;

                var toastclass = new ToastClass();

                toastclass.ShowToast(new NotificationOptions()
                {
                    Title          = "You got mail!",
                    Description    = "Go to your snapbox to pick your snailmail",
                    IsClickable    = true,
                    WindowsOptions = new WindowsOptions()
                    {
                        LogoUri = "icon.png"
                    },
                    ClearFromHistory             = false,
                    AllowTapInNotificationCenter = false,
                    AndroidOptions = new AndroidOptions()
                    {
                        HexColor = "#F99D1C",
                        ForceOpenAppOnNotificationTap = true
                    }
                });
            }
        }
Beispiel #4
0
        private void DoorStatus()
        {
            string obj = HTTPRequestHandler.CreateGetRequest(HodoorUri + "newest/").ToString();

            var hodoorObject = JsonConvert.DeserializeObject <HodoorObject>(obj);

            Device.BeginInvokeOnMainThread(() =>
            {
                if (hodoorObject.OpenStatus == false)
                {
                    doorStatus.Text = "Locked";
                }

                if (hodoorObject.OpenStatus == true)
                {
                    doorStatus.Text = "Unlocked";
                }
            });
        }
Beispiel #5
0
        private void LockBtn_Clicked(object sender, EventArgs e)
        {
            string obj = HTTPRequestHandler.CreateGetRequest(HodoorUri + "newest/").ToString();
            var    hodoorStateObject = JsonConvert.DeserializeObject <HodoorObject>(obj);

            if (hodoorStateObject.OpenStatus == false)
            {
                DisplayAlert("Well tried", "Hodoor is already closed!", "OK");
            }
            else
            {
                LockBtn.IsEnabled = false;
                HodoorObject hodoorObject = new HodoorObject()
                {
                    Command = "CmdLock",
                    IsRun   = false,
                };
                HTTPRequestHandler.CreateRequest(hodoorObject, HodoorUri);
                LockBtn.IsEnabled = true;
            }
        }
Beispiel #6
0
        /////////////////////////////////////////////////
        /// Loads current battery powerlevel to be
        /// displayed in app. If powerlevel reach 20%
        /// or lower make nofitication
        /////////////////////////////////////////////////
        private void BatteryStatus()
        {
            string obj = HTTPRequestHandler.CreateGetRequest(SnapboxUri + "newest/").ToString();

            var snapboxObject = JsonConvert.DeserializeObject <SnapboxObject>(obj);

            Device.BeginInvokeOnMainThread(() =>
            {
                powerlevel.Text = snapboxObject.PowerLevel + "%";

                if (int.Parse(snapboxObject.PowerLevel) <= 20 && _powerNotificationSent == false)
                {
                    _powerNotificationSent = true;
                    // Make nofitication if powerlevel is less than 20%
                    var toastclass = new ToastClass();

                    toastclass.ShowToast(new NotificationOptions()
                    {
                        Title          = "Low battery",
                        Description    = "Your snapbox powerlevel has reached 20% or lower!",
                        IsClickable    = true,
                        WindowsOptions = new WindowsOptions()
                        {
                            LogoUri = "icon.png"
                        },
                        ClearFromHistory             = false,
                        AllowTapInNotificationCenter = false,
                        AndroidOptions = new AndroidOptions()
                        {
                            HexColor = "#F99D1C",
                            ForceOpenAppOnNotificationTap = true
                        }
                    });
                }
                else if (int.Parse(snapboxObject.PowerLevel) > 20)
                {
                    _powerNotificationSent = false;
                }
            });
        }
Beispiel #7
0
        /////////////////////////////////////////////////
        /// Button event handler that turnes on
        /// MorningSun
        /////////////////////////////////////////////////
        private void OnButton_Clicked(object sender, EventArgs e)
        {
            string obj = HTTPRequestHandler.CreateGetRequest(LightUri + "newest/").ToString();
            var    lightStateObject = JsonConvert.DeserializeObject <LightObject>(obj);

            if (lightStateObject.IsOn == true)
            {
                DisplayAlert("Well tried", "Light is already turned on!", "OK");
            }
            else
            {
                OnButton.IsEnabled = false;
                LightObject lightObject = new LightObject()
                {
                    Command = "on",
                    IsRun   = false,
                    IsOn    = true
                };
                HTTPRequestHandler.CreateRequest(lightObject, LightUri);
                OnButton.IsEnabled = true;
            }
        }
Beispiel #8
0
        /////////////////////////////////////////////////
        /// Button event handler that turnes off
        /// Poomba
        /////////////////////////////////////////////////
        private void OffButton_Clicked(object sender, EventArgs e)
        {
            string obj = HTTPRequestHandler.CreateGetRequest(PoombaUri + "newest/").ToString();
            var    poombaStateObject = JsonConvert.DeserializeObject <PoombaObject>(obj);

            if (poombaStateObject.IsOn == false)
            {
                DisplayAlert("Well tried", "Poomba is already turned off!", "OK");
            }
            else
            {
                OffButton.IsEnabled = false;

                PoombaObject poombaObject = new PoombaObject()
                {
                    Command = "off",
                    IsRun   = false,
                    IsOn    = false
                };
                HTTPRequestHandler.CreateRequest(poombaObject, PoombaUri);
                OffButton.IsEnabled = true;
            }
        }
        /////////////////////////////////////////////////
        /// Make plot for statistics displaying 8
        /// coloums, 7 for recent days and 1 for total
        /////////////////////////////////////////////////
        public void MakePlot()
        {
            // Last seven days in specific format. Is to be used in labels in chart.
            DateTime[] last7Days = Enumerable.Range(0, 7).Select(i => DateTime.Now.Date.AddDays(-i)).ToArray();
            string     day1      = last7Days[6].ToString("yyyy-MM-dd");
            string     day2      = last7Days[5].ToString("yyyy-MM-dd");
            string     day3      = last7Days[4].ToString("yyyy-MM-dd");
            string     day4      = last7Days[3].ToString("yyyy-MM-dd");
            string     day5      = last7Days[2].ToString("yyyy-MM-dd");
            string     day6      = last7Days[1].ToString("yyyy-MM-dd");
            string     day7      = last7Days[0].ToString("yyyy-MM-dd");

            // Get objects from recent seven days
            string obj = HTTPRequestHandler.CreateGetRequest("http://fwps.azurewebsites.net/api/snapbox/getupdate").ToString();

            var snapboxObject = JsonConvert.DeserializeObject <List <SnapboxPage.SnapboxObject> >(obj);

            int day1Count = snapboxObject.Count(spo => spo.CreatedDate.Date == last7Days[6].Date && spo.MailReceived == false);
            int day2Count = snapboxObject.Count(spo => spo.CreatedDate.Date == last7Days[5].Date && spo.MailReceived == false);
            int day3Count = snapboxObject.Count(spo => spo.CreatedDate.Date == last7Days[4].Date && spo.MailReceived == false);
            int day4Count = snapboxObject.Count(spo => spo.CreatedDate.Date == last7Days[3].Date && spo.MailReceived == false);
            int day5Count = snapboxObject.Count(spo => spo.CreatedDate.Date == last7Days[2].Date && spo.MailReceived == false);
            int day6Count = snapboxObject.Count(spo => spo.CreatedDate.Date == last7Days[1].Date && spo.MailReceived == false);
            int day7Count = snapboxObject.Count(spo => spo.CreatedDate.Date == last7Days[0].Date && spo.MailReceived == false);

            int total = day1Count + day2Count + day3Count + day4Count + day5Count + day6Count + day7Count;

            var entries = new[]
            {
                new Entry(day1Count)
                {
                    Label      = day1,
                    ValueLabel = day1Count.ToString(),
                    Color      = SKColor.Parse("#b455b6")
                },
                new Entry(day2Count)
                {
                    Label      = day2,
                    ValueLabel = day2Count.ToString(),
                    Color      = SKColor.Parse("#b455b6")
                },
                new Entry(day3Count)
                {
                    Label      = day3,
                    ValueLabel = day3Count.ToString(),
                    Color      = SKColor.Parse("#b455b6")
                },
                new Entry(day4Count)
                {
                    Label      = day4,
                    ValueLabel = day4Count.ToString(),
                    Color      = SKColor.Parse("#b455b6")
                },
                new Entry(day5Count)
                {
                    Label      = day5,
                    ValueLabel = day5Count.ToString(),
                    Color      = SKColor.Parse("#b455b6")
                },
                new Entry(day6Count)
                {
                    Label      = day6,
                    ValueLabel = day6Count.ToString(),
                    Color      = SKColor.Parse("#b455b6")
                },
                new Entry(day7Count)
                {
                    Label      = day7,
                    ValueLabel = day7Count.ToString(),
                    Color      = SKColor.Parse("#b455b6")
                },
                new Entry(total)
                {
                    Label      = "Total",
                    ValueLabel = total.ToString(),
                    Color      = SKColor.Parse("#3498db")
                }
            };


            var chart = new BarChart()
            {
                Entries = entries
            };

            chartView.Chart = chart;
        }
Beispiel #10
0
        /////////////////////////////////////////////////
        /// Button event handler that handles if user
        /// sets and apply wake up and sleep time
        /////////////////////////////////////////////////
        private void WakeUpAndSleepApplyBtn_Clicked(object sender, EventArgs e)
        {
            WakeUpAndSleepApplyBtn.IsEnabled = false;
            // The four editor fiels has to hold integer values
            if (!int.TryParse((hhWakeUpEditor.Text), out int something))
            {
                DisplayAlert("Wrong input", "Field(s) either empty or wrong input type. Please try again", "OK");
                hhWakeUpEditor.Text = "";
                WakeUpAndSleepApplyBtn.IsEnabled = true;
                return;
            }

            if (!int.TryParse((mmWakeUpEditor.Text), out int something2))
            {
                DisplayAlert("Wrong input", "Field(s) either empty or wrong input type. Please try again", "OK");
                mmWakeUpEditor.Text = "";
                WakeUpAndSleepApplyBtn.IsEnabled = true;
                return;
            }

            if (!int.TryParse((hhSleepEditor.Text), out int something3))
            {
                DisplayAlert("Wrong input", "Field(s) either empty or wrong input type. Please try again", "OK");
                hhSleepEditor.Text = "";
                WakeUpAndSleepApplyBtn.IsEnabled = true;
                return;
            }

            if (!int.TryParse((mmSleepEditor.Text), out int something4))
            {
                DisplayAlert("Wrong input", "Field(s) either empty or wrong input type. Please try again", "OK");
                mmSleepEditor.Text = "";
                WakeUpAndSleepApplyBtn.IsEnabled = true;
                return;
            }


            var hhWakeUpInput = Double.Parse(hhWakeUpEditor.Text);
            var mmWakeUpInput = Double.Parse(mmWakeUpEditor.Text);
            var hhSleepInput  = Double.Parse(hhSleepEditor.Text);
            var mmSleepInput  = Double.Parse(mmSleepEditor.Text);

            // Check if inputs are within ranges
            if (hhWakeUpInput < 0 || hhWakeUpInput > 23)
            {
                DisplayAlert("Wrong input", "Input(s) out of range. Please try again", "OK");
                hhWakeUpEditor.Text = "";
                WakeUpAndSleepApplyBtn.IsEnabled = true;
                return;
            }

            if (mmWakeUpInput < 0 || mmWakeUpInput > 59)
            {
                DisplayAlert("Wrong input", "Input(s) out of range. Please try again", "OK");
                mmWakeUpEditor.Text = "";
                WakeUpAndSleepApplyBtn.IsEnabled = true;
                return;
            }

            if (hhSleepInput < 0 || hhSleepInput > 23)
            {
                DisplayAlert("Wrong input", "Input(s) out of range. Please try again", "OK");
                hhSleepEditor.Text = "";
                WakeUpAndSleepApplyBtn.IsEnabled = true;
                return;
            }

            if (mmSleepInput < 0 || mmSleepInput > 59)
            {
                DisplayAlert("Wrong input", "Input(s) out of range. Please try again", "OK");
                mmSleepEditor.Text = "";
                WakeUpAndSleepApplyBtn.IsEnabled = true;
                return;
            }


            DateTime WakeUpParsedDate = new DateTime();

            WakeUpParsedDate = DateTime.Today;
            WakeUpParsedDate = WakeUpParsedDate.AddHours(hhWakeUpInput);
            WakeUpParsedDate = WakeUpParsedDate.AddMinutes(mmWakeUpInput);

            DateTime SleepParsedDate = new DateTime();

            SleepParsedDate = DateTime.Today;
            SleepParsedDate = SleepParsedDate.AddHours(hhSleepInput);
            SleepParsedDate = SleepParsedDate.AddMinutes(mmSleepInput);


            string obj = HTTPRequestHandler.CreateGetRequest(LightUri + "newest/").ToString();

            var lightObject = JsonConvert.DeserializeObject <LightObject>(obj);

            LightObject lightWakeUpObject = new LightObject()
            {
                IsOn       = lightObject.IsOn,
                Command    = "UpdateTime",
                WakeUpTime = WakeUpParsedDate,
                SleepTime  = SleepParsedDate
            };

            HTTPRequestHandler.CreateRequest(lightWakeUpObject, LightUri);
            WakeUpAndSleepApplyBtn.IsEnabled = true;
        }