public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath) { if (editingStyle == UITableViewCellEditingStyle.Delete) { // get the folder from the local collection, and refresh it from the viewmodel in case // it changed underneath us Folder folder = controller.Folders[indexPath.Row]; if (App.ViewModel.Folders.Any(f => f.ID == folder.ID)) { folder = App.ViewModel.Folders.Single(f => f.ID == folder.ID); } // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Delete, Body = folder }); // save the changes to local storage App.ViewModel.FolderDictionary.Remove(folder.ID); App.ViewModel.Folders.Remove(folder); StorageHelper.WriteFolders(App.ViewModel.Folders); StorageHelper.DeleteFolder(folder); // refresh the table UI controller.SortFolders(); tableView.DeleteRows(new [] { indexPath }, UITableViewRowAnimation.Fade); } }
private void ImportListPopup_ImportButton_Click(object sender, RoutedEventArgs e) { Item target = ImportListPopupListPicker.SelectedItem as Item; if (target == null) { return; } // create a copy of the item and attach all the non-list children to its Items collection Item targetList = new Item(target, false); targetList.Items = App.ViewModel.Items.Where(i => i.ParentID == target.ID && i.IsList != true).ToObservableCollection(); // add the items in the template to the existing folder foreach (Item i in targetList.Items) { DateTime now = DateTime.UtcNow; // create the new item Item item = new Item(i) { ID = Guid.NewGuid(), FolderID = folder.ID, ParentID = list.ID, Created = now, LastModified = now }; // recreate the itemtags (they must be unique) if (item.ItemTags != null && item.ItemTags.Count > 0) { foreach (var tt in item.ItemTags) { tt.ID = Guid.NewGuid(); } } // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = item }); // add the item to the folder and list folder.Items.Add(item); list.Items.Add(item); } // render the list ListHelper.RenderList(list); // save the changes to local storage StorageHelper.WriteFolder(folder); // trigger a sync with the Service App.ViewModel.SyncWithService(); // close the popup importPopupOpen = false; ImportListPopup.IsOpen = false; }
private static Item CreateNewContact(ABPerson selectedPerson) { Guid id = Guid.NewGuid(); // get the default list for contacts Guid folderID; Guid? parentID = null; ClientEntity defaultList = App.ViewModel.GetDefaultList(SystemItemTypes.Contact); if (defaultList == null) { TraceHelper.AddMessage("CreateNewContact: error - could not find default contact list"); return(null); } if (defaultList is Item) { folderID = ((Item)defaultList).FolderID; parentID = defaultList.ID; } else { folderID = defaultList.ID; parentID = null; } Item newContact = new Item() { ID = id, Name = selectedPerson.ToString(), FolderID = folderID, ParentID = parentID, ItemTypeID = SystemItemTypes.Contact, FieldValues = new ObservableCollection <FieldValue>() }; // add the new contact locally Folder folder = App.ViewModel.Folders.FirstOrDefault(f => f.ID == folderID); if (folder == null) { TraceHelper.AddMessage("CreateNewContact: error - could not find the folder for this item"); return(null); } folder.Items.Add(newContact); // save the current state of the folder StorageHelper.WriteFolder(folder); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = newContact, }); return(newContact); }
/// <summary> /// Handle click event on Complete checkbox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CompleteCheckbox_Click(object sender, RoutedEventArgs e) { // trace data TraceHelper.StartMessage("CompleteCheckbox Click"); CheckBox cb = (CheckBox)e.OriginalSource; Guid itemID = (Guid)cb.Tag; // get the item that was just updated, and ensure the Complete flag is in the correct state Item item = folder.Items.Single <Item>(t => t.ID == itemID); // create a copy of that item Item itemCopy = new Item(item); // toggle the complete flag to reflect the checkbox click item.Complete = (item.Complete == null) ? true : !item.Complete; // bump the last modified timestamp item.LastModified = DateTime.UtcNow; if (item.Complete == true) { item.CompletedOn = item.LastModified.ToString("o"); } else { item.CompletedOn = null; } // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Update, Body = new List <Item>() { itemCopy, item }, BodyTypeName = "Item", ID = item.ID }); // reorder the item in the folder and the ListBox ListHelper.ReOrderItem(list, item); // save the changes to local storage StorageHelper.WriteFolder(folder); // trigger a sync with the Service App.ViewModel.SyncWithService(); // trace data TraceHelper.AddMessage("Finished CompleteCheckbox Click"); }
private ObservableCollection<Folder> InitializeFolders() { // get the default folders and enqueue an operation to insert each one of them and their subitems var folders = new ObservableCollection<Folder>(UserConstants.DefaultFolders(null)); foreach (var folder in folders) { string queueName = folder.Name.StartsWith("$") ? RequestQueue.SystemQueue : RequestQueue.UserQueue; FolderDictionary.Add(folder.ID, folder); RequestQueue.EnqueueRequestRecord(queueName, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = folder, ID = folder.ID, IsDefaultObject = true }); foreach (var item in folder.Items) { RequestQueue.EnqueueRequestRecord(queueName, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = item, ID = item.ID, IsDefaultObject = true }); } StorageHelper.WriteFolder(folder); } // extract the $Client folder and handle it specially var cf = folders.Single(f => f.Name == SystemEntities.Client); folders.Remove(cf); ClientFolder = cf; // extract the $PhoneClient folder and handle it specially var pcf = folders.Single(f => f.Name == SystemEntities.PhoneClient); folders.Remove(pcf); PhoneClientFolder = pcf; // initialize the SelectedCount for a few default folders and lists /* foreach (var folder in folders) { if (folder.Name == UserEntities.People || folder.Name == UserEntities.Places) { ListMetadataHelper.IncrementListSelectedCount(pcf, folder); continue; } foreach (var item in folder.Items) { if (item.Name == UserEntities.Tasks || item.Name == UserEntities.Groceries) { ListMetadataHelper.IncrementListSelectedCount(pcf, item); continue; } } } */ return folders; }
// Event handlers for Debug page #region Event Handlers private void Debug_AddButton_Click(object sender, EventArgs e) { Item item; Item taskList, groceryList; // create some debug records // create a to-do style item Folder folder = App.ViewModel.Folders.Single(f => f.Name == "Activities"); taskList = App.ViewModel.Items.Single(i => i.ItemTypeID == SystemItemTypes.Task && i.IsList == true); folder.Items.Add(item = new Item() { FolderID = folder.ID, ParentID = taskList.ID, ItemTypeID = SystemItemTypes.Task, SortOrder = 1000, Name = "Check out Zaplify", Due = DateTime.Today, Priority = 1 }); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = item, ID = item.ID }); folder = App.ViewModel.Folders.Single(f => f.Name == "Lists"); groceryList = App.ViewModel.Items.Single(i => i.ItemTypeID == SystemItemTypes.Grocery && i.IsList == true); // create a shopping item int index = 1; string[] names = { "Milk", "OJ", "Cereal", "Coffee", "Bread" }; foreach (var name in names) { folder.Items.Add(item = new Item() { FolderID = folder.ID, ParentID = groceryList.ID, ItemTypeID = SystemItemTypes.Grocery, SortOrder = (1000 * index), Name = name }); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = item, ID = item.ID }); } // re-render the debug tab RenderDebugPanel(); }
private void DeleteCompletedMenuItem_Click(object sender, EventArgs e) { MessageBoxResult result = MessageBox.Show("delete all completed items in this folder?", "confirm delete", MessageBoxButton.OKCancel); if (result != MessageBoxResult.OK) { return; } // create a copy of the list to foreach over. this is because we can't delete // from the original collection while it's being enumerated. the copy we make is shallow // so as not to create brand new Item objects, but then we add all the item references to // an new Items collection that won't interfere with the existing one. Item itemlist = new Item(list, false); itemlist.Items = new ObservableCollection <Item>(); foreach (Item i in list.Items) { if (i.ItemTypeID != SystemItemTypes.System) { itemlist.Items.Add(i); } } // remove any completed items from the original list foreach (var item in itemlist.Items) { if (item.Complete == true) { // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Delete, Body = item }); // remove the item (and all subitems) from the local folder (and local storage) App.ViewModel.RemoveItem(item); list.Items.Remove(item); } } // recreate the List ListHelper.RenderList(list); // save the changes to local storage StorageHelper.WriteFolder(folder); // trigger a sync with the Service App.ViewModel.SyncWithService(); }
private void HandleAddedContact(Item contact) { // if this contact was found and already selected, nothing more to do (and don't need to refresh the display) if (valueList.Items.Any(i => i.ItemRef == contact.ID)) { return; } // create a new itemref var itemRef = new Item() { Name = contact.Name, FolderID = valueList.FolderID, ItemTypeID = SystemItemTypes.Reference, ParentID = valueList.ID, ItemRef = contact.ID }; // add the itemref to the folder Folder folder = App.ViewModel.Folders.FirstOrDefault(f => f.ID == valueList.FolderID); if (folder == null) { return; } folder.Items.Add(itemRef); // save the current state of the folder StorageHelper.WriteFolder(folder); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = itemRef, }); // add the new item reference to the selected value list valueList.Items.Add(itemRef); // build the current picker list and render it currentList = BuildCurrentList(valueList, pickList); root = RenderPicker(valueList, pickList); dvc.Root = root; dvc.TableView.ReloadData(); // re-render the comma-delimited list in the Element that was passed in RenderCommaList(stringElement, valueList); stringElement.GetImmediateRootElement().Reload(stringElement, UITableViewRowAnimation.None); }
private void DeleteButton_Click(object sender, EventArgs e) { // if this is a new list, delete just does the same thing as cancel if (list == null) { CancelButton_Click(sender, e); return; } MessageBoxResult result = MessageBox.Show(String.Format("delete {0}?", list.Name), "confirm delete", MessageBoxButton.OKCancel); if (result != MessageBoxResult.OK) { return; } // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Delete, Body = list }); // reobtain the current folder (it may have been replaced by a GetUser operations since the ListEditor was invoked) Folder currentFolder = App.ViewModel.LoadFolder(list.FolderID); // remove the item from the viewmodel list = currentFolder.Items.Single(i => i.ID == list.ID); currentFolder.Items.Remove(list); // save the changes to local storage StorageHelper.WriteFolder(currentFolder); // trigger a sync with the Service App.ViewModel.SyncWithService(); // trace page navigation TraceHelper.StartMessage("ListEditor: Navigate back"); // Pop twice and navigate back to the list page controller.PopViewControllerAnimated(false); NavigateBack(); }
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); }
private void DeleteButton_Click(object sender, EventArgs e) { // if this is a new folder, delete just does the same thing as cancel if (folder == null) { CancelButton_Click(sender, e); return; } MessageBoxResult result = MessageBox.Show("delete this folder?", "confirm delete", MessageBoxButton.OKCancel); if (result != MessageBoxResult.OK) { return; } // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Delete, Body = folder }); // remove the item from the viewmodel App.ViewModel.Folders.Remove(folder); App.ViewModel.FolderDictionary.Remove(folder.ID); // save the changes to local storage StorageHelper.WriteFolders(App.ViewModel.Folders); StorageHelper.DeleteFolder(folder); // trigger a sync with the Service App.ViewModel.SyncWithService(); // trace page navigation TraceHelper.StartMessage("FolderEditor: Navigate back"); // Pop twice and navigate back to the folder page controller.PopViewControllerAnimated(false); NavigateBack(); }
private void CreateItem(string name, Folder folder, ItemType itemType, Guid parentID) { // figure out the sort value float sortOrder = 1000f; var listItems = folder.Items.Where(it => it.ParentID == parentID).ToList(); if (listItems.Count > 0) { sortOrder += listItems.Max(it => it.SortOrder); } // create the new item Item item = new Item() { Name = name, FolderID = folder.ID, ItemTypeID = itemType.ID, ParentID = parentID, SortOrder = sortOrder }; // hack: special case processing for item types that have a Complete field // if it exists, set it to false if (itemType.HasField("Complete")) { item.Complete = false; } // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = item }); // add the item to the folder folder.Items.Add(item); }
private void DeleteButton_Click(object sender, EventArgs e) { // if this is a new tag, delete just does the same thing as cancel if (tag == null) { CancelButton_Click(sender, e); return; } MessageBoxResult result = MessageBox.Show("delete this tag?", "confirm delete", MessageBoxButton.OKCancel); if (result != MessageBoxResult.OK) { return; } // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Delete, Body = tag }); // remove the tag App.ViewModel.Tags.Remove(tag); // save the changes to local storage StorageHelper.WriteTags(App.ViewModel.Tags); // trigger a sync with the Service App.ViewModel.SyncWithService(); // trace page navigation TraceHelper.StartMessage("TagEditor: Navigate back"); // Navigate back to the main page NavigationService.GoBack(); }
// 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(); }
private void SaveButton_Click(object sender, EventArgs e) { // get the name of the tag tagCopy.Name = TagName.Text; // get the color from the listpicker tagCopy.ColorID = App.ViewModel.Constants.Colors[ColorListPicker.SelectedIndex].ColorID; // check for appropriate values if (tagCopy.Name == "") { MessageBox.Show("tag name cannot be empty"); return; } // if this is a new tag, create it if (tag == null) { // enqueue the Web Request Record (with a new copy of the tag) // need to create a copy because otherwise other items may be added to it // and we want the record to have exactly one operation in it (create the tag) RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = new Tag(tagCopy) }); // add the tag to the tag folder App.ViewModel.Tags.Add(tagCopy); } else // this is an update { // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Update, Body = new List <Tag>() { tag, tagCopy }, BodyTypeName = "Tag", ID = tagCopy.ID }); // save the changes to the existing tag tag.Copy(tagCopy); } // save the changes to local storage StorageHelper.WriteTags(App.ViewModel.Tags); // trigger a sync with the Service App.ViewModel.SyncWithService(); // trace page navigation TraceHelper.StartMessage("TagEditor: Navigate back"); // Navigate back to the main page NavigationService.GoBack(); }
private void QuickAddPopup_AddButton_Click(object sender, RoutedEventArgs e) { string name = QuickAddPopupTextBox.Text; // don't add empty items if (name == null || name == "") { return; } int itemTypeIndex = QuickAddPopupItemTypePicker.SelectedIndex; if (itemTypeIndex < 0) { MessageBox.Show("item type must be set"); return; } ItemType itemType = App.ViewModel.ItemTypes[itemTypeIndex]; // get the value of the IsList checkbox bool isChecked = (QuickAddPopupIsListCheckbox.IsChecked == null) ? false : (bool)QuickAddPopupIsListCheckbox.IsChecked; // figure out the sort value Guid? parentID = (list.ID == Guid.Empty) ? null : (Guid?)list.ID; float sortOrder = 1000f; var listItems = folder.Items.Where(it => it.ParentID == parentID).ToList(); if (listItems.Count > 0) { sortOrder += listItems.Max(it => it.SortOrder); } // create the new item Item item = new Item() { Name = name, FolderID = folder.ID, ItemTypeID = itemType.ID, ParentID = list.ID, IsList = isChecked, SortOrder = sortOrder }; // hack: special case processing for item types that have a Complete field // if it exists, set it to false if (itemType.HasField("Complete")) { item.Complete = false; } // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = item }); // add the new item to the list list.Items.Add(item); ListHelper.AddItem(list, item); // add the item to the folder and list and re-render list folder.Items.Add(item); // save the changes to local storage StorageHelper.WriteFolder(folder); // trigger a sync with the Service App.ViewModel.SyncWithService(); // clear the textbox and focus back to it QuickAddPopupTextBox.Text = ""; QuickAddPopupTextBox.Focus(); }
public override void MoveRow(UITableView tableView, NSIndexPath sourceIndexPath, NSIndexPath destinationIndexPath) { int sourceRow = sourceIndexPath.Row; int destRow = destinationIndexPath.Row; float before, after; Folder folder = controller.Folders[sourceRow]; // compute the new sort order for the folder based on the directiom of motion (up or down) if (sourceRow < destRow) { // moving down - new position is the average of target position plus next position before = controller.Folders[destRow].SortOrder; if (destRow >= controller.Folders.Count - 1) { after = before + 1000f; } else { after = controller.Folders[destRow + 1].SortOrder; } } else { // moving up - new position is the average of target position plus previous position after = controller.Folders[destRow].SortOrder; if (destRow == 0) { before = 0; } else { before = controller.Folders[destRow - 1].SortOrder; } } float newSortOrder = (before + after) / 2; // make a copy of the folder for the Update operation Folder folderCopy = new Folder(folder); folder.SortOrder = newSortOrder; // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Update, Body = new List <Folder>() { folderCopy, folder }, BodyTypeName = typeof(Folder).Name, ID = folder.ID }); // save the changes to local storage StorageHelper.WriteFolder(folder); StorageHelper.WriteFolders(App.ViewModel.Folders); // re-sort the current folder list, and have the table view update its UI controller.SortFolders(); tableView.MoveRow(sourceIndexPath, destinationIndexPath); }
private void SaveButton_Click(object sender, EventArgs e) { // get the property values folderCopy.Name = ListName.Value; folderCopy.ItemTypeID = ItemTypePicker.SelectedItemType; // check for appropriate values if (folderCopy.Name == "") { MessageBox.Show("folder name cannot be empty"); return; } // if this is a new folder, create it if (folder == null) { folder = folderCopy; // figure out the sort value float sortOrder = 1000f; if (App.ViewModel.Folders.Count > 0) { sortOrder += App.ViewModel.Folders.Max(f => f.SortOrder); } folder.SortOrder = sortOrder; // enqueue the Web Request Record (with a new copy of the folder) // need to create a copy because otherwise other items may be added to it // and we want the record to have exactly one operation in it (create the folder) RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = new Folder(folder) }); // add the item to the local itemType App.ViewModel.Folders.Add(folder); } else // this is an update { // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Update, Body = new List <Folder>() { folder, folderCopy }, BodyTypeName = "Folder", ID = folder.ID }); // save the changes to the existing folder (make a deep copy) folder.Copy(folderCopy, true); } // save the changes to local storage StorageHelper.WriteFolder(folder); StorageHelper.WriteFolders(App.ViewModel.Folders); // trigger a sync with the Service App.ViewModel.SyncWithService(); // trace page navigation TraceHelper.StartMessage("FolderEditor: Navigate back"); // Navigate back to the main page NavigateBack(); }
private void SaveButton_Click(object sender, EventArgs e) { // get the name of the list listCopy.Name = ListName.Value; // get parent list listCopy.FolderID = ParentListPicker.SelectedFolderID; listCopy.ParentID = ParentListPicker.SelectedParentID; // get item type listCopy.ItemTypeID = ItemTypePicker.SelectedItemType; // check for appropriate values if (listCopy.Name == "") { MessageBox.Show("name cannot be empty"); return; } // get a reference to the folder of the new or existing list Folder currentFolder = App.ViewModel.LoadFolder(listCopy.FolderID); // if this is a new list, create it if (list == null) { // figure out the sort value float sortOrder = 1000f; var listItems = currentFolder.Items.Where(it => it.ParentID == listCopy.ParentID).ToList(); if (listItems.Count > 0) { sortOrder += listItems.Max(it => it.SortOrder); } listCopy.SortOrder = sortOrder; // enqueue the Web Request Record (with a new copy of the list) // need to create a copy because otherwise other items may be added to it // and we want the record to have exactly one operation in it (create the list) RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = new Item(listCopy) }); // add the item to the local Folder currentFolder.Items.Add(listCopy); } else // this is an update { // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Update, Body = new List <Item>() { list, listCopy }, BodyTypeName = "Item", ID = list.ID }); // save the changes to the existing list (make a deep copy) list.Copy(listCopy, true); // save the new list properties back to the item in the folder var item = currentFolder.Items.Single(i => i.ID == list.ID); item.Name = list.Name; item.ItemTypeID = list.ItemTypeID; item.ParentID = list.ParentID; item.FolderID = list.FolderID; } // save the changes to local storage StorageHelper.WriteFolder(currentFolder); // trigger a sync with the Service App.ViewModel.SyncWithService(); // trace page navigation TraceHelper.StartMessage("ListEditor: Navigate back"); // Navigate back to the main page NavigateBack(); }
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); } }
private void Checkbox_Click(object sender, EventArgs e) { var element = sender as Element; bool isChecked; var cie = element as CheckboxImageElement; if (cie == null) { var ce = element as CheckboxElement; if (ce == null) { return; } else { isChecked = ce.Value; } } else { isChecked = cie.Value; } int index = section.Elements.IndexOf(element); if (index < 0) { return; } // get the clicked item Item currentItem = currentList[index]; Folder folder = App.ViewModel.Folders.Single(f => f.ID == currentItem.FolderID); if (isChecked) { // add the clicked item to the value list valueList.Items.Add(currentItem); folder.Items.Add(currentItem); StorageHelper.WriteFolder(folder); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = currentItem }); } else { // remove the clicked item from the value list valueList.Items.Remove(currentItem); folder.Items.Remove(currentItem); StorageHelper.WriteFolder(folder); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Delete, Body = currentItem }); } // re-render the comma-delimited list in the Element that was passed in RenderCommaList(stringElement, valueList); stringElement.GetImmediateRootElement().Reload(stringElement, UITableViewRowAnimation.None); }
public static void AddContactInfo(Contact contact, Item item) { if (contact == null) { return; } // make a copy of the item var itemCopy = new Item(item, true); // get more info from the address book var mobile = (from p in contact.PhoneNumbers where p.Kind == PhoneNumberKind.Mobile select p.PhoneNumber).FirstOrDefault(); var home = (from p in contact.PhoneNumbers where p.Kind == PhoneNumberKind.Home select p.PhoneNumber).FirstOrDefault(); var work = (from p in contact.PhoneNumbers where p.Kind == PhoneNumberKind.Work select p.PhoneNumber).FirstOrDefault(); var email = (from em in contact.EmailAddresses select em.EmailAddress).FirstOrDefault(); var website = (from w in contact.Websites select w).FirstOrDefault(); var birthday = (from b in contact.Birthdays select b).FirstOrDefault(); string FacebookPrefix = "fb://profile/"; var facebook = (from w in contact.Websites where w.Contains(FacebookPrefix) select w).FirstOrDefault(); var fbid = !String.IsNullOrWhiteSpace(facebook) ? facebook.Substring(facebook.IndexOf(FacebookPrefix) + FacebookPrefix.Length) : null; if (birthday != null && birthday.Ticks != 0) { item.GetFieldValue(FieldNames.Birthday, true).Value = birthday.ToString("d"); } if (mobile != null) { item.GetFieldValue(FieldNames.Phone, true).Value = mobile; } if (home != null) { item.GetFieldValue(FieldNames.HomePhone, true).Value = home; } if (work != null) { item.GetFieldValue(FieldNames.WorkPhone, true).Value = work; } if (email != null) { item.GetFieldValue(FieldNames.Email, true).Value = email; } //if (website != null) // item.GetFieldValue(FieldNames.Website, true).Value = website; if (fbid != null) { item.GetFieldValue(FieldNames.FacebookID, true).Value = fbid; var sourcesFV = item.GetFieldValue(FieldNames.Sources, true); if (!String.IsNullOrEmpty(sourcesFV.Value)) { if (!sourcesFV.Value.Contains(Sources.Facebook)) { sourcesFV.Value = String.Format("{0},{1}", sourcesFV.Value, Sources.Facebook); } } else { sourcesFV.Value = Sources.Facebook; } } // save changes to local storage Folder folder = App.ViewModel.LoadFolder(item.FolderID); StorageHelper.WriteFolder(folder); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Update, Body = new List <Item>() { itemCopy, item }, BodyTypeName = "Item", ID = item.ID }); // TODO: add the zaplify contact header to a special Zaplify Note field // can't find a way to do this currently :-( }
private static void AddContactInfo(ABPerson selectedPerson, Item item) { // find the contact in the address book var book = new AddressBook(); Contact contact = null; if (book.LoadSupported) { contact = book.Load(selectedPerson.Id.ToString()); } else { contact = book.FirstOrDefault(c => c.Id == selectedPerson.Id.ToString()); } if (contact == null) { return; } // make a copy of the item var itemCopy = new Item(item, true); // get more info from the address book var mobile = (from p in contact.Phones where p.Type == Xamarin.Contacts.PhoneType.Mobile select p.Number).FirstOrDefault(); var home = (from p in contact.Phones where p.Type == Xamarin.Contacts.PhoneType.Home select p.Number).FirstOrDefault(); var work = (from p in contact.Phones where p.Type == Xamarin.Contacts.PhoneType.Work select p.Number).FirstOrDefault(); var email = (from em in contact.Emails select em.Address).FirstOrDefault(); //var website = (from w in contact.Websites // select w.Address).FirstOrDefault(); string birthday = null; if (selectedPerson.Birthday != null) { birthday = ((DateTime)selectedPerson.Birthday).ToString("d"); } if (birthday != null) { item.GetFieldValue(FieldNames.Birthday, true).Value = birthday; } if (mobile != null) { item.GetFieldValue(FieldNames.Phone, true).Value = mobile; } if (home != null) { item.GetFieldValue(FieldNames.HomePhone, true).Value = home; } if (work != null) { item.GetFieldValue(FieldNames.WorkPhone, true).Value = work; } if (email != null) { item.GetFieldValue(FieldNames.Email, true).Value = email; } /* * if (website != null) * item.GetFieldValue(FieldNames.Website, true).Value = website */ // save changes to local storage Folder folder = App.ViewModel.LoadFolder(item.FolderID); StorageHelper.WriteFolder(folder); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Update, Body = new List <Item>() { itemCopy, item }, BodyTypeName = "Item", ID = item.ID }); // add the zaplify contact header to a special Zaplify "related name" field // use the native address book because the cross-platform AddressBook class is read-only var ab = new ABAddressBook(); var contactToModify = ab.GetPerson(selectedPerson.Id); /* RelatedNames doesn't work on a real device (iPad) * var relatedNames = contactToModify.GetRelatedNames().ToMutableMultiValue(); * if (relatedNames.Any(name => name.Label == ZaplifyContactHeader)) * { * // remove the existing one (can't figure out a way to get a mutable ABMultiValueEntry out of zapField) * var zapField = relatedNames.Single(name => name.Label == ZaplifyContactHeader); * relatedNames.RemoveAt(relatedNames.GetIndexForIdentifier(zapField.Identifier)); * } * // add the Zaplify related name field with the itemID value * relatedNames.Add(item.ID.ToString(), new MonoTouch.Foundation.NSString(ZaplifyContactHeader)); * contactToModify.SetRelatedNames(relatedNames); */ var zapField = contactToModify.Note; if (zapField == null) { contactToModify.Note = ZaplifyContactHeader + item.ID.ToString(); } else { if (zapField.Contains(ZaplifyContactHeader)) { var idstring = GetContactID(zapField); if (idstring != null) { contactToModify.Note = zapField.Replace(idstring, item.ID.ToString()); } else { contactToModify.Note += String.Format("\n{0}{1}", ZaplifyContactHeader, item.ID.ToString()); } } else { contactToModify.Note += String.Format("\n{0}{1}", ZaplifyContactHeader, item.ID.ToString()); } } // save changes to the address book ab.Save(); }
public ItemRefListPicker(Folder folder, Item currentList, Guid itemTypeID, PropertyInfo pi, object container) { this.ExpansionMode = ExpansionMode.FullScreenOnly; this.SelectionMode = SelectionMode.Multiple; this.SummaryForSelectedItemsDelegate = (list) => { return(CreateCommaDelimitedList(list)); }; // create a list of ItemRefs to all the items in the user's Item collection that match the item type passed in var allRefs = App.ViewModel.Items. Where(it => it.ItemTypeID == itemTypeID && it.IsList == false). Select(it => new Item() { Name = it.Name, FolderID = currentList.FolderID, ItemTypeID = SystemItemTypes.Reference, ParentID = currentList.ID, ItemRef = it.ID }). ToList(); this.ItemsSource = allRefs; this.DisplayMemberPath = "Name"; this.SetValue(ListPicker.SelectedItemsProperty, new List <Item>()); // replace all ItemRefs which are already in the selected list foreach (var itemRef in currentList.Items.ToList()) { bool found = false; for (var i = 0; i < allRefs.Count; i++) { if (allRefs[i].ItemRef == itemRef.ItemRef) { found = true; allRefs[i] = itemRef; this.SelectedItems.Add(itemRef); break; } } // remove item refs that no longer point to a valid contact if (found == false) { currentList.Items.Remove(itemRef); folder.Items.Remove(itemRef); StorageHelper.WriteFolder(folder); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Delete, Body = itemRef }); } } this.SelectionChanged += new SelectionChangedEventHandler((o, ea) => { // if the list doesn't yet exist, create it now if (ea.AddedItems.Count > 0 && currentList.ID == Guid.Empty) { Guid id = Guid.NewGuid(); currentList.ID = id; // fix the pickList's ParentID's to this new list ID (otherwise they stay Guid.Empty) foreach (var i in allRefs) { i.ParentID = id; } // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = currentList }); // add the list to the folder folder.Items.Add(currentList); StorageHelper.WriteFolder(folder); // store the list's Guid in the item's property pi.SetValue(container, id.ToString(), null); } // add all the newly added items foreach (var added in ea.AddedItems) { Item addedItem = added as Item; if (addedItem == null) { continue; } currentList.Items.Add(addedItem); folder.Items.Add(addedItem); StorageHelper.WriteFolder(folder); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = addedItem }); } // remove all the newly removed items foreach (var removed in ea.RemovedItems) { Item removedItem = removed as Item; if (removedItem == null) { continue; } currentList.Items.Remove(removedItem); folder.Items.Remove(removedItem); StorageHelper.WriteFolder(folder); // enqueue the Web Request Record RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Delete, Body = removedItem }); } }); }