コード例 #1
0
        public DialogEditChannelViewModel()
        {
            this.useHoldingBay = true;

            _holdingBay = ContainerHelper.GetService <IHoldingBay>();

            NewYtChannel = (YTChannel)_holdingBay.GetEntry("CHANNEL_NEW", false); // do not remove object from our repo
        }
コード例 #2
0
ファイル: YupRepository.cs プロジェクト: rezasurmar/YUP
        /// <summary>
        /// Adds new youtube channel to our repository
        /// </summary>
        /// <param name="channel">Defined youtube channel</param>
        public void AddChannel(YTChannel channel)
        {
            if (ReferenceEquals(channel, null))
            {
                return;
            }

            appRepo.ytChannels.Add(channel);

            _eventBus.RaiseEvent(EventOnBus.channelAdded, this, new EventBusArgs()
            {
                Item = channel
            });
        }
コード例 #3
0
ファイル: ChannelsViewModel.cs プロジェクト: rezasurmar/YUP
        /// <summary>
        /// Handler executed when CardEditmd command is invoked
        /// </summary>
        private async void OnCardEdited()
        {
            if (ReferenceEquals(_selectedYtChannel, null))
            {
                return;
            }

            // Create a copy if we would cancel our edit
            var channelBackup = Activator.CreateInstance <YTChannel>();
            var fields        = channelBackup.GetType().GetFields(BindingFlags.Public
                                                                  | BindingFlags.Instance);

            foreach (var field in fields)
            {
                var value = field.GetValue(_selectedYtChannel);
                field.SetValue(channelBackup, value);
            }

            //let's set up a little MVVM, cos that's what the cool kids are doing:
            var view = new DialogEditChannel()
            {
                DataContext = new DialogEditChannelViewModel(_selectedYtChannel)
            };

            //show the dialog
            bool result = (bool)await DialogHost.Show(view, "RootDialog");

            // User cliked cancel - so we dont edit this channel
            if (!result)
            {
                _selectedYtChannel = channelBackup;
                return;
            }

            // Save change in our repository
            _yupRepository.SaveRepository();

            // Fire up event that we had a channel modification
            _eventBus.RaiseEvent(EventOnBus.channelEdited, this, new EventBusArgs()
            {
                Item = _selectedYtChannel
            });

            // Clean up searchbox terms
            _searchBoxTerm = "";
            SearchBoxTerm  = "";
        }
コード例 #4
0
ファイル: ChannelsViewModel.cs プロジェクト: rezasurmar/YUP
        /// <summary>
        /// Method responsible for filtering based on username
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FilterChannels(object sender, FilterEventArgs e)
        {
            YTChannel svm = (YTChannel)e.Item;

            if (string.IsNullOrWhiteSpace(this.SearchBoxTerm) || this.SearchBoxTerm.Length == 0 || this.SearchBoxTerm.Length < 3)
            {
                e.Accepted = true;
            }
            else
            {
                if (!ReferenceEquals(svm.user, null))
                {
                    e.Accepted = (svm.friendlyName.IndexOf(SearchBoxTerm, StringComparison.OrdinalIgnoreCase)) >= 0 || (svm.user.IndexOf(SearchBoxTerm, StringComparison.OrdinalIgnoreCase)) >= 0 || (svm.description.IndexOf(SearchBoxTerm, StringComparison.OrdinalIgnoreCase)) >= 0;
                }
                else
                {
                    e.Accepted = true;
                }
            }
        }
コード例 #5
0
ファイル: YupRepository.cs プロジェクト: rezasurmar/YUP
 public void Editchannel(YTChannel channel)
 {
     //TODO ? Do we need to edit channels ?
 }
コード例 #6
0
ファイル: ChannelsViewModel.cs プロジェクト: rezasurmar/YUP
        /// <summary>
        /// Handler executed when SearchBoxCmd command is invoked
        /// </summary>
        private async void OnSearchBoxCmd()
        {
            // If we dont have anything we skip actions :)
            if (string.IsNullOrWhiteSpace(SearchBoxTerm))
            {
                return;
            }

            string  tmpChannelID;
            Channel tmpChannelStats = null;

            if (IsUrl(SearchBoxTerm))
            {
                tmpChannelID = _ytManager.GetChannelIdFromUrl(SearchBoxTerm);

                if (tmpChannelID != null)
                {
                    tmpChannelStats = _ytManager.GetChannelStatistcsByChannelId(tmpChannelID);
                }
            }
            else
            {
                tmpChannelID = await _ytManager.GetChannelIdForUserAsync(SearchBoxTerm);

                if (tmpChannelID != null)
                {
                    tmpChannelStats = _ytManager.GetChannelStatistcsByUser(SearchBoxTerm);
                }
            }

            // bail out if we have not found anything
            if (tmpChannelStats == null)
            {
                return;
            }



            var chann = new YTChannel()
            {
                description =
                    $"{tmpChannelStats.Snippet.Description.Substring(0, tmpChannelStats.Snippet.Description.Length < 100 ? tmpChannelStats.Snippet.Description.Length : 100).Trim()} ...",
                thumbnail = tmpChannelStats.Snippet.Thumbnails.High.Url,
                channelId = tmpChannelStats.Id,
                user      = tmpChannelStats.Snippet.Title
            };

            /*
             *  At this stage we have channel so we can push it into our holding bay.
             *  Probably there is a better way to do it - just havent discovered it yet :)
             */
            _holdingbay.AddEntry("CHANNEL_NEW", chann);

            //let's set up a little MVVM, cos that's what the cool kids are doing:
            var view = new DialogEditChannel()
            {
                DataContext = new DialogEditChannelViewModel()
            };

            //show the dialog
            bool result = (bool)await DialogHost.Show(view, "RootDialog");

            if (!result)
            {
                return;             // User cliked cancel - so we dont add this channel
            }
            chann = (YTChannel)_holdingbay.GetEntry("CHANNEL_NEW");

            _yupRepository.AddChannel(chann);
            _yupRepository.SaveRepository();

            YtChannels.Add(chann);

            _eventBus.RaiseEvent(EventOnBus.channelAdded, this, new EventBusArgs()
            {
                Item = chann
            });

            // Clean up searchbox terms
            _searchBoxTerm = "";
            SearchBoxTerm  = "";
            this.OnFilterChanged();
        }
コード例 #7
0
 public DialogEditChannelViewModel(YTChannel newYtChannel)
 {
     NewYtChannel = newYtChannel;
 }