public IceCreamsViewController(IntPtr handle) : base(handle) { var history = IceCreamHistory.Load(); items = history.Reverse() .Select(s => KeyValue(CollectionViewItem.IceCream, s)) .ToList(); items.Insert(0, KeyValue(CollectionViewItem.Create, (IceCream)null)); }
public void Build(BuildIceCreamViewController controller, IceCreamPart iceCreamPart) { var conversation = ActiveConversation; if (conversation == null) { throw new Exception("Expected a conversation"); } var iceCream = controller.IceCream; if (iceCream == null) { throw new Exception("Expected the controller to be displaying an ice cream"); } string messageCaption = string.Empty; var b = iceCreamPart as Base; var s = iceCreamPart as Scoops; var t = iceCreamPart as Topping; if (b != null) { iceCream.Base = b; messageCaption = "Let's build an ice cream"; } else if (s != null) { iceCream.Scoops = s; messageCaption = "I added some scoops"; } else if (t != null) { iceCream.Topping = t; messageCaption = "Our finished ice cream"; } else { throw new Exception("Unexpected type of ice cream part selected."); } // Create a new message with the same session as any currently selected message. var message = ComposeMessage(iceCream, messageCaption, conversation.SelectedMessage?.Session); // Add the message to the conversation. conversation.InsertMessage(message, null); // If the ice cream is complete, save it in the history. if (iceCream.IsComplete) { var history = IceCreamHistory.Load(); history.Append(iceCream); history.Save(); } Dismiss(); }
public static IceCreamHistory Load() { var iceCreams = GetSavedIceCreams().Select(sic => { var components = NSUrlComponents.FromUrl(new NSUrl(sic), false); return(new IceCream(components.QueryItems)); }).ToList(); if (iceCreams.Count == 0) { iceCreams.Add(new IceCream(BaseType.base01, ScoopsType.scoops05, ToppingType.topping09)); iceCreams.Add(new IceCream(BaseType.base03, ScoopsType.scoops07, ToppingType.topping01)); iceCreams.Add(new IceCream(BaseType.base04, ScoopsType.scoops08, ToppingType.topping07)); iceCreams.Add(new IceCream(BaseType.base02, ScoopsType.scoops03, ToppingType.topping10)); iceCreams.Add(new IceCream(BaseType.base01, ScoopsType.scoops01, ToppingType.topping05)); var historyToSave = new IceCreamHistory(iceCreams); historyToSave.Save(); } return(new IceCreamHistory(iceCreams)); }