コード例 #1
0
ファイル: SettingsPage.xaml.cs プロジェクト: kimmiboy2/Qreg
        private void Button_Clicked(object sender, EventArgs e)
        {
            //Clears properties
            Application.Current.Properties.Clear();

            //Clears templateDictionary
            TemplateDictionary.setDictionary(new Dictionary <string, string>());

            //Dispose FlurlClient
            FlurlClient_Singleton.DisposeInstance();

            Application.Current.SavePropertiesAsync();

            //Returns to loginPage
            Application.Current.MainPage.Navigation.PushAsync(new MainPage());

            //Unsubscribe to all MessagingCenters
            MessagingCenter.Unsubscribe <JSONFetcher, string>(this, "loginResponseString");
            MessagingCenter.Unsubscribe <JSONFetcher, string>(this, "CUST_PATH_LOADED");
            MessagingCenter.Unsubscribe <JSONFetcher>(this, "JSON_ACTION_GET_KEYWORDS_LOADED");
            MessagingCenter.Unsubscribe <JSONFetcher>(this, "TEMPLATES_LOADED");


            //Clears navigation stack
            var existingPages = Navigation.NavigationStack.ToList();

            foreach (var page in existingPages)
            {
                Navigation.RemovePage(page);
            }
        }
コード例 #2
0
ファイル: MainMenuPage.xaml.cs プロジェクト: kimmiboy2/Qreg
        private void loadIcons()
        {
            //Loads icon from TEMPLATE_DICTIONARY in application properties if it already exits.
            if (Application.Current.Properties.ContainsKey("TEMPLATE_DICTIONARY"))
            {
                templateDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(Application.Current.Properties["TEMPLATE_DICTIONARY"] as string);
                TemplateDictionary.setDictionary(templateDictionary);
            }
            else
            {
                templateDictionary = TemplateDictionary.Instance();
                string templateJSON = JsonConvert.SerializeObject(templateDictionary, Formatting.Indented);
                Application.Current.Properties["TEMPLATE_DICTIONARY"] = templateJSON;
                Application.Current.SavePropertiesAsync();
            }

            int left = 0;
            int top  = 0;

            for (int i = 0; i < templateDictionary.Count; i++)
            {
                StackLayout stackLayout = new StackLayout {
                    Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Start
                };
                Label label = new Label();

                //Get iconURL
                string  templateString = (string)templateDictionary[i.ToString()];
                JObject templateJSON   = JObject.Parse(templateString);
                string  iconURL        = (string)templateJSON["templateiconurl"];

                //Set image to iconURL
                var imageSource = new UriImageSource {
                    Uri = new Uri("https://e-dok.rm.dk/" + iconURL)
                };
                Image iconImage = new Image();
                iconImage.Source        = imageSource;
                iconImage.ClassId       = i.ToString();
                iconImage.HeightRequest = 100;
                iconImage.WidthRequest  = 100;
                label.Text              = (string)templateJSON["data"]["templatetitle"];
                label.TextColor         = Color.Black;
                label.HorizontalOptions = LayoutOptions.Center;

                stackLayout.Children.Add(iconImage);
                stackLayout.Children.Add(label);

                frame = new Frame {
                    Content = stackLayout, Margin = new Thickness(2, 2, 2, 2), ClassId = i.ToString(), StyleId = (string)templateJSON["data"]["templatetitle"]
                };
                frame.HasShadow = true;

                //Adds onTap event
                var tapGestureRecognizer = new TapGestureRecognizer();
                tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;
                frame.GestureRecognizers.Add(tapGestureRecognizer);

                imageList.Add(frame);
            }

            //Sort alphabetically
            List <Frame> sortedFrameList = imageList.OrderBy(o => o.StyleId).ToList();

            for (int i = 0; i < sortedFrameList.Count; i++)
            {
                frame = sortedFrameList[i];
                MainLayout.Children.Add(frame, left, top);
                left++;

                if (left > 1)
                {
                    top++;
                    left = 0;
                }
            }

            Content = ParentLayout;
        }