コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
 private void Update(StoredChannel channel)
 {
     lock (CollisionLock)
     {
         DbConnection.UpdateAsync(channel);
     }
 }
コード例 #3
0
 private void Save(StoredChannel channel)
 {
     lock (CollisionLock)
     {
         DbConnection.InsertAsync(channel);
     }
 }
コード例 #4
0
 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);
             }
         }
     });
 }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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));
                });
            }
        }
コード例 #9
0
        public StoredChannel Get(string id)
        {
            StoredChannel channel = Channels.Find(chan => chan.ChannelId == id);

            return(channel);
        }