コード例 #1
0
        public static string GetUrl(InfoUrl urlType, string twoLetterIsoLanguageCode)
        {
            twoLetterIsoLanguageCode = AsNorwegian.Any(x => x == twoLetterIsoLanguageCode) ? "no" : "en";

            var appVersionLastDelimiterIndex = AppInfo.VersionString.LastIndexOf('.');
            var appVersion = AppInfo.VersionString.Substring(0, appVersionLastDelimiterIndex);
            var osVersion  = DeviceInfo.Platform.ToString().ToLower();

            var urlPath = string.Empty;

            if (urlType == InfoUrl.Consent)
            {
                urlPath = $"consent_{twoLetterIsoLanguageCode}";
            }
            else if (urlType == InfoUrl.Defibrillator)
            {
                urlPath = $"defibrillator_{twoLetterIsoLanguageCode}";
            }
            else if (urlType == InfoUrl.Permissions)
            {
                urlPath = $"permissions_{osVersion}_{twoLetterIsoLanguageCode}";
            }
            else if (urlType == InfoUrl.Phone)
            {
                urlPath = $"phone_{twoLetterIsoLanguageCode}";
            }
            else if (urlType == InfoUrl.PrivacyPolicy)
            {
                urlPath = $"privacy_policy_{twoLetterIsoLanguageCode}";
            }
            else if (urlType == InfoUrl.Terms)
            {
                urlPath = $"terms_{twoLetterIsoLanguageCode}";
            }
            else
            {
                throw new Exception("Unrecognized URL");
            }

            var url = $"{UrlBase}{urlPath}.html";

            return(System.Text.RegularExpressions.Regex.Escape(url));
        }
コード例 #2
0
        public void SetupView(InfoUrl urlType)
        {
            actIndicator.Hidden = false;

            this.View.BackgroundColor = UIColor.Orange;

            webView.ShouldStartLoad = HandleShouldStartLoad;
            webView.Opaque          = false;
            webView.BackgroundColor = UIColor.Clear;

            string style = "<style>";

            style = style + " @font-face {font-family: 'Montserrat-Regular';src: url('Montserrat-Regular.ttf'), format('truetype') ;}";
            style = style + " @font-face {font-family: 'Montserrat-Medium';src: url('Fonts/Montserrat-Medium.ttf'), format('truetype');}";
            style = style + " h1 {font-family: 'Montserrat-Medium'; font-size: 16px;font-weight: normal;}";
            style = style + " h2 {font-family: 'Montserrat-Medium'; font-size: 14px;font-weight: normal;}";
            style = style + " h3 {font-family: 'Montserrat-Regular'; font-size: 14px;}";
            style = style + " body {font-family: 'Montserrat-Regular'; font-size: 14px;margin-left: 20px;margin-right: 20px;}";
            style = style + " }</style>";

            string languageCode = LangUtil.GetLanguage();
            string url          = UrlUtil.GetUrl(urlType, languageCode);

            //https://blog.xamarin.com/getting-started-with-async-await/
            CancellationTokenSource cts;

            // Create new CancellationTokenSource for this view's async call
            cts = new CancellationTokenSource();

            // Get the cancellation token to pass into the async method
            var ct = cts.Token;

            Task.Run(async() =>
            {
                try
                {
                    // Call my async method, whihc in turn calls an HttpClient async method.
                    string html  = await GetTextAsync(url, ct);
                    html         = html.Replace("<head>", "<head> " + style);
                    string title = GetTitle(html);

                    BeginInvokeOnMainThread(delegate
                    {
                        Title     = title;
                        string hh = GetBaseUrl();
                        webView.LoadHtmlString(html, new NSUrl(GetBaseUrl()));
                        actIndicator.Hidden = true;
                    });
                }
                // Catch the exception when the async method is cancelled
                catch (System.OperationCanceledException ex)
                {
                    //   Log.Debug("WEB", $"Text load cancelled: {ex.Message}");
                }
                // Catch any other exceptinons that may have occured
                catch (Exception ex)
                {
                    // Log.Debug("WEB", ex.Message);
                }
            }, ct);
        }