public TimingDetailPage() { ReaderWriterLockSlim locker = new ReaderWriterLockSlim(); IDictionary <IBoat, DateTime> times = new Dictionary <IBoat, DateTime>(); Action updateTitle = () => { var u = times.Count(t => t.Key.Number <= 0); var i = times.Count(t => t.Key.Number > 0 && t.Value > DateTime.MinValue); if (TitleUpdated != null) { TitleUpdated(this, new StringEventArgs(string.Format(" - to save: {0} identified, {1} unidentified", i, u))); } }; Action saveBoats = () => { TimingItemManager manager = (TimingItemManager)BindingContext; try { locker.EnterWriteLock(); manager.SaveBoat(times.Where(kvp => kvp.Value > DateTime.MinValue).Select(t => new Tuple <IBoat, DateTime, string>(t.Key, t.Value, string.Empty))); times.Clear(); updateTitle(); } finally { locker.ExitWriteLock(); } }; Action <IBoat, bool> flipflop = (IBoat boat, bool seen) => { try { locker.EnterWriteLock(); boat.Seen = seen; if (times.ContainsKey(boat)) { times.Remove(boat); } times.Add(boat, seen ? DateTime.Now : DateTime.MinValue); updateTitle(); } finally { locker.ExitWriteLock(); } }; Action unidentified = () => { flipflop(((TimingItemManager)BindingContext).UnidentifiedBoat, true); }; // var anchor = new ToolbarItem("Anchor", "Anchor.png", () => Debug.WriteLine("anchor"), priority: 3); var plus = new ToolbarItem("Add", "Add.png", () => unidentified(), priority: 3); var sync = new ToolbarItem("Sync", "Syncing.png", saveBoats, priority: 2); ToolbarItem more = null; Action refreshToolbar = () => { ToolbarItems.Clear(); ToolbarItems.Add(plus); ToolbarItems.Add(sync); ToolbarItems.Add(more); }; more = new ToolbarItem("More", "More.png", refreshToolbar, priority: 1); refreshToolbar(); var listView = new ListView(); listView.SetBinding(ListView.ItemsSourceProperty, "Unfinished"); Action <IBoat> press = async(IBoat boat) => { string pin = "Pin to top"; string send = "Send to End"; var sheet = await DisplayActionSheet(string.Format("Boat {0}: Send to ... ?", boat.Number), "Cancel", null, pin, send); if (sheet == pin) { ToolbarItem item = null; Action action = () => { flipflop(boat, true); ToolbarItems.Remove(item); }; item = new ToolbarItem(boat.Number.ToString(), null, action, priority: -1); ToolbarItems.Add(item); } if (sheet == send) { boat.End = true; } Debug.WriteLine("Action: " + sheet); }; listView.ItemTemplate = new DataTemplate(() => new UnseenCell(press)); listView.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => { Debug.WriteLine("underlying change"); }; listView.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => { if (e.SelectedItem == null) { return; } IBoat boat = (IBoat)e.SelectedItem; flipflop(boat, !boat.Seen); listView.SelectedItem = null; }; SearchBar searchBar = new SearchBar { Placeholder = "Filter list", }; searchBar.TextChanged += (object sender, TextChangedEventArgs e) => { TimingItemManager manager = (TimingItemManager)BindingContext; manager.Filter(searchBar.Text); }; Content = new StackLayout() { Children = { searchBar, listView } }; // idea: hide a non-starter }
public void AddItem(TimingItem item) { _timingItemManager.SaveBoat(null); // (item); _popover.UpdateStatus(_timingItemManager.Status); PopulateTable(false); }