// Configures the table view and initializes view elements.
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			TableView.EstimatedRowHeight = 44;
			TableView.RowHeight = UITableView.AutomaticDimension;

			selectedRoom = Accessory.Room ?? Home.GetRoomForEntireHome ();

			// If the accessory belongs to the home already, we are in 'edit' mode.
			editingExistingAccessory = AccessoryHasBeenAddedToHome ();

			// Show 'save' instead of 'add.'
			// If we're not editing an existing accessory, then let the back button show in the left.
			if (editingExistingAccessory)
				AddButton.Title = "Save";
			else
				NavigationItem.LeftBarButtonItem = null;

			// Put the accessory's name in the 'name' field.
			ResetNameField ();

			// Register a cell for the rooms.
			TableView.RegisterClassForCellReuse (typeof(UITableViewCell), RoomCell);
		}
Example #2
0
 public void DidRemoveRoomFromZone(HMHome home, HMRoom room, HMZone zone)
 {
     if (zone == HomeZone)
     {
         DidRemoveRoom(room);
     }
 }
Example #3
0
 public void DidRemoveRoom(HMHome home, HMRoom room)
 {
     if (room == Room)
     {
         NavigationController.PopViewController(true);
     }
 }
Example #4
0
 public void DidUpdateNameForRoom(HMHome home, HMRoom room)
 {
     if (room == Room)
     {
         NavigationItem.Title = room.Name;
     }
 }
        public NSIndexPath Remove(HMRoom room)
        {
            var indexPath = IndexPathOfObject(room);

            Rooms.RemoveAt(indexPath.Row);
            return(indexPath);
        }
Example #6
0
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            tableView.DeselectRow(indexPath, true);

            switch ((AddAccessoryTableViewSection)indexPath.Section)
            {
            case AddAccessoryTableViewSection.Rooms:
                if (!Home.IsAdmin())
                {
                    return;
                }
                selectedRoom = Home.GetAllRooms() [indexPath.Row];

                var sections = NSIndexSet.FromIndex((nint)(int)AddAccessoryTableViewSection.Rooms);
                tableView.ReloadSections(sections, UITableViewRowAnimation.Automatic);
                break;

            case AddAccessoryTableViewSection.Identify:
                IdentifyAccessory();
                break;

            case AddAccessoryTableViewSection.Name:
                break;

            default:
                throw new InvalidOperationException("Unexpected `AddAccessoryTableViewSection` value.");
            }
        }
Example #7
0
 public void DidAddRoomToZone(HMHome home, HMRoom room, HMZone zone)
 {
     if (zone == HomeZone)
     {
         DidAddRoom(room);
     }
 }
Example #8
0
        // Configures the table view and initializes view elements.
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            TableView.EstimatedRowHeight = 44;
            TableView.RowHeight          = UITableView.AutomaticDimension;

            selectedRoom = Accessory.Room ?? Home.GetRoomForEntireHome();

            // If the accessory belongs to the home already, we are in 'edit' mode.
            editingExistingAccessory = AccessoryHasBeenAddedToHome();

            // Show 'save' instead of 'add.'
            // If we're not editing an existing accessory, then let the back button show in the left.
            if (editingExistingAccessory)
            {
                AddButton.Title = "Save";
            }
            else
            {
                NavigationItem.LeftBarButtonItem = null;
            }

            // Put the accessory's name in the 'name' field.
            ResetNameField();

            // Register a cell for the rooms.
            TableView.RegisterClassForCellReuse(typeof(UITableViewCell), RoomCell);
        }
		// returns:  All rooms in the home, including `roomForEntireHome`.
		public static HMRoom[] GetAllRooms (this HMHome self)
		{
			var rooms = self.Rooms;
			var allRooms = new HMRoom[rooms.Length + 1];
			Array.Copy (rooms, allRooms, rooms.Length);
			allRooms [rooms.Length] = self.GetRoomForEntireHome ();
			return allRooms;
		}
Example #10
0
        // returns:  All rooms in the home, including `roomForEntireHome`.
        public static HMRoom[] GetAllRooms(this HMHome self)
        {
            var rooms    = self.Rooms;
            var allRooms = new HMRoom[rooms.Length + 1];

            Array.Copy(rooms, allRooms, rooms.Length);
            allRooms [rooms.Length] = self.GetRoomForEntireHome();
            return(allRooms);
        }
Example #11
0
 public void DidRemoveRoom(HMHome home, HMRoom room)
 {
     // Reset the selected room if ours was deleted.
     if (selectedRoom == room)
     {
         selectedRoom = HomeStore.Home.GetRoomForEntireHome();
     }
     TableView.ReloadData();
 }
Example #12
0
 async void TryRemove(HMRoom room)
 {
     try {
         await Home.RemoveRoomAsync(room);
     } catch (NSErrorException ex) {
         DisplayError(ex.Error);
         Add(room);
     }
 }
Example #13
0
        async void AddRoomWithName(string roomName)
        {
            try {
                HMRoom room = await Home.AddRoomAsync(roomName);

                Add(room);
            } catch (NSErrorException ex) {
                DisplayError(ex.Error);
            }
        }
Example #14
0
        // Reloads the cell corresponding a given room.
        void DidUpdateRoom(HMRoom room)
        {
            var roomIndex = rooms.IndexOf(room);

            if (roomIndex >= 0)
            {
                var roomIndexPath = NSIndexPath.FromRowSection(roomIndex, 0);
                TableView.ReloadRows(new [] { roomIndexPath }, UITableViewRowAnimation.Automatic);
            }
        }
Example #15
0
 public void DidUpdateRoom(HMHome home, HMRoom room, HMAccessory accessory)
 {
     if (room == Room)
     {
         DidAssignAccessory(accessory);
     }
     else if (Accessories.Contains(accessory))
     {
         DidUnassignAccessory(accessory);
     }
 }
Example #16
0
 // Removes a room from HomeKit and updates the view.
 void RemoveRoom(HMRoom room)
 {
     DidRemoveRoom(room);
     HomeZone.RemoveRoom(room, error => {
         if (error != null)
         {
             DisplayError(error);
             DidAddRoom(room);
         }
     });
 }
Example #17
0
        // Removes a room from the internal array of rooms and deletes the row from the table view.
        void DidRemoveRoom(HMRoom room)
        {
            var roomIndex = rooms.IndexOf(room);

            if (roomIndex >= 0)
            {
                rooms.RemoveAtIndex(roomIndex);
                var roomIndexPath = NSIndexPath.FromRowSection(roomIndex, 0);
                TableView.DeleteRows(new [] { roomIndexPath }, UITableViewRowAnimation.Automatic);
            }

            ReloadAddIndexPath();
        }
Example #18
0
        // Adds a room to the internal array of rooms and inserts new row into the table view.
        void DidAddRoom(HMRoom room)
        {
            rooms.Add(room);
            SortRooms();

            var newRoomIndex = rooms.IndexOf(room);

            if (newRoomIndex >= 0)
            {
                var newRoomIndexPath = NSIndexPath.FromRowSection(newRoomIndex, 0);
                TableView.InsertRows(new [] { newRoomIndexPath }, UITableViewRowAnimation.Automatic);
            }

            ReloadAddIndexPath();
        }
Example #19
0
        // Assigns the given accessory to the provided room. This method will enter and leave the saved dispatch group.
        void AssignAccessory(HMHome home, HMAccessory accessory, HMRoom room)
        {
            if (accessory.Room == room)
            {
                return;
            }

            saveAccessoryGroup.Enter();
            home.AssignAccessory(accessory, room, error => {
                if (error != null)
                {
                    DisplayError(error);
                    didEncounterError = true;
                }
                saveAccessoryGroup.Leave();
            });
        }
        public NSIndexPath IndexPathOfObject(HMRoom room)
        {
            var index = Rooms.IndexOf(room);

            return(index < 0 ? null : BuildIndexPath(index, HomeKitObjectSection.Room));
        }
Example #21
0
 public void DidUpdateNameForRoom(HMHome home, HMRoom room)
 {
     DidUpdateRoom(room);
 }
		public NSIndexPath IndexPathOfObject (HMRoom room)
		{
			var index = Rooms.IndexOf (room);
			return index < 0 ? null : BuildIndexPath (index, HomeKitObjectSection.Room);
		}
Example #23
0
 public void DidAddRoom(HMHome home, HMRoom room)
 {
     ReloadAddIndexPath();
 }
Example #24
0
 public void DidRemoveRoom(HMHome home, HMRoom room)
 {
     DidRemoveRoom(room);
 }
		public void DidRemoveRoom (HMHome home, HMRoom room)
		{
			DeleteRowAt (ObjectCollection.Remove (room));
		}
		public void DidRemoveRoom (HMHome home, HMRoom room)
		{
			DidRemoveRoom (room);
		}
		// Reloads the cell corresponding a given room.
		void DidUpdateRoom (HMRoom room)
		{
			var roomIndex = rooms.IndexOf (room);
			if (roomIndex >= 0) {
				var roomIndexPath = NSIndexPath.FromRowSection (roomIndex, 0);
				TableView.ReloadRows (new []{ roomIndexPath }, UITableViewRowAnimation.Automatic);
			}
		}
		public void DidAddRoom (HMHome home, HMRoom room)
		{
			Add (room);
		}
		public void DidUpdateNameForRoom (HMHome home, HMRoom room)
		{
			DidUpdateRoom (room);
		}
		// Assigns the given accessory to the provided room. This method will enter and leave the saved dispatch group.
		void AssignAccessory (HMHome home, HMAccessory accessory, HMRoom room)
		{
			if (accessory.Room == room)
				return;

			saveAccessoryGroup.Enter ();
			home.AssignAccessory (accessory, room, error => {
				if (error != null) {
					DisplayError (error);
					didEncounterError = true;
				}
				saveAccessoryGroup.Leave ();
			});
		}
		public void DidRemoveRoomFromZone (HMHome home, HMRoom room, HMZone zone)
		{
			if (zone == HomeZone)
				DidRemoveRoom (room);
		}
		public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
		{
			tableView.DeselectRow (indexPath, true);

			switch ((AddAccessoryTableViewSection)indexPath.Section) {
			case AddAccessoryTableViewSection.Rooms:
				if (!Home.IsAdmin ())
					return;
				selectedRoom = Home.GetAllRooms () [indexPath.Row];

				var sections = NSIndexSet.FromIndex ((nint)(int)AddAccessoryTableViewSection.Rooms);
				tableView.ReloadSections (sections, UITableViewRowAnimation.Automatic);
				break;
			case AddAccessoryTableViewSection.Identify:
				IdentifyAccessory ();
				break;
			case AddAccessoryTableViewSection.Name:
				break;
			default:
				throw new InvalidOperationException ("Unexpected `AddAccessoryTableViewSection` value.");
			}
		}
Example #33
0
 public void DidUpdateNameForRoom(HMHome home, HMRoom room)
 {
     TableView.ReloadData();
 }
		public void DidUpdateNameForRoom (HMHome home, HMRoom room)
		{
			TableView.ReloadData ();
		}
		public void DidAddRoom (HMHome home, HMRoom room)
		{
			TableView.ReloadData ();
		}
		public void DidRemoveRoom (HMHome home, HMRoom room)
		{
			// Reset the selected room if ours was deleted.
			if (selectedRoom == room)
				selectedRoom = HomeStore.Home.GetRoomForEntireHome ();
			TableView.ReloadData ();
		}
Example #37
0
 void Add(HMRoom room)
 {
     InsertRowAt(ObjectCollection.Add(room));
 }
		void Add (HMRoom room)
		{
			InsertRowAt (ObjectCollection.Add (room));
		}
		public NSIndexPath Remove (HMRoom room)
		{
			var indexPath = IndexPathOfObject (room);
			Rooms.RemoveAt (indexPath.Row);
			return indexPath;
		}
		public void DidUpdateNameForRoom (HMHome home, HMRoom room)
		{
			ResetDisplayedRooms ();
		}
		public NSIndexPath Add (HMRoom room)
		{
			Rooms.Add (room);
			Rooms.SortByLocalizedName (r => r.Name);
			return IndexPathOfObject (room);
		}
		public void DidRemoveRoom (HMHome home, HMRoom room)
		{
			ResetDisplayedRooms ();
		}
 public NSIndexPath Add(HMRoom room)
 {
     Rooms.Add(room);
     Rooms.SortByLocalizedName(r => r.Name);
     return(IndexPathOfObject(room));
 }
		public void DidAddRoomToZone (HMHome home, HMRoom room, HMZone zone)
		{
			ResetDisplayedRooms ();
		}
		// Removes a room from the internal array of rooms and deletes the row from the table view.
		void DidRemoveRoom (HMRoom room)
		{
			var roomIndex = rooms.IndexOf (room);
			if (roomIndex >= 0) {
				rooms.RemoveAtIndex (roomIndex);
				var roomIndexPath = NSIndexPath.FromRowSection (roomIndex, 0);
				TableView.DeleteRows (new []{ roomIndexPath }, UITableViewRowAnimation.Automatic);
			}

			ReloadAddIndexPath ();
		}
		public void DidRemoveRoomFromZone (HMHome home, HMRoom room, HMZone zone)
		{
			ResetDisplayedRooms ();
		}
		// Removes a room from HomeKit and updates the view.
		void RemoveRoom (HMRoom room)
		{
			DidRemoveRoom (room);
			HomeZone.RemoveRoom (room, error => {
				if (error != null) {
					DisplayError (error);
					DidAddRoom (room);
				}
			});
		}
 public void DidAddRoomToZone(HMHome home, HMRoom room, HMZone zone)
 {
     ResetDisplayedRooms();
 }
		public void DidAddRoom (HMHome home, HMRoom room)
		{
			ReloadAddIndexPath ();
		}
		public void DidRemoveRoom (HMHome home, HMRoom room)
		{
			if (room == Room)
				NavigationController.PopViewController (true);
		}
		public void DidAddRoomToZone (HMHome home, HMRoom room, HMZone zone)
		{
			if (zone == HomeZone)
				DidAddRoom (room);
		}
		public void DidUpdateNameForRoom (HMHome home, HMRoom room)
		{
			if (room == Room)
				NavigationItem.Title = room.Name;
		}
		// Adds a room to the internal array of rooms and inserts new row into the table view.
		void DidAddRoom (HMRoom room)
		{
			rooms.Add (room);
			SortRooms ();

			var newRoomIndex = rooms.IndexOf (room);
			if (newRoomIndex >= 0) {
				var newRoomIndexPath = NSIndexPath.FromRowSection (newRoomIndex, 0);
				TableView.InsertRows (new []{ newRoomIndexPath }, UITableViewRowAnimation.Automatic);
			}

			ReloadAddIndexPath ();
		}
Example #54
0
 public void DidAddRoom(HMHome home, HMRoom room)
 {
     Add(room);
 }
 public void DidRemoveRoomFromZone(HMHome home, HMRoom room, HMZone zone)
 {
     ResetDisplayedRooms();
 }
Example #56
0
 public void DidRemoveRoom(HMHome home, HMRoom room)
 {
     DeleteRowAt(ObjectCollection.Remove(room));
 }
Example #57
0
 public void DidAddRoom(HMHome home, HMRoom room)
 {
     TableView.ReloadData();
 }
Example #58
0
 public void DidUpdateNameForRoom(HMHome home, HMRoom room)
 {
     ReloadRowAt(ObjectCollection.IndexPathOfObject(room));
 }
		public void DidUpdateRoom (HMHome home, HMRoom room, HMAccessory accessory)
		{
			if (room == Room)
				DidAssignAccessory (accessory);
			else if (Accessories.Contains (accessory))
				DidUnassignAccessory (accessory);
		}
		public void DidUpdateNameForRoom (HMHome home, HMRoom room)
		{
			ReloadRowAt (ObjectCollection.IndexPathOfObject (room));
		}