Esempio n. 1
0
        private void CheckIfShowTimetableAtStartupToogleSwitchShouldBeOn()
        {
            //sets default values
            if (!LocalSettingsServices.ShowTimetableAtStartup.ContainsKey())
            {
                LocalSettingsServices.ShowTimetableAtStartup.AddKey(true);
            }

            if (!LocalSettingsServices.ShowTimetableAtStartupValue.ContainsKey())
            {
                LocalSettingsServices.ShowTimetableAtStartupValue.AddKey("");
            }

            ShowTimeTableAtStartupToogleSwitch.IsOn = int.Parse(LocalSettingsServices.ShowTimetableAtStartup.GetKeyValue()) == 1;

            //fill a ComboBox.Items with names of timetables
            foreach (var t in Timetable.GetAllTimeTables(MainPage.TimeTable))
            {
                ShowTimeTableAtStartupComboBox.Items.Add(t.name);
            }

            //If switch is setted on, then we have to
            //set as selected item in ComboBox a selected
            //timetable
            if (ShowTimeTableAtStartupToogleSwitch.IsOn)
            {
                ShowTimeTableAtStartupComboBox.Visibility = Visibility.Visible;

                var nameOfSelectedItemInComboBox = LocalSettingsServices.ShowTimetableAtStartupValue.GetKeyValue();

                if (nameOfSelectedItemInComboBox == "" || ShowTimeTableAtStartupComboBox.Items == null)
                {
                    return;
                }

                int idOfSelectedItem = ShowTimeTableAtStartupComboBox.Items.IndexOf(nameOfSelectedItemInComboBox);

                if (idOfSelectedItem == -1)
                {
                    return;
                }

                var selectedItem = ShowTimeTableAtStartupComboBox.Items[idOfSelectedItem];

                ShowTimeTableAtStartupComboBox.SelectedItem = selectedItem;
                return;
            }

            ShowTimeTableAtStartupComboBox.Visibility = Visibility.Collapsed;
        }
Esempio n. 2
0
        private void ShowTimeTableAtStartupComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //we have to check if selection is changeg as first time, because
            //if we load the data, and then sets as selected some item
            //this function is called
            //and text appears. We dont want it

            bool isContentEmpty = string.IsNullOrEmpty((string)ShowTimeTableAtStartupComboBox.SelectedItem);

            if (!_firstTimeSettingsPageOpened)
            {
                if (!isContentEmpty && ((string)ShowTimeTableAtStartupComboBox.SelectedItem) == LocalSettingsServices.ShowTimetableAtStartupValue.GetKeyValue())
                {
                    _firstTimeSettingsPageOpened = true;
                    return;
                }
            }

            if (isContentEmpty)
            {
                MainPage.TimeTable.IdOfLastOpenedTimeTable = -1;
                return;
            }

            var headerTextBlock = ((TextBlock)ShowTimeTableAtStartupToogleSwitch.Header);

            if (!headerTextBlock.Text.Contains("aktualizacji"))
            {
                headerTextBlock.Text += Environment.NewLine + "Po każdej aktualizacji planu, będziesz musiał ustawić tę opcję ponownie.";
            }

            if (LocalSettingsServices.ShowTimetableAtStartup.ContainsKey())
            {
                LocalSettingsServices.ShowTimetableAtStartup.RemoveKey();
            }

            LocalSettingsServices.ShowTimetableAtStartup.AddKey(ShowTimeTableAtStartupToogleSwitch.IsOn);

            var selectedTimeTable =
                Timetable.GetAllTimeTables(MainPage.TimeTable)
                .Find(p => p.name == (ShowTimeTableAtStartupComboBox.SelectedItem as string));

            LocalSettingsServices.ShowTimetableAtStartupValue.RemoveKey();
            LocalSettingsServices.ShowTimetableAtStartupValue.AddKey(selectedTimeTable.name);
        }