public SongsViewController()
        {
            Title            = "Songs";
            TableView.Source = new ViewModelDataSource <Song> {
                CellForItem = (tv, item) => {
                    var cell = tv.DequeueReusableCell <SongCell>(SongCell.Key);
                    cell.Song = item;
                    return(cell);
                },
                ViewModel = (viewModel = new SongsViewModel()),
            };

            TableView.TableHeaderView = progressView = new UIProgressView(UIProgressViewStyle.Bar)
            {
                Alpha = 0f
            };

            progressView.SizeToFit();

            viewModel.ItemsChanged += (sender, e) =>
                                      InvokeOnMainThread(() => {
                Console.WriteLine("Reloading the TableView.");
                TableView.ReloadData();
            });

            viewModel.SongsUpdated += progress =>
                                      InvokeOnMainThread(() => {
                Console.WriteLine("{0:P}", progress);
                progressView.Progress = progress;
                progressView.Alpha    = progress >= 1f ? 0 : 1;
            });
        }
		public SongsViewController ()
		{
			Title = "Songs";
			TableView.Source = new ViewModelDataSource<Song> {
				CellForItem = (tv,item) => {
					var cell = tv.DequeueReusableCell<SongCell>(SongCell.Key);
					cell.Song = item;
					return cell;
				},
				ViewModel = (viewModel = new SongsViewModel()),
			};

			TableView.TableHeaderView = progressView = new UIProgressView (UIProgressViewStyle.Bar) {
				Alpha = 0f
			};

			progressView.SizeToFit ();

			viewModel.ItemsChanged += (sender, e) => 
				InvokeOnMainThread(() => {
					Console.WriteLine("Reloading the TableView.");
					TableView.ReloadData();
				});

			viewModel.SongsUpdated += progress => 
				InvokeOnMainThread(() => {
					Console.WriteLine("{0:P}", progress);
					progressView.Progress = progress;
					progressView.Alpha = progress >= 1f ? 0 : 1;
				});

		}
Exemple #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor = UIColor.White;

            Title = ViewModel.Title;

#pragma warning disable XI0002 // Notifies you from using newer Apple APIs when targeting an older OS version
            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                NavigationItem.LargeTitleDisplayMode = UINavigationItemLargeTitleDisplayMode.Never;
            }
#pragma warning restore XI0002 // Notifies you from using newer Apple APIs when targeting an older OS version

            var shareButton = new UIBarButtonItem(UIBarButtonSystemItem.Action, OnShareButtonClick);
            NavigationItem.RightBarButtonItem = shareButton;

            var webConfig = new WKWebViewConfiguration();
            _webView = new WKWebView(CGRect.Empty, webConfig)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                NavigationDelegate = this,
                UIDelegate         = this
            };
            View.AddSubview(_webView);

            var constraints = new[]
            {
                _webView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _webView.TopAnchor.ConstraintEqualTo(View.TopAnchor),
                _webView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
                _webView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor)
            };

            View.AddConstraints(constraints);

            _loadBar = new UIProgressView(UIProgressViewStyle.Bar)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            _loadBar.SizeToFit();

            View.AddSubview(_loadBar);

            var guide = this.GetCompatibleLayoutGuide();
            _loadBar.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor).Active   = true;
            _loadBar.TopAnchor.ConstraintEqualTo(guide.TopAnchor).Active          = true;
            _loadBar.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor).Active = true;

            _webView.LoadRequest(new NSUrlRequest(NSUrl.FromString(ViewModel.StoryUrl)));
        }
Exemple #4
0
        public SongsViewController()
        {
            Title            = "Songs";
            TableView.Source = new ViewModelDataSource <Song> {
                CellForItem = (tv, item) => {
                    var cell = tv.DequeueReusableCell <SongCell>(SongCell.Key);
                    cell.Song = item;
                    return(cell);
                },
                ViewModel = (viewModel = new SongsViewModel()),
            };

            TableView.TableHeaderView = progressView = new UIProgressView(UIProgressViewStyle.Bar)
            {
                Alpha = 0f
            };

            progressView.SizeToFit();

            viewModel.ItemsChanged += (sender, e) => {
                // TODO: Step 2b - update UI 1/sec vs. each notification
                if ((DateTime.Now - lastUpdate).TotalSeconds >= 1)
                {
                    InvokeOnMainThread(() => {
                        Console.WriteLine("Reloading the TableView.");
                        TableView.ReloadData();
                    });
                    lastUpdate = DateTime.Now;
                }
            };

            viewModel.SongsUpdated += progress =>
                                      InvokeOnMainThread(() => {
                Console.WriteLine("{0:P}", progress);
                progressView.Progress = progress;
                progressView.Alpha    = progress >= 1f ? 0 : 1;
            });
        }
		public SongsViewController ()
		{
			Title = "Songs";
			TableView.Source = new ViewModelDataSource<Song> {
				CellForItem = (tv,item) => {
					var cell = tv.DequeueReusableCell<SongCell>(SongCell.Key);
					cell.Song = item;
					return cell;
				},
				ViewModel = (viewModel = new SongsViewModel()),
			};

			TableView.TableHeaderView = progressView = new UIProgressView (UIProgressViewStyle.Bar) {
				Alpha = 0f
			};

			progressView.SizeToFit ();

			viewModel.ItemsChanged += (sender, e) => {
				// TODO: Step 2b - update UI 1/sec vs. each notification
				if ((DateTime.Now - lastUpdate).TotalSeconds >= 1) {
					InvokeOnMainThread(() => {
						Console.WriteLine("Reloading the TableView.");
						TableView.ReloadData();
					});
					lastUpdate = DateTime.Now;
				}
			};

			viewModel.SongsUpdated += progress => 
				InvokeOnMainThread(() => {
					Console.WriteLine("{0:P}", progress);
					progressView.Progress = progress;
					progressView.Alpha = progress >= 1f ? 0 : 1;
				});

		}