Пример #1
0
        private async void LoadVideos(string userId, string channelId)
        {
            List <SearchResult> filmiki;

            var muchos = await _ytManager.GetChannelIdForUserAsync(userId);

            if (!ReferenceEquals(muchos, null))
            {
                filmiki = await _ytManager.GetVideosFromChannelAsync(muchos);
            }
            else
            {
                filmiki = await _ytManager.GetVideosFromChannelAsync(channelId);
            }

            if (ReferenceEquals(filmiki, null))
            {
                return;
            }



            // New colletion
            YtVideos.Clear();

            List <YTVideo> xx = new List <YTVideo>();

            Random rnd = new Random();

            foreach (SearchResult searchResult in filmiki)
            {
                var tmpobj = new YTVideo()
                {
                    videoId            = searchResult.Id.VideoId,
                    channelId          = searchResult.Snippet.ChannelId,
                    publishDdate       = searchResult.Snippet.PublishedAt ?? new DateTime(1900, 1, 1),
                    title              = searchResult.Snippet.Title,
                    thumbnail          = searchResult.Snippet.Thumbnails.Default__?.Url ?? "empty",
                    description        = searchResult.Snippet.Description,
                    rating             = rnd.Next(0, 5),  // creates a number between 1 and 6
                    isAvailableOffline = true,
                    category           = "default"
                };

                YtVideos.Add(tmpobj);
            }
        }
Пример #2
0
        /// <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();
        }