void InitializeComponent() { // calculate the frame sizes float navBarHeight = new UINavigationController().NavigationBar.Bounds.Height; float tabBarHeight = new UITabBarController().TabBar.Bounds.Height; float availableHeight = View.Bounds.Height - navBarHeight - tabBarHeight; float toolbarHeight = navBarHeight; float tableHeight = availableHeight - toolbarHeight; // create the tableview TableView = new UITableView() { Frame = new RectangleF(0, 0, View.Bounds.Width, tableHeight) }; TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.TableBackground); TableView.SeparatorColor = UIColorHelper.FromString(App.ViewModel.Theme.TableSeparatorBackground); this.View.AddSubview(TableView); // create the toolbar Toolbar = new UIToolbar() { Frame = new RectangleF(0, tableHeight, View.Bounds.Width, toolbarHeight) }; var flexSpace = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace); //var addButton = new UIBarButtonItem("\u2795" /* big plus */ + "List", UIBarButtonItemStyle.Plain, delegate { var addButton = new UIBarButtonItem(UIBarButtonSystemItem.Add, delegate { FolderEditor folderEditor = new FolderEditor(this.NavigationController, null); folderEditor.PushViewController(); }); var editButton = new UIBarButtonItem(UIBarButtonSystemItem.Edit); var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done); editButton.Clicked += delegate { if (TableView.Editing == false) { TableView.SetEditing(true, true); Toolbar.SetItems(new UIBarButtonItem[] { flexSpace, addButton, flexSpace, doneButton, flexSpace }, false); } }; doneButton.Clicked += delegate { if (TableView.Editing == true) { TableView.SetEditing(false, true); Toolbar.SetItems(new UIBarButtonItem[] { flexSpace, addButton, flexSpace, editButton, flexSpace }, false); // trigger a sync with the Service App.ViewModel.SyncWithService(); } }; Toolbar.SetItems(new UIBarButtonItem[] { flexSpace, addButton, flexSpace, editButton, flexSpace }, false); this.View.AddSubview(Toolbar); }
private void InitializeComponent() { // create and push the view onto the nav stack dvc = new DialogViewController(new ThemedRootElement("Settings")); dvc.NavigationItem.HidesBackButton = true; dvc.Title = NSBundle.MainBundle.LocalizedString("Settings", "Settings"); dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground); this.PushViewController(dvc, false); }
private void InitializeComponent() { var root = new RootElement("More") { new Section() { new StyledStringElement("Add Folder", delegate { //var form = new FolderEditor(this.NavigationController, null); var form = new FolderEditor(this, null); form.PushViewController(); }) { Accessory = UITableViewCellAccessory.DisclosureIndicator, BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.TableBackground) }, new StyledStringElement("Add List", delegate { //r form = new ListEditor(this.NavigationController, null, null, null); var form = new ListEditor(this, null, null, null); form.PushViewController(); }) { Accessory = UITableViewCellAccessory.DisclosureIndicator, BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.TableBackground) }, new StyledStringElement("Erase All Data", delegate { MessageBoxResult result = MessageBox.Show( "are you sure you want to erase all data on the phone? unless you connected the phone to an account, your data will be not be retrievable.", "confirm erasing all data", MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) { return; } App.ViewModel.EraseAllData(); }) { Accessory = UITableViewCellAccessory.DisclosureIndicator, BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.TableBackground) }, new StyledStringElement("Debug", DebugPage) { Accessory = UITableViewCellAccessory.DisclosureIndicator, BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.TableBackground) } }, }; // create and push the dialog view onto the nav stack dvc = new DialogViewController(UITableViewStyle.Plain, root); dvc.NavigationItem.HidesBackButton = true; dvc.Title = NSBundle.MainBundle.LocalizedString("More", "More"); this.PushViewController(dvc, true); }
private void InitializeComponent() { // initialize controls ListName = new EntryElement("Name", "", folderCopy.Name); // set up the item type listpicker ItemTypePicker = new ItemTypePickerElement("Folder Type", folderCopy.ItemTypeID); var root = new RootElement("Folder Properties") { new Section() { ListName, ItemTypePicker } }; // if this isn't a new folder, render the delete button if (folder != null) { var actionButtons = new ButtonListElement() { new Button() { Caption = "Delete", Background = "Images/redbutton.png", Clicked = DeleteButton_Click }, }; actionButtons.Margin = 0f; root.Add(new Section() { actionButtons }); } if (dvc == null) { // create and push the dialog view onto the nav stack dvc = new DialogViewController(UITableViewStyle.Grouped, root); dvc.Title = NSBundle.MainBundle.LocalizedString("Folder Properties", "Folder Properties"); dvc.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, delegate { // save the item and trigger a sync with the service SaveButton_Click(null, null); }); dvc.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, delegate { NavigateBack(); }); dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground); controller.PushViewController(dvc, true); } else { // refresh the dialog view controller with the new root var oldroot = dvc.Root; dvc.Root = root; oldroot.Dispose(); dvc.ReloadData(); } }
public override void ViewDidAppear(bool animated) { TraceHelper.AddMessage("More: ViewDidAppear"); if (dvc == null) { InitializeComponent(); } // set the background dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.TableBackground); dvc.TableView.SeparatorColor = UIColorHelper.FromString(App.ViewModel.Theme.TableSeparatorBackground); base.ViewDidAppear(animated); }
public override void ViewDidAppear(bool animated) { TraceHelper.AddMessage("Folders: ViewDidAppear"); // set the background TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.TableBackground); TableView.SeparatorColor = UIColorHelper.FromString(App.ViewModel.Theme.TableSeparatorBackground); SortFolders(); TableView.ReloadData(); base.ViewDidAppear(animated); // HACK: touch the ViewControllers array to refresh it (in case the user popped the nav stack) // this is to work around a bug in monotouch (https://bugzilla.xamarin.com/show_bug.cgi?id=1889) // where the UINavigationController leaks UIViewControllers when the user pops the nav stack if (this.NavigationController.ViewControllers.Length > 0) { } }
public override void ViewDidAppear(bool animated) { TraceHelper.AddMessage("Settings: ViewDidAppear"); if (dvc == null) { InitializeComponent(); } else { CreateRoot(); } // set the background dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground); dvc.ReloadData(); base.ViewDidAppear(animated); }
public void PushViewController() { // trace event TraceHelper.AddMessage("ListPicker: PushViewController"); // if the sublist hasn't been created, do so now if (valueList.ID == Guid.Empty) { Guid id = Guid.NewGuid(); valueList.ID = id; // fix the pickList's ParentID's to this new list ID (otherwise they stay Guid.Empty) foreach (var i in pickList.Items) { i.ParentID = id; } // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = valueList }); // add the list to the folder Folder folder = App.ViewModel.Folders.Single(f => f.ID == valueList.FolderID); folder.Items.Add(valueList); StorageHelper.WriteFolder(folder); // store the list's Guid in the item's property pi.SetValue(container, id.ToString(), null); // save the item change, which will queue up the update item operation //itemPage.SaveButton_Click(null, null); } // build the current picker list and render it currentList = BuildCurrentList(valueList, pickList); root = RenderPicker(valueList, pickList); dvc = new DialogViewController(root, true); dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground); controller.PushViewController(dvc, true); }
public override void ViewDidAppear(bool animated) { TraceHelper.AddMessage("Schedule: ViewDidAppear"); // initialize an empty DVC if hasn't happened yet if (dvc == null) { InitializeComponent(); } // refresh the dialog view controller with the new root (dvc disposes the old root) dvc.Root = CreateScheduleRoot(); //dvc.ReloadData(); // set the background dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.TableBackground); dvc.TableView.SeparatorColor = UIColorHelper.FromString(App.ViewModel.Theme.TableSeparatorBackground); base.ViewDidAppear(animated); }
public override void ViewDidAppear(bool animated) { // trace event TraceHelper.AddMessage("Add: ViewDidAppear"); if (dialogViewController == null) { InitializeComponent(); } // set the background dialogViewController.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground); // initialize controls Name.Value = ""; // populate the lists section dynamically listsSection.Clear(); CreateAddButtons(); // add the buttons by using Insert instead of AddAll, which allows disabling the animation foreach (var b in AddButtons) { if (b != null) { listsSection.Insert(listsSection.Count, UITableViewRowAnimation.None, b); } } // HACK: touch the ViewControllers array to refresh it (in case the user popped the nav stack) // this is to work around a bug in monotouch (https://bugzilla.xamarin.com/show_bug.cgi?id=1889) // where the UINavigationController leaks UIViewControllers when the user pops the nav stack if (this.NavigationController != null && this.NavigationController.ViewControllers != null) { if (this.NavigationController.ViewControllers.Length > 0) { } } base.ViewDidAppear(animated); }
private void CreateAddButtons() { if (AddButtons == null) { AddButtons = new ButtonListElement[3]; } // get all the lists var entityRefItems = App.ViewModel.GetListsOrderedBySelectedCount(); lists = new List <ClientEntity>(); foreach (var entityRefItem in entityRefItems) { var entityType = entityRefItem.GetFieldValue(FieldNames.EntityType).Value; var entityID = new Guid(entityRefItem.GetFieldValue(FieldNames.EntityRef).Value); if (entityType == typeof(Folder).Name && App.ViewModel.Folders.Any(f => f.ID == entityID)) { lists.Add(App.ViewModel.Folders.Single(f => f.ID == entityID)); } if (entityType == typeof(Item).Name && App.ViewModel.Items.Any(i => i.ID == entityID)) { lists.Add(App.ViewModel.Items.Single(i => i.ID == entityID)); } } // create a list of buttons - one for each list buttonList = (from it in lists select new Button() { Background = "Images/darkgreybutton.png", Caption = it.Name, Clicked = AddButton_Click }).ToList(); // clear the button rows for (int i = 0; i < AddButtons.Length; i++) { AddButtons[i] = null; } // assemble the buttons into rows (maximum of six buttons and two rows) // if there are three or less buttons, one row // otherwise distribute evenly across two rows int count = Math.Min(buttonList.Count, MaxLists); int firstrow = count, secondrow = 0, addButtonsRow = 0; if (count > MaxLists / 2) { firstrow = count / 2; secondrow = count - firstrow; } if (firstrow > 0) { AddButtons[addButtonsRow++] = new ButtonListElement() { buttonList.Take(firstrow) }; } if (secondrow > 0) { AddButtons[addButtonsRow++] = new ButtonListElement() { buttonList.Skip(firstrow).Take(secondrow) }; } // create a last "row" of buttons containing only one "More..." button which will bring up the folder/list page AddButtons[addButtonsRow] = new ButtonListElement() { new Button() { Background = "Images/darkgreybutton.png", Caption = "More...", Clicked = (s, e) => { // assemble a page which contains a hierarchy of every folder and list, grouped by folder var title = String.IsNullOrEmpty(Name.Value) ? "Navigate to:" : "Add " + Name.Value + " to:"; ListsRootElement = new ThemedRootElement(title) { from f in App.ViewModel.Folders orderby f.Name ascending select new Section() { new StyledStringElement(f.Name, delegate { AddItem(f, null); // increment the selected count for this folder and sync if this isn't an actual Add ListMetadataHelper.IncrementListSelectedCount(App.ViewModel.PhoneClientFolder, f); // (do not sync for operations against $ClientSettings) //if (String.IsNullOrWhiteSpace(Name.Value)) // App.ViewModel.SyncWithService(); }) { Image = UIImageCache.GetUIImage("Images/appbar.folder.rest.png") }, from li in f.Items where li.IsList == true && li.ItemTypeID != SystemItemTypes.Reference orderby li.Name ascending select(Element) new StyledStringElement(" " + li.Name, delegate { AddItem(f, li); // increment the selected count for this list and sync if this isn't an actual Add ListMetadataHelper.IncrementListSelectedCount(App.ViewModel.PhoneClientFolder, li); // (do not sync for operations against $ClientSettings) //if (String.IsNullOrWhiteSpace(Name.Value)) // App.ViewModel.SyncWithService(); }) { Image = UIImageCache.GetUIImage("Images/179-notepad.png") } } }; var dvc = new DialogViewController(ListsRootElement, true); dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground); dvc.NavigationItem.HidesBackButton = false; dialogViewController.NavigationController.PushViewController(dvc, true); } } }; }
public void DebugPage() { TraceHelper.AddMessage("Debug: constructor"); // render URL and status var serviceUrl = new EntryElement("URL", "URL to connect to", WebServiceHelper.BaseUrl); var service = new Section("Service") { serviceUrl, new StringElement("Store New Service URL", delegate { serviceUrl.FetchValue(); // validate that this is a good URL before storing it (a bad URL can hose the phone client) Uri uri = null; if (Uri.TryCreate(serviceUrl.Value, UriKind.RelativeOrAbsolute, out uri) && (uri.Scheme == "http" || uri.Scheme == "https")) { WebServiceHelper.BaseUrl = serviceUrl.Value; } else { serviceUrl.Value = WebServiceHelper.BaseUrl; } }), new StringElement("Connected", App.ViewModel.LastNetworkOperationStatus.ToString()), }; // render user queue var userQueue = new Section("User Queue"); userQueue.Add(new StringElement( "Clear Queue", delegate { RequestQueue.DeleteQueue(RequestQueue.UserQueue); userQueue.Clear(); })); List <RequestQueue.RequestRecord> requests = RequestQueue.GetAllRequestRecords(RequestQueue.UserQueue); if (requests != null) { foreach (var req in requests) { string typename; string reqtype; string id; string name; RequestQueue.RetrieveRequestInfo(req, out typename, out reqtype, out id, out name); var sse = new StyledStringElement(String.Format(" {0} {1} {2} (id {3})", reqtype, typename, name, id)) { Font = UIFont.FromName("Helvetica", UIFont.SmallSystemFontSize), }; userQueue.Add(sse); } } // render system queue var systemQueue = new Section("System Queue"); systemQueue.Add(new StringElement( "Clear Queue", delegate { RequestQueue.DeleteQueue(RequestQueue.SystemQueue); systemQueue.Clear(); })); requests = RequestQueue.GetAllRequestRecords(RequestQueue.SystemQueue); if (requests != null) { foreach (var req in requests) { string typename; string reqtype; string id; string name; RequestQueue.RetrieveRequestInfo(req, out typename, out reqtype, out id, out name); var sse = new StyledStringElement(String.Format(" {0} {1} {2} (id {3})", reqtype, typename, name, id)) { Font = UIFont.FromName("Helvetica", UIFont.SmallSystemFontSize), }; systemQueue.Add(sse); } } var traceMessages = new Section("Trace Messages"); traceMessages.Add(new StringElement( "Clear Trace", delegate { TraceHelper.ClearMessages(); traceMessages.Clear(); })); traceMessages.Add(new StringElement( "Send Trace", delegate { TraceHelper.SendMessages(App.ViewModel.User); })); foreach (var m in TraceHelper.GetMessages().Split('\n')) { // skip empty messages if (m == "") { continue; } // create a new (small) string element with a detail indicator which // brings up a message box with the entire message var sse = new StyledStringElement(m) { Accessory = UITableViewCellAccessory.DetailDisclosureButton, Font = UIFont.FromName("Helvetica", UIFont.SmallSystemFontSize), }; string msg = m; // make a copy for the closure below sse.AccessoryTapped += delegate { var alert = new UIAlertView("Detail", msg, null, "Ok"); alert.Show(); }; traceMessages.Add(sse); } ; var root = new RootElement("Debug") { service, userQueue, systemQueue, traceMessages, }; var dvc = new DialogViewController(root, true); dvc.TableView.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground); this.PushViewController(dvc, true); //this.NavigationController.PushViewController (dvc, 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); } }