Exemple #1
0
 public HybridWebPageRenderer(HybridWebViewModel viewModel, object razorPageInstanceOrUrl)
 {
     hyrbidPage   = new HybridWebPageView(viewModel, razorPageInstanceOrUrl);
     this.Content = hyrbidPage;
 }
Exemple #2
0
        public HybridWebPageView(HybridWebViewModel viewModel, object razorPageInstanceOrUrl)
        {
            if (razorPageInstanceOrUrl == null)
            {
                throw new ArgumentNullException("razorPageInstance", "An instance of a Razor Page is needed");
            }

            var appSettings        = Resolver.Resolve <IAppSettings> ();
            var content            = string.Empty;
            var isWebPortalRequest = false;
            var loader             = Resolver.Resolve <IProgressDialog> ();

            loader.Title = "Loading Page...";
            loader.Show();
            try
            {
                var pageType = razorPageInstanceOrUrl.GetType();
                if (pageType != typeof(System.String))
                {
                    pageType.GetRuntimeProperty("Model").SetValue(razorPageInstanceOrUrl, viewModel);
                    MethodInfo info = pageType.GetRuntimeMethod("GenerateString", new Type[] { });
                    content = (string)info.Invoke(razorPageInstanceOrUrl, null);
                }
                else
                {
                    content            = razorPageInstanceOrUrl.ToString();
                    isWebPortalRequest = true;
                }
            } catch
            {
                ViewHasErrors = true;
                loader.Hide();
                return;
            }
            var stack = new StackLayout {
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };
            var hwv = new HybridWebView {
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            hwv.LoadFinished += (object sender, EventArgs e) =>
            {
                loader.Hide();
            };

            if (viewModel.NativeCallbacks.Count > 0)
            {
                foreach (KeyValuePair <string, Action <string> > pair in viewModel.NativeCallbacks)
                {
                    hwv.RegisterCallback(pair.Key, t => Device.BeginInvokeOnMainThread(() =>
                    {
                        pair.Value(t);
                    }));
                }
            }

            if (viewModel.ShowHeader)
            {
                var header = new FormHeaderBar();
                header.Text                = viewModel.Title;
                header.HasCloseButton      = true;
                header.CloseButtonClicked += async(object sender, EventArgs e) =>
                {
                    await Navigation.PopModalAsync();
                };
                stack.Children.Add(header);
            }
            stack.Children.Add(hwv);
            this.Content = stack;


            if (!isWebPortalRequest)
            {
                hwv.Source = new HtmlWebViewSource()
                {
                    Html = content
                };
            }
            else
            {
                var uri    = new Uri(string.Format("{0}{1}", appSettings.WebPortalHost, content));
                var qsColl = HttpUtility.ParseQueryString(uri.Query);
                qsColl.Add("mobilerequest_auth_token", App.MobileSession.AuthToken);
                var qs      = HttpUtility.GenerateQueryString(qsColl);
                var request = new UriBuilder(uri.Scheme, uri.Host, uri.Port, uri.AbsolutePath, qs).Uri;

                                #if DEBUG
                Debug.WriteLine("Hybrid Request Uri:" + request.ToString());
                                #endif
                hwv.Uri = request;
            }
        }
Exemple #3
0
        private void CreateSettings()
        {
            ListView settingsView = new ListView();

            if (Device.OS == TargetPlatform.iOS)
            {
                settingsView.RowHeight     = 45;
                settingsView.HeightRequest = 90;
            }
            else
            {
                settingsView.RowHeight     = 60;
                settingsView.HeightRequest = 120;
            }

            settingsView.VerticalOptions = LayoutOptions.Start;
            var collection = new List <SettingsListItemViewModel> ();

            collection.Add(new SettingsListItemViewModel()
            {
                HeaderText = "About",
                ItemText   = "Information about us",

                OnItemClicked = async(itemSender) =>
                {
                    try
                    {
                        var viewModel   = new HybridWebViewModel();
                        viewModel.Title = "About";

                        await base.Navigation.PushModalAsync(new HybridWebPageRenderer(viewModel, "home/about"));
                    } catch (Exception)
                    {
                        await DisplayAlert("Error", AppSettings.Constants.DisplayPageErrorMessage, "OK");
                    }
                }
            });
            collection.Add(new SettingsListItemViewModel()
            {
                HeaderText    = "Help",
                ItemText      = "Application Help",
                OnItemClicked = async(itemSender) =>
                {
                    try
                    {
                        var viewModel   = new HybridWebViewModel();
                        viewModel.Title = "Help";

                        await base.Navigation.PushModalAsync(new HybridWebPageRenderer(viewModel, "home/help"));
                    } catch (Exception)
                    {
                        await DisplayAlert("Error", AppSettings.Constants.DisplayPageErrorMessage, "OK");
                    }
                }
            });



            settingsView.ItemsSource  = collection;
            settingsView.ItemTemplate = new DataTemplate(typeof(TextCell));
            settingsView.ItemTemplate.SetBinding(TextCell.TextProperty, "HeaderText");
            settingsView.ItemTemplate.SetValue(TextCell.TextColorProperty, Color.FromHex("#E91E63"));
            settingsView.ItemTemplate.SetBinding(TextCell.DetailProperty, "ItemText");
            settingsView.ItemTemplate.SetValue(TextCell.DetailColorProperty, Color.FromHex("#37474F"));

            settingsView.ItemSelected += async(object sender, SelectedItemChangedEventArgs e) =>
            {
                await Task.Yield();

                var itemObject = e.SelectedItem  as SettingsListItemViewModel;
                if (itemObject != null)
                {
                    if (itemObject.OnItemClicked != null)
                    {
                        itemObject.OnItemClicked(sender);
                    }
                }
                settingsView.SelectedItem = null;
            };

            var sl = new StackLayout();

            sl.Orientation = StackOrientation.Horizontal;
            sl.Padding     = new Thickness(12, 8, 5, 5);
            var lbl = new Label();

            lbl.Text              = "Set Sign In page as your home page?";
            lbl.FontAttributes    = FontAttributes.Bold;
            lbl.FontSize          = Device.GetNamedSize(NamedSize.Medium, typeof(Label));
            lbl.HorizontalOptions = LayoutOptions.FillAndExpand;
            lbl.VerticalOptions   = LayoutOptions.Center;
            switchOpt             = new Switch();
            switchOpt.SetValue(Switch.IsToggledProperty, GetSwitchLandingPageOptionValue());
            switchOpt.Toggled += async(object sender, ToggledEventArgs e) =>
            {
                await Task.Yield();

                try
                {
                    var choice = e.Value;
                    if (choice)
                    {
                        App.Current.Properties [AppSettings.Constants.AppLaunchSettingsCacheKey] = DefaultLandingScreen.SignIn;
                    }
                    else
                    {
                        App.Current.Properties [AppSettings.Constants.AppLaunchSettingsCacheKey] = DefaultLandingScreen.Home;
                    }
                    await App.Current.SavePropertiesAsync();
                } catch (Exception)
                {
                    await DisplayAlert("Error", AppSettings.Constants.DisplayPageErrorMessage, "OK");
                }
            };
            sl.Children.Add(lbl);
            sl.Children.Add(switchOpt);
            this.Content = new StackLayout()
            {
                Children =
                {
                    settingsView,
                    sl
                }
            };
        }