protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { if (isInitialized == true) { return; } // trace page navigation TraceHelper.AddMessage("Settings: Loaded"); Email.IsEnabled = !IsConnected; Password.IsEnabled = !IsConnected; accountOperationSuccessful = false; accountTextChanged = false; SettingsPanel.Children.Clear(); foreach (var setting in PhoneSettings.Settings.Keys) { // get the source list for the setting, along with any current value var phoneSetting = PhoneSettings.Settings[setting]; //var bindingList = (from l in list select new { Name = l }).ToList(); var bindingList = phoneSetting.Values; var value = PhoneSettingsHelper.GetPhoneSetting(App.ViewModel.PhoneClientFolder, setting); int selectedIndex = 0; if (value != null && bindingList.Any(ps => ps.Name == value)) { var selectedValue = bindingList.Single(ps => ps.Name == value); selectedIndex = bindingList.IndexOf(selectedValue); } var template = !String.IsNullOrEmpty(phoneSetting.DisplayTemplate) ? (DataTemplate)App.Current.Resources[phoneSetting.DisplayTemplate] : null; // create a new list picker for the setting var listPicker = new ListPicker() { Header = setting, Tag = setting, SelectedIndex = selectedIndex >= 0 ? selectedIndex : 0 }; listPicker.ItemsSource = bindingList; listPicker.DisplayMemberPath = "Name"; if (template != null) { listPicker.FullModeItemTemplate = template; } SettingsPanel.Children.Add(listPicker); } CreateUserButton.DataContext = this; CreateButtonLabel.DataContext = this; ConnectUserButton.DataContext = this; ConnectButtonLabel.DataContext = this; Email.LostFocus += new RoutedEventHandler(delegate { accountTextChanged = true; NotifyPropertyChanged("EnableButtons"); }); Password.LostFocus += new RoutedEventHandler(delegate { accountTextChanged = true; NotifyPropertyChanged("EnableButtons"); }); isInitialized = true; }
// Event handlers for settings tab private void SaveButton_Click(object sender, EventArgs e) { // if we made changes in the account info but didn't successfully carry them out, put up a warning dialog if (accountTextChanged && !accountOperationSuccessful) { MessageBoxResult result = MessageBox.Show( "account was not successfully created or connected (possibly because you haven't clicked the 'create' or 'connect' button). " + "click ok to dismiss the settings page and forget the changes to the account page, or cancel to try again.", "exit settings before creating or connecting to an account?", MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) { return; } } // get current version of phone settings var phoneSettingsItemCopy = new Item(PhoneSettingsHelper.GetPhoneSettingsItem(App.ViewModel.PhoneClientFolder), true); // loop through the settings and store the new value foreach (var element in SettingsPanel.Children) { // get the listpicker key and value ListPicker listPicker = element as ListPicker; if (listPicker == null) { continue; } string key = (string)listPicker.Tag; var phoneSetting = PhoneSettings.Settings[key]; string value = phoneSetting.Values[listPicker.SelectedIndex].Name; // store the key/value pair in phone settings (without syncing) PhoneSettingsHelper.StorePhoneSetting(App.ViewModel.PhoneClientFolder, key, value); } // get the new version of phone settings var phoneSettingsItem = PhoneSettingsHelper.GetPhoneSettingsItem(App.ViewModel.PhoneClientFolder); // queue up a server request if (App.ViewModel.PhoneClientFolder.ID != Guid.Empty) { RequestQueue.EnqueueRequestRecord(RequestQueue.SystemQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Update, Body = new List <Item>() { phoneSettingsItemCopy, phoneSettingsItem }, BodyTypeName = "Item", ID = phoneSettingsItem.ID, IsDefaultObject = true }); // sync with the server App.ViewModel.SyncWithService(); } // trace page navigation TraceHelper.StartMessage("Settings: Navigate back"); // notify the view model that some data-bound properties bound to client settings may have changed App.ViewModel.NotifyPropertyChanged("BackgroundColor"); // go back to main page NavigationService.GoBack(); }
// // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // // You have 17 seconds to return from this method, or iOS will terminate your application. // public override bool FinishedLaunching(UIApplication app, NSDictionary options) { // trace event TraceHelper.StartMessage("App: Loaded"); // if data isn't loaded from storage yet, load the app data if (!App.ViewModel.IsDataLoaded) { // Load app data from local storage (user creds, about tab data, constants, item types, folders, etc) App.ViewModel.LoadData(); } // create pages var add = new AddPage(); var calendar = new SchedulePage(); var folders = new UINavigationController(new FoldersViewController(UITableViewStyle.Plain)); var settings = new SettingsPage(); var more = new MoreViewController(); //var more = new UINavigationController(new MoreViewController()); tabBarController = new UITabBarController(); tabBarController.ViewControllers = new UIViewController [] { add, calendar, folders, settings, more, }; tabBarController.ViewControllerSelected += (sender, e) => { UITabBarController v = (UITabBarController)sender; v.LoadView(); }; // if haven't synced with web service yet, try now if (initialSyncAlreadyHappened == false) { App.ViewModel.SyncWithService(); initialSyncAlreadyHappened = true; // if there's a home tab set, switch to it now var homeTab = PhoneSettingsHelper.GetHomeTab(App.ViewModel.PhoneClientFolder); if (homeTab != null && homeTab != "Add") { SelectTab(homeTab); } } // create a new window instance based on the screen size window = new UIWindow(UIScreen.MainScreen.Bounds); if (UIDevice.CurrentDevice.CheckSystemVersion(4, 0)) { window.RootViewController = tabBarController; } else { window.AddSubview(tabBarController.View); } window.MakeKeyAndVisible(); // trace exit TraceHelper.AddMessage("Exiting App Loaded"); return(true); }
private void CreateRoot() { // create the root for all settings. note that the RootElement is cleared and recreated, as opposed to // new'ed up from scratch. this is by design - otherwise we don't get correct behavior on page transitions // when the theme is changed. if (dvc.Root == null) { dvc.Root = new ThemedRootElement("Settings"); } else { // clean up any existing state for the existing root element if (dvc.Root.Count > 0) { // force the dismissal of the keyboard in the account settings page if it was created if (dvc.Root[0].Count > 0) { var tableView = dvc.Root[0][0].GetContainerTableView(); if (tableView != null) { tableView.EndEditing(true); } } } // clearing the root will cascade the Dispose call on its children dvc.Root.Clear(); } // create the account root element dvc.Root.Add(new Section() { InitializeAccountSettings() }); // initialize other phone settings by creating a radio element list for each phone setting var elements = (from ps in PhoneSettings.Settings.Keys select(Element) new ThemedRootElement(ps, new RadioGroup(null, 0))).ToList(); // loop through the root elements we just created and create their substructure foreach (ThemedRootElement rootElement in elements) { // set the ViewDisappearing event on child DialogViewControllers to refresh the theme rootElement.OnPrepare += (sender, e) => { DialogViewController viewController = e.ViewController as DialogViewController; viewController.ViewDisappearing += delegate { var parent = viewController.Root.GetImmediateRootElement() as RootElement; if (parent != null && parent.TableView != null) { parent.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground); } }; }; // add a radio element for each of the setting values for this setting type var section = new Section(); section.AddAll(from val in PhoneSettings.Settings[rootElement.Caption].Values select(Element) new RadioEventElement(val.Name)); rootElement.Add(section); // initialize the value of the radio button var currentValue = PhoneSettingsHelper.GetPhoneSetting(App.ViewModel.PhoneClientFolder, rootElement.Caption); var bindingList = PhoneSettings.Settings[rootElement.Caption].Values; int selectedIndex = 0; if (currentValue != null && bindingList.Any(ps => ps.Name == currentValue)) { var selectedValue = bindingList.Single(ps => ps.Name == currentValue); selectedIndex = bindingList.IndexOf(selectedValue); } rootElement.RadioSelected = selectedIndex; // attach an event handler that saves the selected setting foreach (var ree in rootElement[0].Elements) { var radioEventElement = (RadioEventElement)ree; radioEventElement.OnSelected += delegate { // make a copy of the existing version of phone settings var phoneSettingsItemCopy = new Item(PhoneSettingsHelper.GetPhoneSettingsItem(App.ViewModel.PhoneClientFolder), true); // find the key and the valuy for the current setting var radioRoot = radioEventElement.GetImmediateRootElement(); var key = radioRoot.Caption; var phoneSetting = PhoneSettings.Settings[key]; string value = phoneSetting.Values[radioRoot.RadioSelected].Name; // store the new phone setting PhoneSettingsHelper.StorePhoneSetting(App.ViewModel.PhoneClientFolder, key, value); // get the new version of phone settings var phoneSettingsItem = PhoneSettingsHelper.GetPhoneSettingsItem(App.ViewModel.PhoneClientFolder); // queue up a server request if (App.ViewModel.PhoneClientFolder.ID != Guid.Empty) { RequestQueue.EnqueueRequestRecord(RequestQueue.SystemQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Update, Body = new List <Item>() { phoneSettingsItemCopy, phoneSettingsItem }, BodyTypeName = "Item", ID = phoneSettingsItem.ID }); } // sync with the server App.ViewModel.SyncWithService(); }; } } ; // attach the other settings pages to the root element using Insert instead of AddAll so as to disable animation foreach (var e in elements) { dvc.Root[0].Insert(dvc.Root[0].Count, UITableViewRowAnimation.None, e); } }