public void AddUpdate(StoredChannel item, NotificationSetting setting = null) { bool exists = Exists(item.ChannelId); if (!exists) { Channels.Add(item); if (setting == null) { setting = new NotificationSetting(item.ChannelId); Save(setting); } Settings.Add(setting); Save(item); } else { int index = FindIndexOfChannelId(item.ChannelId); Channels[index] = item; Update(item); if (setting != null) { int settingIndex = FindIndexOfSettingId(item.ChannelId); Settings[settingIndex] = setting; Update(setting); } } }
private void Update(StoredChannel channel) { lock (CollisionLock) { DbConnection.UpdateAsync(channel); } }
private void Save(StoredChannel channel) { lock (CollisionLock) { DbConnection.InsertAsync(channel); } }
private void SetupSubscribes() { MessagingCenter.Subscribe <ChannelsAddRemoveEvent>(this, EVENT_ADDREMOVE, (addRemoveEvent) => { string channelId = addRemoveEvent.Id; if (addRemoveEvent.Add) { StoredChannel channel = App.ChannelsDatastore.Get(channelId); Channels.Add(channel); GetChannelActivity(channel, false); } else { var channel = Channels.First(c => c.ChannelId == channelId); if (channel != null) { Channels.Remove(channel); } if (App.ChannelsDatastore.Exists(channel.ChannelId)) { App.ChannelsDatastore.Delete(channel.ChannelId); } } }); }
void Handle_ItemTapped(object sender, Xamarin.Forms.ItemTappedEventArgs e) { StoredChannel item = (StoredChannel)e.Item; NotificationSetting settings = App.ChannelsDatastore.GetSetting(item.ChannelId); NotificationSettings notificationSettingsView = new NotificationSettings(settings); Navigation.PushModalAsync(notificationSettingsView); }
public bool Delete(string id) { StoredChannel channel = Get(id); Channels.Remove(channel); NotificationSetting setting = Settings.First(c => channel.ChannelId == id); Settings.Remove(setting); DeleteChannel(channel.ChannelId); DeleteSetting(channel.ChannelId); return(true); }
private void OnActivityReceive(ChannelActivityEvent activityEvent) { StoredChannel channel = Channels.First(c => c.ChannelId == activityEvent.ChannelId); YoutubeActivity latest = activityEvent.Result.items.OrderByDescending(act => act.Snippet.PublishedAt).First(); channel.NewVideo = channel.LastVideoId == null || !channel.LastVideoId.Equals(latest.VideoId); channel.LastVideoId = latest.VideoId; channel.LastVideoImageLink = latest.ImageLink; channel.LastVideoTitle = latest.Snippet.Title; channel.LastVideoTime = latest.Snippet.PublishedAt.ToShortDateString() + " " + latest.Snippet.PublishedAt.ToShortTimeString(); channel.Activity = latest; channel.Searching = false; App.ChannelsDatastore.AddUpdate(channel); }
private void GetChannelActivity(StoredChannel channel, bool force) { IYoutube api = new YoutubeApi(); channel.Searching = true; if (channel.Activity == null || force) { Task.Run(() => { Task <YoutubeCall <YoutubeActivity> > result = Task.Run(() => api.GetChannelActivity(channel.ChannelId)); var webResult = result.Result; OnActivityReceive(new ChannelActivityEvent(channel.ChannelId, webResult)); }); } }
public StoredChannel Get(string id) { StoredChannel channel = Channels.Find(chan => chan.ChannelId == id); return(channel); }