Inheritance: Xamarin.Forms.ContentView
        /// <summary>
        /// Method that creates the error stack
        /// The stacks visibility is binded to the viewmodel
        /// </summary>
        private StackLayout ErrorStack()
        {
            var text = new Label
            {
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.LoginLabelText,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center
            };
            text.SetBinding(Label.TextProperty, UploadingViewModel.ErrorTextProperty);

            var TryAgainButton = new ButtomButton("Prøv Igen", SendUploadMessage);
            var SaveButton = new ButtomButton("Gem", SendStoreMessage);
            TryAgainButton.Height = Definitions.GpsButtonHeight;
            SaveButton.Height = Definitions.GpsButtonHeight;

            var layout = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(50, 70, 50, 70),
                Spacing = 30,
                Children =
                {
                    text,
                    TryAgainButton,
                    SaveButton
                }
            };
            layout.SetBinding(StackLayout.IsVisibleProperty, UploadingViewModel.ErrorVisibilityProperty);

            return layout;
        }
        /// <summary>
        /// Method that creates a stacklayout of a popup with a yes/no before logging out
        /// </summary>
        /// <returns>Stacklayout of popup</returns>
        private StackLayout LogoutPopup()
        {
            var display = Resolver.Resolve<IDevice>().Display;
            var header = new Label
            {
                Text = "Log Ud",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center,
            };
            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    header,
                }
            };
            var text = new Label
            {
                Text = "Ved at logge ud slettes eventuelle gemte kørsler",
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.PopupTextSize,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center
            };
            var text2 = new Label
            {
                Text = "Vil du logge ud alligevel?",
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.PopupTextSize,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center
            };


            var noButton = new ButtomButton("Nej", ClosePopup);
            var noStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = Definitions.ButtonHeight,
                WidthRequest = _yesNoButtonWidth,
                Children = { noButton }
            };
            var yesButton = new ButtomButton("Ja", SendLogoutMessage);
            var yesStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = Definitions.ButtonHeight,
                WidthRequest = _yesNoButtonWidth,
                Children = { yesButton }
            };

            var ButtonStack = new StackLayout
            {
                BackgroundColor = Color.White, // for Android and WP
                Orientation = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.End,
                Padding = new Thickness(Definitions.Padding, 5, Definitions.Padding, Definitions.Padding),
                Spacing = Definitions.Padding,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children =
                {
                    noStack,
                    yesStack
                }
            };

            var PopUp = new StackLayout
            {
                WidthRequest = _popupWidth,
                HeightRequest = _popupHeight,
                BackgroundColor = Color.White,
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Spacing = 4,
                Children =
                {
                    headerstack,
                    text,
                    text2,
                    ButtonStack
                }
            };
            var topPadding = display.Height / 2 - 150;
            var PopUpBackground = new StackLayout
            {
                Padding = new Thickness(0, topPadding, 0, 0),
                WidthRequest = display.Width,
                HeightRequest = display.Height,
                BackgroundColor = Color.FromRgba(0, 0, 0, 0.85),
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                Children =
                {
                    PopUp
                }
            };

            return PopUpBackground;
        }
        /// <summary>
        /// Method that creates the page content
        /// </summary>
        /// <returns>View of the content to be displayed</returns>
        public View SetContent()
        {
            var header = new Label
            {
                Text = "Ny Kørsel",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
            };
            var vertButton = new VertsButton(SendViewStoredMessage, Definitions.storedReportsCount.ToString());
            var exitButton = new LogoutButton(ShowLogoutPopup);

            vertButton.WidthRequest = 100;
            vertButton.HeightRequest = 60;
            exitButton.WidthRequest = 100;
            exitButton.HeightRequest = 60;

            _header = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                HeightRequest = Definitions.HeaderHeight,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Padding = 5,
                Children =
                {
                    exitButton,
                    header,
                    vertButton,
                }
            };
            _header.SetBinding(StackLayout.BackgroundColorProperty, MainViewModel.PrimaryHexProperty);

            Definitions.DateToView = DateTime.Now.ToString("d/M/yyyy");
            Definitions.DateToApi = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
            var date = new Label
            {
                Text = Definitions.DateToView,
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                FontSize = Definitions.LoginLabelText,
                HeightRequest = 40,
            };

            List = new ListView
            {
                ItemTemplate = new DataTemplate(typeof(DriveReportCell)),
                SeparatorColor = Color.FromHex("#EE2D2D"),
                SeparatorVisibility = SeparatorVisibility.Default,
                VerticalOptions = LayoutOptions.StartAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };
            List.SetBinding(ListView.ItemsSourceProperty, MainViewModel.DriveProperty);
            
            List.ItemSelected += async (sender, e) =>
            {
                if (e.SelectedItem == null) return;
                var selectedItem = (DriveReportCellModel)e.SelectedItem;
                SendSelectedMessage();
            };

            var startButton = new ButtomButton("Start Kørsel", StartDrive);
            
            var buttomStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.End,
                Padding = Definitions.Padding,
                HeightRequest = Definitions.ButtonHeight,

                Children = {startButton}
            };
            
            var layout = new StackLayout
            {
                Spacing = 2,
                Children =
                {
                    _header,
                    date,
                    List,
                    CheckStack(),
                    buttomStack
                },
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
            };
            
            _popUpLayout = new PopupLayout();
            _popUpLayout.Content = layout;
            return _popUpLayout;
        }
        /// <summary>
        /// Method used to create the layout of the page
        /// </summary>
        private View SetContent()
        {

            var header = new Label
            {
                Text = "OS2Indberetning",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize - 8,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
            };

            var backButton = new BackButton(SendBackMessage);
            var filler = new Filler();

            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    backButton,
                    header,
                    filler
                }
            };
            var usernameLabel = new Label
            {
                Text = _usernamePlaceholder,
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
            };
            var username = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
            };
            username.SetBinding(Entry.TextProperty, CouplingViewModel.UsernameProperty);

            var pwLabel = new Label
            {
                Text = _pwPlaceholder,
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
            };
            var pw = new Entry
            {
                
                HorizontalOptions = LayoutOptions.FillAndExpand,
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                IsPassword = true,
            };
            pw.SetBinding(Entry.TextProperty, CouplingViewModel.PasswordProperty);

            pw.Completed += (sender, args) =>
            {
                SendCoupleMessage();
            };

            var informationText = new Label
            {
                Text = "Du skal oprette et password for at logge ind på app'en. \n\n" +
                       "Passwordet opretter du i OS2Indberetning under Personlige Indstillinger: Adgangskode til app.\n\n" +
                       "Her finder du også dit brugernavn, som er dine initialer.\n",
                       
                HorizontalOptions = LayoutOptions.Center,
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.InformationFontSize,
            };

            var version = new Label
            {
                Text = "version " + Definitions.VersionNumber,
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.EndAndExpand,
                YAlign = TextAlignment.Center,
            };

            var textFrame = new StackLayout
            {
                Padding = Definitions.Padding,
                VerticalOptions = LayoutOptions.StartAndExpand,
                Children =
                {
                    informationText
                }
            };

            var coupleButton = new ButtomButton("Log Ind", SendCoupleMessage);
           
            var buttomStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.Start,
                Padding = Definitions.Padding,
                Spacing = 2,
                HeightRequest = Definitions.ButtonHeight,

                Children = {  coupleButton }
            };

            var layout = new StackLayout
            {
                Children =
                {
                    headerstack,
                    usernameLabel,
                    username,
                    pwLabel,
                    pw,
                    buttomStack,
                    textFrame,
                    version
                },
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
            };

            return layout;
        }
        /// <summary>
        /// Method that creates a stacklayout of a popup with a specific message
        /// </summary>
        /// <param name="Message">string message of the text to be displayed in the popup</param>
        /// <returns>Stacklayout of popup</returns>
        private StackLayout CreatePopup(string Message)
        {
            var display = Resolver.Resolve<IDevice>().Display;
            var header = new Label
            {
                Text = "Fejl",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center,
            };
            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    header,
                }
            };
            var text = new Label
            {
                Text = Message,
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.PopupTextSize,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
            };


            var noButton = new ButtomButton("Ok", ClosePopup);
            var noStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = Definitions.ButtonHeight,
                WidthRequest = _yesNoButtonWidth,
                Children = { noButton }
            };

            var ButtonStack = new StackLayout
            {
                BackgroundColor = Color.White, // for Android and WP
                Orientation = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.End,
                Padding = new Thickness(Definitions.Padding, 0, Definitions.Padding, Definitions.Padding),
                Spacing = Definitions.Padding,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children =
                {
                    noStack,
                }
            };

            var PopUp = new StackLayout
            {
                WidthRequest = _popupWidth,
                HeightRequest = _popupHeight,
                BackgroundColor = Color.White,
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Children =
                {
                    headerstack,
                    text,
                    ButtonStack
                }
            };
            var topPadding = display.Height / 2 - 150;
            var PopUpBackground = new StackLayout
            {
                Padding = new Thickness(0, topPadding, 0, 0),
                WidthRequest = display.Width,
                HeightRequest = display.Height,
                BackgroundColor = Color.FromRgba(0, 0, 0, 0.85),
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                Children =
                {
                    PopUp
                }
            };

            return PopUpBackground;
        }
        /// <summary>
        /// Method that creates the page content
        /// </summary>
        public View SetContent()
        {
            var signalStatus = new Label
            {

                TextColor = Color.Red,
                FontSize = Definitions.AccuracyTextSize,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
                Text = "Intet GPS signal",
            };
            signalStatus.SetBinding(Label.IsVisibleProperty, GpsViewModel.SignalProperty);

            var signalStack = new StackLayout
            {
                HeightRequest = 45,
                Children = { signalStatus}
            };
            var gpsStatus = new Label
            {

                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.AccuracyTextSize,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
            };
            gpsStatus.SetBinding(Label.TextProperty, GpsViewModel.AccuracyProperty);

            var gpsDriven = new Label
            {
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.DrivenTextSize,
                FontAttributes = FontAttributes.Bold,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center,
                WidthRequest = _popupWidth - 80
            };
            gpsDriven.SetBinding(Label.TextProperty, GpsViewModel.DrivenProperty);

            var gpsUpdate = new Label
            {
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.LastupdateTextSize,
                FontAttributes = FontAttributes.Italic,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
            };
            gpsUpdate.SetBinding(Label.TextProperty, GpsViewModel.LastUpdateProperty);

            var gpsTextStack = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
                VerticalOptions = LayoutOptions.Center,
                Padding = new Thickness(0, 80, 0, 100),
                Children =
                {
                    signalStack,
                    gpsStatus,
                    gpsDriven,
                    gpsUpdate,
                }
            };

            _pauseButton = new ToggleButton(_startDrive, _pauseDrive, _driveAgain, SendToggleMessage);
            var finishButton = new ButtomButton("Afslut Kørsel", OpenPopup);
            _pauseButton.Height = Definitions.GpsButtonHeight;
            finishButton.Height = Definitions.GpsButtonHeight;

            var buttomStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center,
                Padding = new Thickness(50, 0, 50, 0),
                Spacing = 30,
                Children = { _pauseButton, finishButton }
            };

            var gpsStack = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(10, 50, 10, 50),
                Children =
                {
                    gpsTextStack,
                    buttomStack
                }
            };

            _popUpLayout = new PopupLayout();
            _popUpLayout.Content = gpsStack;
            return _popUpLayout;
        }
        /// <summary>
        /// Method that creates the stacklayout for the popup
        /// </summary>
        /// <param name="message">Text to be displayed in the popup</param>
        /// <returns>Stacklayout of the popup</returns>
        private StackLayout CreatePopup(string message)
        {
            var display = Resolver.Resolve<IDevice>().Display;
            var header = new Label
            {
                Text = "Send Rapport",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center,
            };
            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    header,
                }
            };
            var text = new Label
            {
                Text = message,
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.PopupTextSize,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center,
            };

            var sendButton = new ButtomButton("Send", SendUploadMessage);
            var cancelButton = new ButtomButton("Fortryd", ClosePopup);
            var removeButton = new ButtomButton("Slet", SendRemoveMessage);
            sendButton.WidthRequest = _yesNoButtonWidth;
            cancelButton.WidthRequest = _yesNoButtonWidth;
            removeButton.WidthRequest = _yesNoButtonWidth;
            var noStack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = Definitions.ButtonHeight,
                Spacing = Definitions.Padding,
                Padding = new Thickness(Definitions.Padding, 0, Definitions.Padding, Definitions.Padding),
                Children = { cancelButton, sendButton, removeButton}
            };

            var PopUp = new StackLayout
            {
                WidthRequest = _popupWidth,
                BackgroundColor = Color.White,
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Spacing = Definitions.Padding,
                Children =
                {
                    headerstack,
                    text,
                    noStack
                }
            };
            var topPadding = display.Height / 2 - 150;
            var PopUpBackground = new StackLayout
            {
                Padding = new Thickness(0, topPadding, 0, 0),
                WidthRequest = display.Width,
                HeightRequest = display.Height,
                BackgroundColor = Color.FromRgba(0, 0, 0, 0.85),
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                Children =
                {
                    PopUp
                }
            };

            return PopUpBackground;
        }
        /// <summary>
        /// Method that creates and opens a popup for noGpsTimeout error
        /// </summary>
        /// <returns>Stacklayout of the popup</returns>
        private StackLayout NoGpsTimeoutPopUp()
        {
            var display = Resolver.Resolve<IDevice>().Display;
            var header = new Label
            {
                Text = "Fejl",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center,
            };
            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    header,
                }
            };
            var textline1 = new Label
            {
                Text = "Der har ikke været gps signal i minimum " + Definitions.NoGpsSignalTimer + " sammenhængende sekunder under kørslen.",
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.PopupTextSize,
                HorizontalOptions = LayoutOptions.Center,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center
            };
            var textline2 = new Label
            {
                Text = "Vær opmærksom på mulige fejl i ruten.",
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.PopupTextSize,
                HorizontalOptions = LayoutOptions.Center,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center
            };
            var textstack = new StackLayout
            {
                Padding = new Thickness(Definitions.Padding, 0, Definitions.Padding, 0),
                Children = { textline1, textline2 }
            };

            var yesButton = new ButtomButton("Ok", SendFinishMessage);
            var yesStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.End,
                HeightRequest = Definitions.ButtonHeight,
                WidthRequest = _yesNoButtonWidth,
                Children = { yesButton }
            };

            var ButtonStack = new StackLayout
            {
                BackgroundColor = Color.White, // for Android and WP
                Orientation = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.End,
                Padding = new Thickness(Definitions.Padding, 0, Definitions.Padding, Definitions.Padding),
                Spacing = Definitions.Padding,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children =
                {
                    yesStack
                }
            };

            var PopUp = new StackLayout
            {
                WidthRequest = _popupWidth,
                //HeightRequest = popupHeight,
                BackgroundColor = Color.White,
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Spacing = Definitions.Padding,
                Children =
                {
                    headerstack,
                    textstack,
                    ButtonStack
                }
            };
            var topPadding = display.Height / 2 - 150;
            var PopUpBackground = new StackLayout
            {
                Padding = new Thickness(0, topPadding, 0, 0),
                WidthRequest = display.Width,
                HeightRequest = display.Height,
                BackgroundColor = Color.FromRgba(0, 0, 0, 0.85),
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                Children =
                {
                    PopUp
                }
            };

            return PopUpBackground;
        }
        /// <summary>
        /// Method that creates and opens a popup for pause error
        /// </summary>
        /// <returns>Stacklayout of the popup</returns>
        private StackLayout PauseSpaceTooBigPopUp()
        {
            var display = Resolver.Resolve<IDevice>().Display;
            var header = new Label
            {
                Text = "Fejl",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center,
            };
            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    header,
                }
            };
            var text = new Label
            {
                Text = "Du har bevæget dig for langt væk fra punktet hvor du trykkede på pause." +
                       " Afslut eller bevæg dig inden for 200m af punktet hvor du trykkede på pause.",
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.PopupTextSize,
                HorizontalOptions = LayoutOptions.Center,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center
            };
            

            var noButton = new ButtomButton("Annuller", ClosePopup);
            var noStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.Start,
                HeightRequest = Definitions.ButtonHeight,
                WidthRequest = _yesNoButtonWidth,
                Children = { noButton }
            };
            var yesButton = new ButtomButton("Afslut", SendFinishMessage);
            var yesStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.End,
                HeightRequest = Definitions.ButtonHeight,
                WidthRequest = _yesNoButtonWidth,
                Children = { yesButton }
            };

            var ButtonStack = new StackLayout
            {
                BackgroundColor = Color.White, // for Android and WP
                Orientation = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.End,
                Padding = new Thickness(Definitions.Padding, 0, Definitions.Padding, Definitions.Padding),
                Spacing = Definitions.Padding,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children =
                {
                    noStack,
                    yesStack
                }
            };

            var PopUp = new StackLayout
            {
                WidthRequest = _popupWidth,
                //HeightRequest = popupHeight,
                BackgroundColor = Color.White,
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Spacing = Definitions.Padding,
                Children =
                {
                    headerstack,
                    text,
                    ButtonStack
                }
            };
            var topPadding = display.Height / 2 - 150;
            var PopUpBackground = new StackLayout
            {
                Padding = new Thickness(0, topPadding, 0, 0),
                WidthRequest = display.Width,
                HeightRequest = display.Height,
                BackgroundColor = Color.FromRgba(0, 0, 0, 0.85),
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                Children =
                {
                    PopUp
                }
            };

            return PopUpBackground;
        }
        /// <summary>
        /// Method that creates the stacklayout for the popup
        /// </summary>
        /// <returns>Stacklayout of the popup</returns>
        private StackLayout CreatePopup()
        {
            var display = Resolver.Resolve<IDevice>().Display;
            var header = new Label
            {
                Text = "Afslut Kørsel?",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center,
            };
            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    header,
                }
            };
            var text = new Label
            {
                Text = "Er du sikker på at du vil afslutte kørslen?",
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.PopupTextSize,
                HorizontalOptions = LayoutOptions.Center,
                YAlign = TextAlignment.Center,
            };

            var checkboxtext = new Label
            {
                Text = "Kørsel slutter hjemme",
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.PopupTextSize,
                HorizontalOptions = LayoutOptions.Center,
                YAlign = TextAlignment.Center,
            };

            SendFirstFinishedHomeMessage();
            var checkbox = new CheckboxButton(SendFinishedHomeMessage);

            var checkStack = new StackLayout
            {
                BackgroundColor = Color.White, // for Android and WP
                Orientation = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Spacing = 20,
                Children =
                {
                    checkboxtext,
                    checkbox
                }
            };

            var noButton = new ButtomButton("Nej", ClosePopup);
            var noStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.Start,
                HeightRequest = Definitions.ButtonHeight,
                WidthRequest = _yesNoButtonWidth,
                Children = { noButton }
            };
            var yesButton = new ButtomButton("Ja", SendFinishMessage);
            var yesStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.End,
                HeightRequest = Definitions.ButtonHeight,
                WidthRequest = _yesNoButtonWidth,
                Children = { yesButton }
            };

            var ButtonStack = new StackLayout
            {
                BackgroundColor = Color.White, // for Android and WP
                Orientation = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.End,
                Padding = new Thickness(Definitions.Padding, 0, Definitions.Padding, Definitions.Padding),
                Spacing = Definitions.Padding,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children =
                {
                    noStack,
                    yesStack
                }
            };
            
            var PopUp = new StackLayout
            {
                WidthRequest = _popupWidth,
                //HeightRequest = popupHeight,
                BackgroundColor = Color.White,
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Spacing = Definitions.Padding,
                Children =
                {
                    headerstack,
                    text,
                    checkStack,
                    ButtonStack
                }
            };
            var topPadding = display.Height / 2 - 150;
            var PopUpBackground = new StackLayout
            {
                Padding = new Thickness(0, topPadding, 0, 0),
                WidthRequest = display.Width,
                HeightRequest = display.Height,
                BackgroundColor = Color.FromRgba(0, 0, 0, 0.85),
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                Children =
                {
                    PopUp
                }
            };

            return PopUpBackground;
        }
        /// <summary>
        /// Method that creates the view content
        /// </summary>
        /// <returns>the view to be displayed</returns>
        public View SetContent()
        {
            // View Title
            var header = new Label
            {
                Text = "Afslut Kørsel",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
            };

            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HeightRequest = Definitions.HeaderHeight,
                Padding = 5,
                Children =
                {
                    header,
                }
            };

            // Date View
            var date = new Label
            {
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                FontSize = Definitions.LoginLabelText,
                HeightRequest = 35,
            };
            date.SetBinding(Label.TextProperty, FinishDriveViewModel.DateProperty);
            var user = new Label
            {
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                FontSize = Definitions.LoginLabelText,
                HeightRequest = 35,
            };
            user.SetBinding(Label.TextProperty, FinishDriveViewModel.UsernameProperty);

            // Purpose View
            var purpose = new DriveFinishedCommonCell(SendPurposeMessage);
            purpose.Title = PurposeText;
            purpose.SetBinding(DriveFinishedCommonCell.DetailsProperty, FinishDriveViewModel.PurposeProperty);

            // Organization View
            var organization = new DriveFinishedCommonCell(SendOrganizationMessage);
            organization.Title = OrganizationText;
            organization.SetBinding(DriveFinishedCommonCell.DetailsProperty, FinishDriveViewModel.OrganizationProperty);

            // Rate View
            var rate = new DriveFinishedCommonCell(SendRateMessage);
            rate.Title = RateText;
            rate.SetBinding(DriveFinishedCommonCell.DetailsProperty, FinishDriveViewModel.RateProperty);

            // Remark View
            var remark = new DriveFinishedCommonCell(SendRemarkMessage);
            remark.Title = RemarkText;
            remark.SetBinding(DriveFinishedCommonCell.DetailsProperty, FinishDriveViewModel.RemarkProperty);

            // Total Km View
            var totalKm = new DriveFinishedCommonCell(SendSelectNewKmMessage);
            totalKm.Title = NewKmText;
            totalKm.SetBinding(DriveFinishedCommonCell.DetailsProperty, FinishDriveViewModel.NewKmProperty);

            // Home to Border Distance View 
            /*
            var homeToBorderDistance = new DriveFinishedCommonCell(SendSelectHomeToBorderDistanceMessage);
            homeToBorderDistance.Title = HomeToBorderDistanceText;
            homeToBorderDistance.SetBinding(DriveFinishedCommonCell.DetailsProperty, FinishDriveViewModel.HomeToBorderDistanceProperty);
            homeToBorderDistance.SetBinding(DriveFinishedCommonCell.IsVisibleProperty, FinishDriveViewModel.FourKmRuleCheckProperty);
            */

            // Cancel and send buttons
            var startButton = new ButtomButton("Indsend Kørsel", SendUploadMessage);
            var cancelButton = new ButtomButton("Annuller og Slet", OpenPopup);
            startButton.FontSize = 24;
            cancelButton.FontSize = 24;
            var width = Resolver.Resolve<IDevice>().Display.Width;
            startButton.Width = width / 2;
            cancelButton.Width = width / 2;

            var buttomStack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.End,
                Padding = Definitions.Padding,
                Spacing = Definitions.Padding,
                HeightRequest = Definitions.ButtonHeight + 20,
                HorizontalOptions = LayoutOptions.Fill,
                Children = { cancelButton, startButton }
            };

            // Header View Container
            var headerLayout = new StackLayout
            {
                Spacing = 2,
                Children =
                {
                    headerstack,
                    date,
                    user
                },
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor)
            };

            // Content View Container
            var contentLayout = new StackLayout
            {
                Spacing = 2,
                Children =
                    {
                        purpose,
                        organization,
                        rate,
                        remark,
                        totalKm,
                        StartCheck(),
                        EndCheck(),
                        //FourKmRuleCheck(),
                        //homeToBorderDistance,
                        buttomStack
                    },
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
            };
        
            // Add content view to a scrollview
            var scrollView = new ScrollView
            {
                Content = contentLayout,
            };

            // Add Header and Content View Containers to a container
            var layout = new StackLayout
            {
                Spacing = 2,
                Children =
                {
                    headerLayout,
                    scrollView
                },
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor)
            };

            // Add layout to a PopUpLayout
            PopUpLayout = new PopupLayout();
            PopUpLayout.Content = layout;
            
            return PopUpLayout;
        }
        /// <summary>
        /// Creates a view for the HomeToBorderDistance popup
        /// </summary>
        /// <returns>Stacklayout of the popup content</returns>
        public StackLayout HomeToBorderDistancePopup()
        {
            var display = Resolver.Resolve<IDevice>().Display;
            var header = new Label
            {
                Text = HomeToBorderDistanceText,
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center,
            };
            

            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    header,
                }
            };
            var text = new Label
            {
                Text = "Rediger i antal kørte km: ",
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                FontSize = Definitions.PopupTextSize,
                HorizontalOptions = LayoutOptions.Center,
                YAlign = TextAlignment.Center,
            };

            var entry = new Entry
            {
                TextColor = Color.FromHex(Definitions.DefaultTextColor),
                Keyboard = Keyboard.Numeric,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            entry.SetBinding(Entry.TextProperty, FinishDriveViewModel.HomeToBorderDistanceProperty);
            entry.Focus();

            var noButton = new ButtomButton("Fortryd", () => PopUpLayout.DismissPopup());
            var noStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.Start,
                HeightRequest = Definitions.ButtonHeight,
                WidthRequest = _yesNoButtonWidth,
                Children = { noButton }
            };
            var yesButton = new ButtomButton("Gem", SendHomeToBorderDistanceMessage);
            var yesStack = new StackLayout
            {
                VerticalOptions = LayoutOptions.End,
                HorizontalOptions = LayoutOptions.End,
                HeightRequest = Definitions.ButtonHeight,
                WidthRequest = _yesNoButtonWidth,
                Children = { yesButton }
            };

            var ButtonStack = new StackLayout
            {
                BackgroundColor = Color.White, // for Android and WP
                Orientation = StackOrientation.Horizontal,
                VerticalOptions = LayoutOptions.End,
                Padding = new Thickness(Definitions.Padding, 0, Definitions.Padding, Definitions.Padding),
                Spacing = Definitions.Padding,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children =
                {
                    noStack,
                    yesStack
                }
            };

            var PopUp = new StackLayout
            {
                WidthRequest = _popupWidth,

                BackgroundColor = Color.White,
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Spacing = Definitions.Padding,
                Children =
                {
                    headerstack,
                    text,
                    entry,
                    ButtonStack
                }
            };
            var topPadding = display.Height / 2 - 150;
            var PopUpBackground = new StackLayout
            {
                Padding = new Thickness(0, topPadding, 0, 0),
                WidthRequest = display.Width,
                HeightRequest = display.Height,
                BackgroundColor = Color.FromRgba(0, 0, 0, 0.85),
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.Center,
                Children =
                {
                    PopUp
                }
            };

            return PopUpBackground;
        }