コード例 #1
0
        public void OldRequestIsThrownAwayIfNewOneArrives()
        {
            using (var library = Helpers.CreateLibrary())
            {
                new TestScheduler().With(scheduler =>
                {
                    var songs = new[] { new YoutubeSong("http://blabla.com", TimeSpan.Zero) };

                    // Define that the old request takes longer than the new request
                    var firstReturn  = Observable.Timer(TimeSpan.FromSeconds(2000), scheduler).Select(x => new List <YoutubeSong>());
                    var secondReturn = Observable.Return(new List <YoutubeSong>(songs));

                    var songFinder = Substitute.For <IYoutubeSongFinder>();
                    songFinder.GetSongsAsync(Arg.Any <string>()).Returns(firstReturn, secondReturn);

                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                    var vm     = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, songFinder);

                    vm.SearchText = "Request1";

                    scheduler.AdvanceByMs(501);

                    vm.SearchText = "Request2";

                    scheduler.AdvanceByMs(501);

                    scheduler.AdvanceByMs(2000);

                    Assert.Equal(songs.First().OriginalPath, vm.SelectableSongs.First().Path);
                });
            }
        }
コード例 #2
0
        public void SmokeTest()
        {
            var song1 = new YoutubeSong("www.youtube.com?watch=abcde", TimeSpan.Zero)
            {
                Title = "A"
            };
            var song2 = new YoutubeSong("www.youtube.com?watch=abcdef", TimeSpan.Zero)
            {
                Title = "B"
            };

            var songs = (IReadOnlyList <YoutubeSong>) new[] { song1, song2 }.ToList();

            var songFinder = Substitute.For <IYoutubeSongFinder>();

            songFinder.GetSongsAsync(Arg.Any <string>()).Returns(Observable.Return(songs));

            using (var library = Helpers.CreateLibrary())
            {
                Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                var  vm    = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, songFinder);

                Assert.Equal(songs, vm.SelectableSongs.Select(x => x.Model).ToList());
                Assert.Equal(songs.First(), vm.SelectableSongs.First().Model);
                Assert.False(vm.IsSearching);
            }
        }
コード例 #3
0
        public void OldRequestIsThrownAwayIfNewOneArrives()
        {
            var networkStatus = Substitute.For<INetworkStatus>();
            networkStatus.IsAvailable.Returns(Observable.Return(true));

            using (var library = Helpers.CreateLibrary())
            {
                new TestScheduler().With(scheduler =>
                {
                    var songs = new[] { new YoutubeSong("http://blabla.com", TimeSpan.Zero) };

                    // Define that the old request takes longer than the new request
                    var firstReturn = Observable.Timer(TimeSpan.FromSeconds(2000), scheduler).Select(x => (IReadOnlyList<YoutubeSong>)new List<YoutubeSong>()).ToTask();
                    var secondReturn = Task.FromResult((IReadOnlyList<YoutubeSong>)new List<YoutubeSong>(songs));

                    var songFinder = Substitute.For<IYoutubeSongFinder>();
                    songFinder.GetSongsAsync(Arg.Any<string>()).Returns(firstReturn, secondReturn);

                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                    var vm = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, networkStatus, songFinder);

                    vm.SearchText = "Request1";

                    scheduler.AdvanceByMs(501);

                    vm.SearchText = "Request2";

                    scheduler.AdvanceByMs(501);

                    scheduler.AdvanceByMs(2000);

                    Assert.Equal(songs.First().OriginalPath, vm.SelectableSongs.First().Path);
                });
            }
        }
コード例 #4
0
ファイル: LiveView.xaml.cs プロジェクト: kingwisdom/testrepo
 public LiveView()
 {
     InitializeComponent();
     BindingContext = vm = new YoutubeViewModel();
     // webView.Source = $"https://www.youtube.com/watch?v=4150Ebz25pc";
     webView.Source    = $"https://thepottershouseoflagos.org/watch-live/";
     loading.IsVisible = false;
 }
コード例 #5
0
        public async Task YoutubeTest()
        {
            // Arrange
            var youtubeViewModel = new YoutubeViewModel();

            // Act
            await youtubeViewModel.InitDataAsync();

            // Arrange
            Assert.IsNotNull(youtubeViewModel.YoutubeItems);
            Assert.IsTrue(youtubeViewModel.YoutubeItems.Count > 0);
        }
コード例 #6
0
        public void SongFinderExceptionSetsSearchFailedToTrue()
        {
            var songFinder = Substitute.For <IYoutubeSongFinder>();

            songFinder.GetSongsAsync(Arg.Any <string>()).Returns(x => { throw new NetworkSongFinderException("Blabla", null); });

            using (var library = Helpers.CreateLibrary())
            {
                Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                var  vm    = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, songFinder);

                Assert.True(vm.SearchFailed);
            }
        }
コード例 #7
0
ファイル: YoutubeService.cs プロジェクト: zuyuz/Portal
        public async Task <YoutubeViewModel> Search(string searchTerm, int maxResults = 50)
        {
            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = key,
                ApplicationName = this.GetType().ToString()
            });

            var searchListRequest = youtubeService.Search.List("snippet");

            searchListRequest.Q          = searchTerm; // Replace with your search term.
            searchListRequest.MaxResults = maxResults;

            // Call the search.list method to retrieve results matching the specified query term.
            var searchListResponse = await searchListRequest.ExecuteAsync();

            var youtubeViewModel = new YoutubeViewModel();

            // Add each result to the appropriate list, and then display the lists of
            // matching videos, channels, and playlists.
            foreach (var searchResult in searchListResponse.Items)
            {
                switch (searchResult.Id.Kind)
                {
                case "youtube#video":
                    var video = new Video();
                    video.Name = searchResult.Snippet.Title;
                    video.Id   = searchResult.Id.VideoId;
                    youtubeViewModel.Videos.Add(video);
                    break;

                case "youtube#channel":
                    var channel = new Channel();
                    channel.Name = searchResult.Snippet.Title;
                    channel.Id   = searchResult.Id.VideoId;
                    youtubeViewModel.Channels.Add(channel);
                    break;

                case "youtube#playlist":
                    var playlist = new Playlist();
                    playlist.Name = searchResult.Snippet.Title;
                    playlist.Id   = searchResult.Id.VideoId;
                    youtubeViewModel.Playlists.Add(playlist);
                    break;
                }
            }

            return(youtubeViewModel);
        }
コード例 #8
0
            public async Task SmokeTest()
            {
                var songFinder = Substitute.For <IYoutubeSongFinder>();

                songFinder.GetSongsAsync(Arg.Any <string>()).Returns(Observable.Return(new List <YoutubeSong>()));

                using (var library = Helpers.CreateLibrary())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                    var  vm    = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, songFinder);

                    await vm.Search.ExecuteAsync();

                    songFinder.Received(2).GetSongsAsync(string.Empty);
                }
            }
コード例 #9
0
 public YoutubeTestimonialPage(RootPage root)
 {
     try
     {
         InitializeComponent();
         App.Configuration.InitialAsync(this);
         NavigationPage.SetHasNavigationBar(this, false);
         _model = new YoutubeViewModel()
         {
             Root = root,
         };
         BindingContext = _model;
     }
     catch (Exception ex)
     {
         var exceptionHandler = new ExceptionHandler(typeof(YoutubeTestimonialPage).FullName, ex);
     }
 }
コード例 #10
0
        public async Task <JsonResult> Test(YoutubeViewModel model)
        {
            YoutubeData data = new YoutubeData()
            {
                Views       = model.Views,
                FemaleViews = model.FemaleViews,
                Likes       = model.Likes,
                Subcribers  = model.Subcribers,
                MaleViews   = model.MaleViews,
                Comments    = model.Comments,
                Dislike     = model.Dislike,
                Engagement  = model.Engagement,
            };

            _YoutubeRepo.Add(data);

            return(Json(true));
        }
コード例 #11
0
 public YoutubeTestimonialPage(RootPage root)
 {
     try
     {
         InitializeComponent();
         App.Configuration.Initial(this);
         NavigationPage.SetHasNavigationBar(this, false);
         _model = new YoutubeViewModel()
         {
             Root = root,
         };
         BindingContext = _model;
     }
     catch (Exception)
     {
         //
     }
 }
コード例 #12
0
        public void AvailableNetworkStartsSongSearch()
        {
            var isAvailable = new BehaviorSubject<bool>(false);
            var networkStatus = Substitute.For<INetworkStatus>();
            networkStatus.IsAvailable.Returns(isAvailable);

            var songFinder = Substitute.For<IYoutubeSongFinder>();
            songFinder.GetSongsAsync(Arg.Any<string>())
                .Returns(Task.FromResult((IReadOnlyList<YoutubeSong>)new List<YoutubeSong>()));

            using (var library = Helpers.CreateLibrary())
            {
                Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                var vm = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, networkStatus, songFinder);

                isAvailable.OnNext(true);

                songFinder.ReceivedWithAnyArgs(1).GetSongsAsync(null);
            }
        }
コード例 #13
0
        private void App_Startup(object sender, EventArgs e)
        {
            _model     = new TwitcherModel();
            _viewModel = new TwitcherViewModel(_model);

            _viewModel.ExitApplication += delegate(object twitcherViewModelSender, EventArgs twitcherViewModelEventArgs)
            {
                Shutdown();
            };
            _viewModel.YoutubeWindowCommandInvoked += delegate(object twitcherViewModelSender, EventArgs twitcherViewModelEventArgs)
            {
                _view.Hide();

                youtubeModel     = new YoutubeModel();
                youtubeViewModel = new YoutubeViewModel(youtubeModel);

                youtubeWindow             = new YoutubeWindow();
                youtubeWindow.DataContext = youtubeViewModel;

                youtubeViewModel.TwitcherCommandInvoked += delegate(object youtubeViewModelSender, EventArgs youtubeViewModelEventArgs)
                {
                    youtubeWindow.Close();

                    _view.Show();
                };

                youtubeViewModel.Model_DownloadFinished += delegate(object youtubeViewModelSender, EventArgs youtubeViewModelEventArgs)
                {
                    MessageBox.Show("Download finished!", "Youtube video download", MessageBoxButton.OK);
                };

                youtubeWindow.Show();
            };


            _view             = new MainWindow();
            _view.DataContext = _viewModel;

            _view.Show();
        }
コード例 #14
0
        public void SearchTextChangeSetsIsSearchingTest()
        {
            var songFinder = Substitute.For<IYoutubeSongFinder>();
            songFinder.GetSongsAsync(Arg.Any<string>()).Returns(Observable.Return(new List<YoutubeSong>()));

            using (var library = Helpers.CreateLibrary())
            {
                new TestScheduler().With(scheduler =>
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                    var vm = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, songFinder);

                    var isSearching = vm.WhenAnyValue(x => x.IsSearching).CreateCollection();

                    vm.SearchText = "Trololo";

                    scheduler.AdvanceByMs(501);

                    Assert.Equal(new[] { false, true, false }, isSearching);
                });
            }
        }
コード例 #15
0
        public void SearchTextChangeSetsIsSearchingTest()
        {
            var songFinder = Substitute.For <IYoutubeSongFinder>();

            songFinder.GetSongsAsync(Arg.Any <string>()).Returns(Observable.Return(new List <YoutubeSong>()));

            using (var library = Helpers.CreateLibrary())
            {
                new TestScheduler().With(scheduler =>
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                    var vm     = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, songFinder);

                    var isSearching = vm.WhenAnyValue(x => x.IsSearching).CreateCollection();

                    vm.SearchText = "Trololo";

                    scheduler.AdvanceByMs(501);

                    Assert.Equal(new[] { false, true, false }, isSearching);
                });
            }
        }
コード例 #16
0
        public YoutubeViewPage()
        {
            var youtubeViewModel = new YoutubeViewModel();

            BindingContext  = youtubeViewModel;
            Title           = "WhatsApp Fun Videos";
            BackgroundColor = Color.FromHex("#C70039");
            var adBanner = new AdBanner();

            adBanner.Size = AdBanner.Sizes.Standardbanner;
            var dataTemplate = new DataTemplate(() =>
            {
                var titleLabel = new Label
                {
                    TextColor = Color.White,
                    FontSize  = 20
                };

                var mediaImage = new Image
                {
                    HeightRequest = 205
                };

                titleLabel.SetBinding(Label.TextProperty, new Binding("Title"));
                mediaImage.SetBinding(Image.SourceProperty, new Binding("MediumThumbnailUrl"));

                return(new ViewCell
                {
                    View = new StackLayout
                    {
                        Orientation = StackOrientation.Vertical,
                        Padding = new Thickness(0, 0),
                        Children =
                        {
                            titleLabel,
                            mediaImage,
                        }
                    }
                });
            });

            var listView = new ListView
            {
                HasUnevenRows = true
            };

            listView.SetBinding(ListView.ItemsSourceProperty, "YoutubeItems");

            listView.ItemTemplate = dataTemplate;

            listView.ItemTapped += ListViewOnItemTapped;

            Content = new StackLayout
            {
                Padding  = new Thickness(0, 0),
                Children =
                {
                    listView,
                    adBanner
                }
            };
        }
コード例 #17
0
        public void SongFinderExceptionSetsSearchFailedToTrue()
        {
            var songFinder = Substitute.For<IYoutubeSongFinder>();
            songFinder.GetSongsAsync(Arg.Any<string>()).Returns(x => { throw new NetworkSongFinderException("Blabla", null); });

            using (var library = Helpers.CreateLibrary())
            {
                Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                var vm = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, songFinder);

                Assert.True(vm.SearchFailed);
            }
        }
コード例 #18
0
            public async Task SmokeTest()
            {
                var songFinder = Substitute.For<IYoutubeSongFinder>();
                songFinder.GetSongsAsync(Arg.Any<string>()).Returns(Observable.Return(new List<YoutubeSong>()));

                using (var library = Helpers.CreateLibrary())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                    var vm = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, songFinder);

                    await vm.Search.ExecuteAsync();

                    songFinder.Received(2).GetSongsAsync(string.Empty);
                }
            }
コード例 #19
0
            public void SmokeTest()
            {
                var networkStatus = Substitute.For<INetworkStatus>();
                networkStatus.IsAvailable.Returns(Observable.Return(false), Observable.Return(true));

                var songFinder = Substitute.For<IYoutubeSongFinder>();
                songFinder.GetSongsAsync(Arg.Any<string>()).Returns(Task.FromResult((IReadOnlyList<YoutubeSong>)new List<YoutubeSong>()));

                using (var library = Helpers.CreateLibrary())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                    var vm = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, networkStatus, songFinder);

                    Assert.True(vm.IsNetworkUnavailable);

                    vm.RefreshNetworkAvailabilityCommand.Execute(null);

                    Assert.False(vm.IsNetworkUnavailable);
                }
            }
コード例 #20
0
 public TutorialVideos()
 {
     InitializeComponent();
     BindingContext = new YoutubeViewModel();
 }
コード例 #21
0
        public void UnavailableNetworkSmokeTest()
        {
            var isAvailable = new BehaviorSubject<bool>(false);
            var networkStatus = Substitute.For<INetworkStatus>();
            networkStatus.IsAvailable.Returns(isAvailable);

            var songFinder = Substitute.For<IYoutubeSongFinder>();
            songFinder.GetSongsAsync(Arg.Any<string>()).Returns(Task.FromResult((IReadOnlyList<YoutubeSong>)new List<YoutubeSong>()));

            using (var library = Helpers.CreateLibrary())
            {
                Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                var vm = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, networkStatus, songFinder);

                var isNetworkUnavailable = vm.WhenAnyValue(x => x.IsNetworkUnavailable).CreateCollection();

                isAvailable.OnNext(true);

                Assert.Equal(new[] { true, false }, isNetworkUnavailable);
            }
        }
コード例 #22
0
        public YoutubeViewPage()
        {
            new FontButton(this);

            Title = "Youtube";

            var youtubeViewModel = new YoutubeViewModel();

            BindingContext = youtubeViewModel;

            /*var label = new Label
             * {
             *  Text = "Youtube",
             *  TextColor = Color.Gray,
             *  FontSize = 24
             * };*/

            var dataTemplate = new DataTemplate(() =>
            {
                var channelTitleLabel = new Label
                {
                    TextColor = Color.Maroon,
                    FontSize  = Device.GetNamedSize(FontButton.GetTextSize(1), typeof(Label))
                };
                var titleLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = Device.GetNamedSize(FontButton.GetTextSize(0), typeof(Label))
                };
                var descriptionLabel = new Label
                {
                    TextColor = Color.Gray,
                    FontSize  = Device.GetNamedSize(FontButton.GetTextSize(-1), typeof(Label))
                };

                /*var viewCountLabel = new Label
                 * {
                 *  TextColor = Color.FromHex("#0D47A1"),
                 *  FontSize = 14
                 * };
                 * var likeCountLabel = new Label
                 * {
                 *  TextColor = Color.FromHex("#2196F3"),
                 *  FontSize = 14
                 * };
                 * var dislikeCountLabel = new Label
                 * {
                 *  TextColor = Color.FromHex("#0D47A1"),
                 *  FontSize = 14
                 * };
                 * var favoriteCountLabel = new Label
                 * {
                 *  TextColor = Color.FromHex("#2196F3"),
                 *  FontSize = 14
                 * };
                 * var commentCountLabel = new Label
                 * {
                 *  TextColor = Color.FromHex("#0D47A1"),
                 *  FontSize = 14
                 * };*/
                var mediaImage = new Image
                {
                    HeightRequest = GetImageHeight(FontButton.GetTextSize(0))
                };

                /*MessagingCenter.Subscribe<Application>(this, "Hi", (sender) => {
                 *
                 *  channelTitleLabel.FontSize = Device.GetNamedSize(FontButton.GetTextSize(1), typeof(Label));
                 *
                 *  titleLabel.FontSize = Device.GetNamedSize(FontButton.GetTextSize(0), typeof(Label));
                 *
                 *  descriptionLabel.FontSize = Device.GetNamedSize(FontButton.GetTextSize(-1), typeof(Label));
                 *
                 *  mediaImage.HeightRequest = GetImageHeight(FontButton.GetTextSize(0));
                 *
                 * });*/

                channelTitleLabel.SetBinding(Label.TextProperty, new Binding("ChannelTitle"));
                titleLabel.SetBinding(Label.TextProperty, new Binding("Title"));
                descriptionLabel.SetBinding(Label.TextProperty, new Binding("Description"));
                mediaImage.SetBinding(Image.SourceProperty, new Binding("HighThumbnailUrl"));

                /*viewCountLabel.SetBinding(Label.TextProperty, new Binding("ViewCount", BindingMode.Default, null, null, "{0:n0} views"));
                 * likeCountLabel.SetBinding(Label.TextProperty, new Binding("LikeCount", BindingMode.Default, null, null, "{0:n0} likes"));
                 * dislikeCountLabel.SetBinding(Label.TextProperty, new Binding("DislikeCount", BindingMode.Default, null, null, "{0:n0} dislike"));
                 * commentCountLabel.SetBinding(Label.TextProperty, new Binding("CommentCount", BindingMode.Default, null, null, "{0:n0} comments"));
                 * favoriteCountLabel.SetBinding(Label.TextProperty, new Binding("FavoriteCount", BindingMode.Default, null, null, "{0:n0} favorite"));*/

                var viewCell = new ViewCell
                {
                    View = new StackLayout
                    {
                        BackgroundColor = Color.FromHex("#e6e6e6"),
                        Children        =
                        {
                            new Frame
                            {
                                BackgroundColor = Color.FromHex("#FFFFFF"),
                                CornerRadius    = 2,
                                HasShadow       = false,
                                Margin          = new Thickness(10, 5, 10, 5),
                                Content         = new StackLayout
                                {
                                    VerticalOptions = LayoutOptions.Center,
                                    Orientation     = StackOrientation.Horizontal,
                                    //Padding = new Thickness(0, 0, 0, 20),
                                    Children =
                                    {
                                        //channelTitleLabel,

                                        /*new StackLayout
                                         * {
                                         *  Orientation = StackOrientation.Horizontal,
                                         *  Children =
                                         *  {
                                         *      viewCountLabel,
                                         *      likeCountLabel,
                                         *      dislikeCountLabel,
                                         *  }
                                         * },
                                         * new StackLayout
                                         * {
                                         *  Orientation = StackOrientation.Horizontal,
                                         *  TranslationY = -7,
                                         *  Children =
                                         *  {
                                         *      favoriteCountLabel,
                                         *      commentCountLabel
                                         *  }
                                         * },*/
                                        mediaImage,

                                        new StackLayout
                                        {
                                            Padding         = new Thickness(10,         0, 0, 0),
                                            VerticalOptions = LayoutOptions.Center,
                                            Orientation     = StackOrientation.Vertical,
                                            Children        =
                                            {
                                                titleLabel,
                                                descriptionLabel
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                MessagingCenter.Subscribe <Application>(this, "Hi", (sender) => {
                    channelTitleLabel.FontSize = Device.GetNamedSize(FontButton.GetTextSize(1), typeof(Label));

                    titleLabel.FontSize = Device.GetNamedSize(FontButton.GetTextSize(0), typeof(Label));

                    descriptionLabel.FontSize = Device.GetNamedSize(FontButton.GetTextSize(-1), typeof(Label));

                    mediaImage.HeightRequest = GetImageHeight(FontButton.GetTextSize(0));

                    viewCell.ForceUpdateSize();
                });

                return(viewCell);
            });

            var listView = new ListView
            {
                HasUnevenRows = true
            };

            listView.SetBinding(ListView.ItemsSourceProperty, "YoutubeItems");

            listView.ItemTemplate = dataTemplate;

            listView.ItemTapped += ListViewOnItemTapped;

            //listView.SeparatorColor = Color.Gray;

            listView.SeparatorVisibility = SeparatorVisibility.None;

            listView.BackgroundColor = Color.FromHex("#e6e6e6");



            Content = new StackLayout
            {
                Children =
                {
                    //label,
                    listView
                }
            };
        }
コード例 #23
0
 public YoutubeChannel()
 {
     InitializeComponent();
     BindingContext = new YoutubeViewModel("UCePZkMO8KURFX34jvJwXhzQ");
 }
コード例 #24
0
        public YoutubePage()
        {
            InitializeComponent();

            BindingContext = _viewModel = new YoutubeViewModel();
        }
コード例 #25
0
        public YoutubeViewPage()
        {
            Title           = "YouTube";
            BackgroundColor = Color.White;

            var youtubeViewModel = new YoutubeViewModel();

            BindingContext = youtubeViewModel;

            var label = new Label
            {
                Text      = "Videos from my Xamarin Channel",
                TextColor = Color.Gray,
                FontSize  = 24
            };

            var dataTemplate = new DataTemplate(() =>
            {
                var channelTitleLabel = new Label
                {
                    TextColor = Color.Maroon,
                    FontSize  = 22
                };
                var titleLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = 16
                };
                var descriptionLabel = new Label
                {
                    TextColor = Color.Gray,
                    FontSize  = 14
                };
                var viewCountLabel = new Label
                {
                    TextColor = Color.FromHex("#0D47A1"),
                    FontSize  = 14
                };
                var likeCountLabel = new Label
                {
                    TextColor = Color.FromHex("#2196F3"),
                    FontSize  = 14
                };
                var dislikeCountLabel = new Label
                {
                    TextColor = Color.FromHex("#0D47A1"),
                    FontSize  = 14
                };
                var favoriteCountLabel = new Label
                {
                    TextColor = Color.FromHex("#2196F3"),
                    FontSize  = 14
                };
                var commentCountLabel = new Label
                {
                    TextColor = Color.FromHex("#0D47A1"),
                    FontSize  = 14
                };
                var mediaImage = new Image
                {
                    HeightRequest = 200
                };

                channelTitleLabel.SetBinding(Label.TextProperty, new Binding("ChannelTitle"));
                titleLabel.SetBinding(Label.TextProperty, new Binding("Title"));
                descriptionLabel.SetBinding(Label.TextProperty, new Binding("Description"));
                mediaImage.SetBinding(Image.SourceProperty, new Binding("HighThumbnailUrl"));
                viewCountLabel.SetBinding(Label.TextProperty, new Binding("ViewCount", BindingMode.Default, null, null, "{0:n0} views"));
                likeCountLabel.SetBinding(Label.TextProperty, new Binding("LikeCount", BindingMode.Default, null, null, "{0:n0} likes"));
                dislikeCountLabel.SetBinding(Label.TextProperty, new Binding("DislikeCount", BindingMode.Default, null, null, "{0:n0} dislike"));
                commentCountLabel.SetBinding(Label.TextProperty, new Binding("CommentCount", BindingMode.Default, null, null, "{0:n0} comments"));
                favoriteCountLabel.SetBinding(Label.TextProperty, new Binding("FavoriteCount", BindingMode.Default, null, null, "{0:n0} favorite"));

                return(new ViewCell
                {
                    View = new StackLayout
                    {
                        Orientation = StackOrientation.Vertical,
                        Padding = new Thickness(5, 10),
                        Children =
                        {
                            channelTitleLabel,
                            new StackLayout
                            {
                                Orientation = StackOrientation.Horizontal,
                                Children =
                                {
                                    viewCountLabel,
                                    likeCountLabel,
                                    dislikeCountLabel,
                                }
                            },
                            new StackLayout
                            {
                                Orientation = StackOrientation.Horizontal,
                                TranslationY = -7,
                                Children =
                                {
                                    favoriteCountLabel,
                                    commentCountLabel
                                }
                            },
                            titleLabel,
                            mediaImage,
                            descriptionLabel,
                        }
                    }
                });
            });

            var listView = new ListView
            {
                HasUnevenRows = true
            };

            listView.SetBinding(ListView.ItemsSourceProperty, "YoutubeItems");

            listView.ItemTemplate = dataTemplate;

            listView.ItemTapped += ListViewOnItemTapped;

            Content = new StackLayout
            {
                Padding  = new Thickness(5, 10),
                Children =
                {
                    label,
                    listView
                }
            };
        }
コード例 #26
0
        public void SmokeTest()
        {
            var song1 = new YoutubeSong("www.youtube.com?watch=abcde", TimeSpan.Zero) { Title = "A" };
            var song2 = new YoutubeSong("www.youtube.com?watch=abcdef", TimeSpan.Zero) { Title = "B" };

            var songs = (IReadOnlyList<YoutubeSong>)new[] { song1, song2 }.ToList();

            var networkStatus = Substitute.For<INetworkStatus>();
            networkStatus.IsAvailable.Returns(Observable.Return(true));

            var songFinder = Substitute.For<IYoutubeSongFinder>();
            songFinder.GetSongsAsync(Arg.Any<string>()).Returns(Task.FromResult(songs));

            using (var library = Helpers.CreateLibrary())
            {
                Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                var vm = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, networkStatus, songFinder);

                Assert.Equal(songs, vm.SelectableSongs.Select(x => x.Model).ToList());
                Assert.Equal(songs.First(), vm.SelectableSongs.First().Model);
                Assert.False(vm.IsSearching);
            }
        }