public void EditingEnded (UITextField textField)
		{
			NSIndexPath indexPath = IndexPathForView (textField);

			if (indexPath.Row > 0) {
				// Edit the item in place.
				ListItem item = List[indexPath.Row - 1];

				// If the contents of the text field at the end of editing is the same as it started, don't trigger an update.
				if (item.Text != textField.Text) {
					item.Text = textField.Text;

					TriggerNewDataForWidget ();

					// Notify the document of a change.
					document.UpdateChangeCount (UIDocumentChangeKind.Done);
				}
			} else if (textField.Text.Length > 0) {
				// Adds the item to the top of the list.
				ListItem item = new ListItem (textField.Text);
				int insertedIndex = List.InsertItem (item);

				// Update the edit row to show the check box.
				ListItemCell itemCell = (ListItemCell)TableView.CellAt (indexPath);
				itemCell.CheckBox.Hidden = false;

				// Insert a new add item row into the table view.
				TableView.BeginUpdates ();

				NSIndexPath targetIndexPath = NSIndexPath.FromRowSection (insertedIndex, 0);
				TableView.InsertRows (new NSIndexPath[] { targetIndexPath }, UITableViewRowAnimation.Automatic);

				TableView.EndUpdates ();

				TriggerNewDataForWidget ();

				// Notify the document of a change.
				document.UpdateChangeCount (UIDocumentChangeKind.Done);
			}
		}
Beispiel #2
0
		public int IndexOfItem(ListItem item)
		{
			return items.IndexOf (item);
		}
		void ConfigureListItemCell(CheckBoxCell itemCell, ListColor color, ListItem item)
		{
			itemCell.CheckBox.TintColor = AppColors.ColorFrom(color);
			itemCell.CheckBox.Checked = item.IsComplete;
			itemCell.Label.Text = item.Text;

			itemCell.Label.TextColor = UIColor.White;

			// Configure a completed list item cell.
			if (item.IsComplete)
				itemCell.Label.TextColor = UIColor.LightGray;
		}
Beispiel #4
0
		public ListOperationInfo MoveItem(ListItem item, int toIndex)
		{
			int fromIndex = items.IndexOf (item);

			if (fromIndex == -1)
				throw new InvalidProgramException ("Moving an item that isn't in the list is undefined.");

			items.RemoveAt (fromIndex);

			int normalizedToIndex = toIndex;

			if (fromIndex < toIndex)
				normalizedToIndex--;

			items.Insert (normalizedToIndex, item);

			var moveInfo = new ListOperationInfo {
				FromIndex = fromIndex,
				ToIndex = normalizedToIndex
			};

			return moveInfo;
		}
Beispiel #5
0
		// Toggles an item's completion state and moves the item to the appropriate index. The normalized from/to indexes are returned in the ListOperationInfo struct.
		public ListOperationInfo ToggleItem(ListItem item, int preferredDestinationIndex)
		{
			int fromIndex = items.IndexOf (item);

			if (fromIndex == -1)
				throw new InvalidProgramException ("Toggling an item that isn't in the list is undefined.");

			items.RemoveAt (fromIndex);

			item.IsComplete = !item.IsComplete;

			int toIndex = preferredDestinationIndex;

			if (toIndex == -1)
				toIndex = item.IsComplete ? Count : IndexOfFirstCompletedItem();

			items.Insert (toIndex, item);

			var toggleInfo = new ListOperationInfo {
				FromIndex = fromIndex,
				ToIndex = toIndex
			};

			return toggleInfo;
		}
Beispiel #6
0
		public bool CanMoveItem(ListItem item, int index, bool inclusive)
		{
			int fromIndex = items.IndexOf (item);

			if (fromIndex == -1)
				return false;

			if (item.IsComplete)
				return index <= Count && index >= IndexOfFirstCompletedItem ();
			else if (inclusive)
				return index >= 0 && index <= IndexOfFirstCompletedItem ();
			else
				return index >= 0 && index < IndexOfFirstCompletedItem ();
		}
Beispiel #7
0
		public int InsertItem(ListItem item)
		{
			if (item.IsComplete) {
				items.Add (item);
				return items.Count - 1;
			} else {
				items.Insert (0, item);
				return 0;
			}
		}
Beispiel #8
0
		public void InsertItem(ListItem item, int index)
		{
			items.Insert (index, item);
		}
Beispiel #9
0
 public int IndexOfItem(ListItem item)
 {
     return(items.IndexOf(item));
 }
Beispiel #10
0
 public void InsertItem(ListItem item, int index)
 {
     items.Insert(index, item);
 }