/// <summary> /// Delete selected items from phone and watch /// </summary> public async Task DeleteSelectedItems() { int _ConnectionToken = -1; try { //Collect all GUIDs of selected items List <Guid> GuidSelectedItems = new List <Guid>(); var SelectedItems = WatchApps.Where(x => x.Selected); foreach (var SelectedItem in SelectedItems) { GuidSelectedItems.Add(SelectedItem.Model); } //Connect Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance(); _ConnectionToken = await _pc.Connect(_ConnectionToken); //Remove all selected items foreach (var GuidSelectdItem in GuidSelectedItems) { var selecteditem = _pc.WatchItems.Where(x => x.ID == GuidSelectdItem); await _pc.DeleteWatchItemAsync(selecteditem.First()); } //Disconnect if (_pc.IsConnected) { _pc.Disconnect(_ConnectionToken); } } catch (Exception) { Connector.PebbleConnector _pc = Connector.PebbleConnector.GetInstance(); if (_pc.IsConnected) { _pc.Disconnect(_ConnectionToken); } } NotifyPropertyChanged("ItemsSelected"); }
public async void Update(object obj) { UpdateBusy = true; UpdateStatus = "Checking updates"; await WatchApps.CheckUpdates(); await WatchFaces.CheckUpdates(); int i = 0; foreach (var watchitem in WatchApps.WatchApps) { if (watchitem.UpdateAvailable) { i++; } } foreach (var watchitem in WatchFaces.WatchFaces) { if (watchitem.UpdateAvailable) { i++; } } if (i == 0) { UpdateStatus = "No updates available"; } else { UpdateStatus = $"{i} update(s) availables"; } UpdateBusy = false; }
/// <summary> /// Event handler for watch items /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void WatchItemListChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { //Clear all watchfaces case NotifyCollectionChangedAction.Reset: WatchApps.Clear(); AddSportApp(); break; //Add viewmodel WatchFace case NotifyCollectionChangedAction.Add: foreach (IWatchItem item in e.NewItems) { if (item.Type == WatchItemType.WatchApp) { if (item.ID == Guid.Parse(Constants.TennisAppGuid)) { return; } try { var vmExistingWatchFace = WatchApps.Single(x => x.Model == item.ID); WatchApps.Remove(vmExistingWatchFace); } catch (Exception) { }; vmWatchApp _newWatchApp = new vmWatchApp(); _newWatchApp.Name = item.Name; _newWatchApp.Model = item.ID; _newWatchApp.Developer = item.Developer; _newWatchApp.ImageFile = item.File.Replace(".zip", ".gif"); _newWatchApp.Configurable = item.Configurable; _newWatchApp.Item = item; WatchApps.Add(_newWatchApp); LoadImage(_newWatchApp); System.Diagnostics.Debug.WriteLine("vmWatchApps add item: " + item.Name); } } //Sort var SortedApps = WatchApps.OrderBy(x => x.Name).ToList(); WatchApps.Clear(); foreach (var App in SortedApps) { WatchApps.Add(App); } break; //Remove viewmodel WatchFace case NotifyCollectionChangedAction.Remove: foreach (IWatchItem item in e.OldItems) { if (item.Type == WatchItemType.WatchApp) { vmWatchApp element = null; foreach (var WatchApp in WatchApps) { if (WatchApp.Model == item.ID) { element = WatchApp; break; } } try { if (element != null) { WatchApps.Remove(element); } } catch (Exception) { } System.Diagnostics.Debug.WriteLine("vmWatchApps remove item: " + item.Name); } } break; } }