private void AddButton_Click(object sender, EventArgs e) { // determine which button was clicked Button clickedButton = sender as Button ?? AddButtons[0][0]; int listIndex = buttonList.IndexOf(clickedButton); ClientEntity entity = lists[listIndex]; if (entity is Item) { var list = entity as Item; Folder folder = App.ViewModel.Folders.Single(f => f.ID == list.FolderID); AddItem(folder, list); } if (entity is Folder) { var folder = entity as Folder; AddItem(folder, null); } // increment the SelectedCount ListMetadataHelper.IncrementListSelectedCount(App.ViewModel.PhoneClientFolder, entity); // if this is a navigation and not an add operation, we need to sync with the service to push the new selected count // (do not sync for operations against $ClientSettings) //if (String.IsNullOrWhiteSpace(Name.Value)) // App.ViewModel.SyncWithService(); }
public List<Item> GetListsOrderedBySelectedCount() { var lists = ListMetadataHelper.GetListsOrderedBySelectedCount(PhoneClientFolder); // if there are no lists with a selected count, create one for each default list if (lists.Count == 0) { // give the task and shopping item lists a count of 2 var task = GetDefaultList(SystemItemTypes.Task); if (task != null) { ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, task); ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, task); } var grocery = GetDefaultList(SystemItemTypes.Grocery); if (grocery != null) { ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, grocery); ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, grocery); } // give the contact and location lists a count of 1 var contact = GetDefaultList(SystemItemTypes.Contact); if (contact != null) ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, contact); var location = GetDefaultList(SystemItemTypes.Location); if (location != null) ListMetadataHelper.IncrementListSelectedCount(PhoneClientFolder, location); // re-retrieve selected count lists lists = ListMetadataHelper.GetListsOrderedBySelectedCount(PhoneClientFolder); } return lists; }
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); } } }; }