예제 #1
0
        public static GistsViewController CreateUserGistsViewController(string username)
        {
            var applicationService = Locator.Current.GetService <IApplicationService>();
            var mine = applicationService.Account.Username.ToLower().Equals(username.ToLower());

            if (mine)
            {
                var viewModel = new CurrentUserGistsViewModel(username);
                var vc        = new GistsViewController(viewModel)
                {
                    Title = "My Gists"
                };

                var button = new UIBarButtonItem(UIBarButtonSystemItem.Add);
                vc.NavigationItem.RightBarButtonItem = button;
                vc.WhenActivated(d =>
                {
                    d(button.GetClickedObservable()
                      .Subscribe(_ => GistCreateViewController.Show(vc)));
                });

                return(vc);
            }
            else
            {
                var viewModel = GistsViewModel.CreateUserGistsViewModel(username);
                var vc        = new GistsViewController(viewModel)
                {
                    Title = $"{username}'s Gists"
                };
                return(vc);
            }
        }
        public static GistCreateViewController Show(UIViewController parent)
        {
            var ctrl   = new GistCreateViewController();
            var weakVm = new WeakReference <GistCreateViewModel>(ctrl.ViewModel);

            ctrl.ViewModel.SaveCommand.Subscribe(_ => parent.DismissViewController(true, null));
            ctrl.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel);
            ctrl.NavigationItem.LeftBarButtonItem.GetClickedObservable().Subscribe(_ => {
                weakVm.Get()?.CancelCommand.Execute().Subscribe();
                parent.DismissViewController(true, null);
            });
            parent.PresentViewController(new ThemedNavigationController(ctrl), true, null);
            return(ctrl);
        }
 public EditSource(GistCreateViewController dvc)
     : base(dvc)
 {
 }