Ejemplo n.º 1
0
        protected BaseViewController()
        {
            Appearing
            .Take(1)
            .Select(_ => this.WhenAnyValue(x => x.ViewModel))
            .Switch()
            .OfType <ILoadableViewModel>()
            .Select(x => x.LoadCommand)
            .Subscribe(x => x.ExecuteNow());

            OnActivation(disposable =>
            {
                this.WhenAnyValue(x => x.ViewModel)
                .OfType <IProvidesTitle>()
                .Select(x => x.WhenAnyValue(y => y.Title))
                .Switch()
                .Subscribe(x => Title = x)
                .AddTo(disposable);

                this.WhenAnyValue(x => x.ViewModel)
                .OfType <IRoutingViewModel>()
                .Select(x => x.RequestNavigation)
                .Switch()
                .Select(x => Locator.Current.GetService <IViewLocatorService>().GetView(x))
                .OfType <UIViewController>()
                .Subscribe(Navigate)
                .AddTo(disposable);
            });
        }
Ejemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var tableViewSource = new FeedbackTableViewSource(TableView, ViewModel.Items);

            TableView.Source = tableViewSource;

            Appearing
            .Take(1)
            .Subscribe(_ => LoadData());

            this.WhenActivated(d =>
            {
                d(this.WhenAnyValue(x => x.ViewModel.Title)
                  .Subscribe(title => Title = title));

                d(_repositorySearchBar.GetChangedObservable()
                  .Subscribe(x => ViewModel.SearchKeyword = x));

                d(ViewModel.WhenAnyValue(x => x.IsEmpty)
                  .Where(x => x.HasValue)
                  .Select(x => x.Value)
                  .Subscribe(SetHasItems));

                d(ViewModel.Items.Changed.Select(_ => Unit.Default)
                  .StartWith(Unit.Default)
                  .Select(_ => ViewModel.Items.Select(x => x.GoToCommand.Select(__ => x)))
                  .Select(x => Observable.Merge(x))
                  .Switch()
                  .Select(x => new IssueView(x.RepositoryOwner, x.RepositoryName, x.IssueId))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));
            });
        }
Ejemplo n.º 3
0
        public BranchesViewController(
            string username,
            string repository,
            IApplicationService applicationService = null)
            : base(UITableViewStyle.Plain)
        {
            applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();

            var loadBranches = ReactiveCommand.CreateFromTask(
                () => applicationService.GitHubClient.Repository.Branch.GetAll(username, repository));

            loadBranches
            .ThrownExceptions
            .Do(_ => SetErrorView())
            .Select(error => new UserError(LoadErrorMessage, error))
            .SelectMany(Interactions.Errors.Handle)
            .Subscribe();

            loadBranches
            .Do(_ => TableView.TableFooterView = null)
            .Subscribe(ItemsLoaded);

            Appearing
            .Take(1)
            .Select(_ => Unit.Default)
            .Do(_ => TableView.TableFooterView = new LoadingIndicatorView())
            .InvokeReactiveCommand(loadBranches);
        }
        public LoginViewController()
            : base(true)
        {
            ViewModel = new LoginViewModel(Mvx.Resolve <IApplicationService>(), Mvx.Resolve <IAccountsService>());
            Title     = "Login";

            Appearing.Take(1).Subscribe(_ => LoadRequest());
            OnActivation(d => d(ViewModel.Bind(x => x.IsLoggingIn).SubscribeStatus("Logging in...")));
        }
Ejemplo n.º 5
0
        public MenuViewController()
            : base(UITableViewStyle.Plain)
        {
            _title = new UILabel(new CGRect(0, 40, 320, 40));
            _title.TextAlignment     = UITextAlignment.Left;
            _title.BackgroundColor   = UIColor.Clear;
            _title.Font              = UIFont.SystemFontOfSize(16f);
            _title.TextColor         = UIColor.FromRGB(246, 246, 246);
            NavigationItem.TitleView = _title;

            _profileSection = new Section();
            _repoSection    = new Section {
                HeaderView = new MenuSectionView("Repositories")
            };
            _infoSection = new Section {
                HeaderView = new MenuSectionView("Info & Preferences")
            };

            OnActivation(d =>
            {
                _profileButton.GetClickedObservable().Subscribe(_ => ProfileButtonClicked()).AddTo(d);

                this.WhenAnyValue(x => x.ViewModel.Title)
                .Subscribe(x => _title.Text = x)
                .AddTo(d);

                var updatables = new[] {
                    ViewModel.Groups.Changed,
                    ViewModel.Teams.Changed,
                    ViewModel.TeamEvents.Changed,
                    ViewModel.PinnedRepositories.Changed
                };

                Observable.Merge(updatables.Select(y => y.Select(_ => Unit.Default).StartWith(Unit.Default)))
                .Throttle(TimeSpan.FromMilliseconds(100))
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(_ => CreateMenuRoot())
                .AddTo(d);

                Observable.Return(ViewModel)
                .OfType <IRoutingViewModel>()
                .Select(x => x.RequestNavigation)
                .Switch()
                .Subscribe(x =>
                {
                    var viewFor = Locator.Current.GetService <IViewLocatorService>().GetView(x);
                    NavigationController.PushViewController(viewFor as UIViewController, true);
                })
                .AddTo(d);
            });

            Appearing
            .Take(1)
            .SelectUnit()
            .BindCommand(ViewModel.LoadCommand);
        }
Ejemplo n.º 6
0
        public ReadmeViewController(
            string owner,
            string repository,
            Octokit.Readme readme = null,
            IApplicationService applicationService = null,
            IMarkdownService markdownService       = null)
            : base(false, false)
        {
            _owner              = owner;
            _repository         = repository;
            _applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();
            _markdownService    = markdownService ?? Locator.Current.GetService <IMarkdownService>();

            Title = "Readme";

            var loadCommand = ReactiveCommand.CreateFromTask(() =>
            {
                if (readme != null)
                {
                    return(Task.FromResult(readme));
                }
                return(_applicationService.GitHubClient.Repository.Content.GetReadme(owner, repository));
            });

            loadCommand
            .ThrownExceptions
            .Do(_ => SetErrorView())
            .Select(error => new UserError(LoadErrorMessage, error))
            .SelectMany(Interactions.Errors.Handle)
            .Subscribe();

            loadCommand
            .ToProperty(this, x => x.Readme, out _readme);

            Appearing
            .Take(1)
            .Select(_ => Unit.Default)
            .InvokeReactiveCommand(loadCommand);

            this.WhenAnyValue(x => x.Readme)
            .Where(x => x != null)
            .SelectMany(ConvertToWebView)
            .Subscribe(LoadContent);

            this.WhenAnyValue(x => x.Readme)
            .Select(x => x != null)
            .Subscribe(x => _actionButton.Enabled = x);

            NavigationItem.RightBarButtonItem = _actionButton;

            this.WhenActivated(d =>
            {
                d(_actionButton.GetClickedObservable()
                  .Subscribe(ShareButtonPress));
            });
        }
Ejemplo n.º 7
0
        public GistFileViewController(
            string gistId,
            string filename,
            Octokit.Gist gist = null,
            IApplicationService applicationService = null,
            IAlertDialogService alertDialogService = null,
            IMessageService messageService         = null)
            : base(false)
        {
            _gistId             = gistId;
            _filename           = filename;
            _gist               = gist;
            _applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();
            _alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>();
            messageService      = messageService ?? Locator.Current.GetService <IMessageService>();

            Title = System.IO.Path.GetFileName(filename);

            var actionButton = new UIBarButtonItem(UIBarButtonSystemItem.Action)
            {
                Enabled = false
            };

            NavigationItem.RightBarButtonItem = actionButton;

            var loadCommand = ReactiveCommand.CreateFromTask(Load);

            loadCommand
            .ThrownExceptions
            .Select(HandleLoadError)
            .SelectMany(Interactions.Errors.Handle)
            .Subscribe();

            this.OnActivation(d =>
            {
                d(this.WhenAnyValue(x => x.Gist)
                  .Select(x => x != null)
                  .Subscribe(x => actionButton.Enabled = x));

                d(actionButton
                  .GetClickedObservable()
                  .Subscribe(CreateActionSheet));

                d(loadCommand
                  .IsExecuting
                  .Subscribe(x => actionButton.Enabled = !x));
            });

            Appearing
            .Take(1)
            .Select(_ => Unit.Default)
            .InvokeReactiveCommand(loadCommand);
        }
Ejemplo n.º 8
0
        public LoginViewController()
            : base(true)
        {
            Title = "Login";

            Appearing.Take(1).Subscribe(_ => LoadRequest());

            OnActivation(d =>
            {
                this.WhenAnyObservable(x => x.ViewModel.LoginCommand.IsExecuting)
                .SubscribeStatus("Logging in...")
                .AddTo(d);
            });
        }
Ejemplo n.º 9
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var tableViewSource = new GistTableViewSource(TableView, ViewModel.Items);

            TableView.Source = tableViewSource;

            Appearing
            .Take(1)
            .Select(_ => ViewModel.LoadCommand.Execute())
            .Switch()
            .Take(1)
            .Catch(Observable.Return(false))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(SetItemsPresent);

            this.WhenActivated(d =>
            {
                if (ShowSearchBar)
                {
                    d(_repositorySearchBar.Value.GetChangedObservable()
                      .Subscribe(x => ViewModel.SearchText = x));
                }

                d(ViewModel.ItemSelected
                  .Select(x => GistViewController.FromGist(x.Gist))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(ViewModel.WhenAnyValue(x => x.HasMore)
                  .Subscribe(x => TableView.TableFooterView = x ? _loading : null));

                d(tableViewSource.RequestMore
                  .InvokeCommand(ViewModel.LoadMoreCommand));

                d(ViewModel.LoadCommand
                  .Select(_ => ViewModel.Items.Changed)
                  .Switch()
                  .Select(_ => Unit.Default)
                  .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
                  .Where(_ => TableView.LastItemVisible())
                  .InvokeCommand(ViewModel.LoadMoreCommand));

                d(ViewModel.LoadCommand.Merge(ViewModel.LoadMoreCommand)
                  .Select(_ => Unit.Default)
                  .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
                  .Where(_ => TableView.LastItemVisible())
                  .InvokeCommand(ViewModel.LoadMoreCommand));
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var tableViewSource = new RepositoryTableViewSource(TableView);

            TableView.Source = tableViewSource;

            Appearing
            .Take(1)
            .Select(_ => Unit.Default)
            .InvokeCommand(ViewModel.LoadCommand);

            this.WhenActivated(d =>
            {
                d(ViewModel.LoadCommand.IsExecuting
                  .Subscribe(Loading));

                d(_trendingTitleButton.GetClickedObservable()
                  .Subscribe(_ => ShowLanguages()));

                d(ViewModel.WhenAnyValue(x => x.SelectedLanguage)
                  .Subscribe(x => _trendingTitleButton.Text = x.Name));

                d(ViewModel.RepositoryItemSelected
                  .Select(x => new RepositoryViewController(x.Owner, x.Name))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(ViewModel.WhenAnyValue(x => x.Items).Subscribe(items =>
                {
                    var sections = items.Select(item =>
                    {
                        var tsi = new TableSectionInformation <RepositoryItemViewModel, RepositoryCellView>(
                            new ReactiveList <RepositoryItemViewModel>(item.Item2),
                            RepositoryCellView.Key,
                            (float)UITableView.AutomaticDimension);
                        tsi.Header = new TableSectionHeader(() => CreateHeaderView(item.Item1), 26f);
                        return(tsi);
                    });

                    tableViewSource.Data = sections.ToList();
                }));
            });
        }
Ejemplo n.º 11
0
        public PullRequestDiffViewController(
            string username,
            string repository,
            int pullRequestId,
            string path,
            string patch,
            string commit,
            IApplicationService applicationService         = null,
            INetworkActivityService networkActivityService = null,
            IMarkdownService markdownService = null)
            : base(false)
        {
            _applicationService     = applicationService ?? Locator.Current.GetService <IApplicationService>();
            _networkActivityService = networkActivityService ?? Locator.Current.GetService <INetworkActivityService>();
            _markdownService        = markdownService ?? Locator.Current.GetService <IMarkdownService>();
            _username      = username;
            _repository    = repository;
            _pullRequestId = pullRequestId;
            _path          = path;
            _patch         = patch;
            _commit        = commit;

            Title = string.IsNullOrEmpty(_path) ? "Diff" : System.IO.Path.GetFileName(_path);

            var loadComments = ReactiveCommand.CreateFromTask(
                _ => _applicationService.GitHubClient.PullRequest.ReviewComment.GetAll(_username, _repository, _pullRequestId));

            loadComments
            .ThrownExceptions
            .Select(error => new UserError("Unable to load comments.", error))
            .SelectMany(Interactions.Errors.Handle)
            .Subscribe();

            loadComments
            .Subscribe(comments => _comments.Reset(comments));

            var loadAll = ReactiveCommand.CreateCombined(new[] { loadComments });

            Appearing
            .Take(1)
            .Select(_ => Unit.Default)
            .InvokeReactiveCommand(loadAll);
        }
Ejemplo n.º 12
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var tableViewSource = new RepositoryTableViewSource(TableView, ViewModel.Items);

            TableView.Source = tableViewSource;

            Appearing
            .Take(1)
            .Subscribe(_ => LoadData());

            this.WhenActivated(d =>
            {
                d(_repositorySearchBar.GetChangedObservable()
                  .Subscribe(x => ViewModel.SearchText = x));

                d(ViewModel.RepositoryItemSelected
                  .Select(x => new RepositoryViewController(x.Owner, x.Name))
                  .Subscribe(x => NavigationController.PushViewController(x, true)));

                d(ViewModel.WhenAnyValue(x => x.HasMore)
                  .Subscribe(x => TableView.TableFooterView = x ? _loading : null));

                d(tableViewSource.RequestMore
                  .InvokeReactiveCommand(ViewModel.LoadMoreCommand));

                d(ViewModel.LoadCommand
                  .Select(_ => ViewModel.Items.Changed)
                  .Switch()
                  .Select(_ => Unit.Default)
                  .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
                  .Where(_ => TableView.LastItemVisible())
                  .InvokeReactiveCommand(ViewModel.LoadMoreCommand));

                d(ViewModel.LoadCommand.Merge(ViewModel.LoadMoreCommand)
                  .Select(_ => Unit.Default)
                  .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
                  .Where(_ => TableView.LastItemVisible())
                  .InvokeReactiveCommand(ViewModel.LoadMoreCommand));
            });
        }
Ejemplo n.º 13
0
        protected TableViewController(UITableViewStyle style = UITableViewStyle.Plain)
            : base(style)
        {
            Appearing
            .Take(1)
            .Select(_ => this.WhenAnyValue(x => x.ViewModel))
            .Switch()
            .OfType <ILoadableViewModel>()
            .Select(x => x.LoadCommand)
            .Subscribe(x => x.ExecuteNow());

            OnActivation(disposable =>
            {
                this.WhenAnyValue(x => x.ViewModel)
                .OfType <IProvidesTitle>()
                .Select(x => x.WhenAnyValue(y => y.Title))
                .Switch()
                .Subscribe(x => Title = x)
                .AddTo(disposable);
            });
        }
        public BranchesAndTagsViewController(
            string username,
            string repository,
            SelectedView selectedView = SelectedView.Branches)
        {
            _branchesViewController = new BranchesViewController(username, repository);
            _tagsViewController     = new TagsViewController(username, repository);

            OnActivation(d =>
            {
                d(_viewSegment
                  .GetChangedObservable()
                  .Subscribe(SegmentValueChanged));
            });

            Appearing
            .Take(1)
            .Select(_ => (int)selectedView)
            .Do(x => _viewSegment.SelectedSegment = x)
            .Do(SegmentValueChanged)
            .Subscribe();

            NavigationItem.TitleView = _viewSegment;
        }
Ejemplo n.º 15
0
        public FileSourceViewController(
            string username,
            string repository,
            string path,
            string sha,
            ShaType shaType,
            bool forceBinary = false,
            IApplicationService applicationService = null,
            IAlertDialogService alertDialogService = null,
            IMessageService messageService         = null)
            : base(false)
        {
            _username           = username;
            _repository         = repository;
            _path               = path;
            _sha                = sha;
            _shaType            = shaType;
            _forceBinary        = forceBinary;
            _applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();
            _alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>();
            messageService      = messageService ?? Locator.Current.GetService <IMessageService>();

            Title = System.IO.Path.GetFileName(path);

            var extension = System.IO.Path.GetExtension(path);

            _isMarkdown = MarkdownExtensions.Contains(extension);

            var actionButton = new UIBarButtonItem(UIBarButtonSystemItem.Action)
            {
                Enabled = false
            };

            NavigationItem.RightBarButtonItem = actionButton;

            var loadCommand = ReactiveCommand.CreateFromTask(Load);

            loadCommand
            .ThrownExceptions
            .Select(HandleLoadError)
            .SelectMany(Interactions.Errors.Handle)
            .Subscribe();

            this.OnActivation(d =>
            {
                d(this.WhenAnyValue(x => x.Content)
                  .Select(x => x != null)
                  .Subscribe(x => actionButton.Enabled = x));

                d(actionButton
                  .GetClickedObservable()
                  .Subscribe(_ => CreateActionSheet(actionButton)));

                d(loadCommand
                  .IsExecuting
                  .Subscribe(x => actionButton.Enabled = !x));
            });

            Appearing
            .Take(1)
            .Select(_ => Unit.Default)
            .InvokeReactiveCommand(loadCommand);

            _messageBus = messageService.Listen <Core.Messages.SourceEditMessage>(_ =>
            {
                Content = null;
                loadCommand.ExecuteNow();
            });
        }
Ejemplo n.º 16
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var split        = new SplitButtonElement();
            var contributors = split.AddButton("Contributors", "-");
            var lastCommit   = split.AddButton("Last Commit", "-");

            var addFeatureButton = new BigButtonElement("Suggest a feature", Octicon.LightBulb);
            var addBugButton     = new BigButtonElement("Report a bug", Octicon.Bug);
            var featuresButton   = new BigButtonElement("Submitted Work Items", Octicon.Clippy);

            HeaderView.SubText = "This app is the product of hard work and great suggestions! Thank you to all whom provide feedback!";
            HeaderView.Image   = UIImage.FromBundle("AppIcons60x60");

            NavigationItem.BackBarButtonItem = new UIBarButtonItem {
                Title = ""
            };

            Root.Reset(
                new Section {
                split
            },
                new Section {
                addFeatureButton, addBugButton
            },
                new Section {
                featuresButton
            });

            OnActivation(d =>
            {
                d(addFeatureButton.Clicked
                  .Select(_ => FeedbackComposerViewController.CreateAsFeature())
                  .Select(viewCtrl => new ThemedNavigationController(viewCtrl))
                  .Subscribe(viewCtrl => PresentViewController(viewCtrl, true, null)));

                d(addBugButton.Clicked
                  .Select(_ => FeedbackComposerViewController.CreateAsBug())
                  .Select(viewCtrl => new ThemedNavigationController(viewCtrl))
                  .Subscribe(viewCtrl => PresentViewController(viewCtrl, true, null)));

                d(this.WhenAnyValue(x => x.ViewModel.Title)
                  .Subscribe(title => Title = title));

                d(featuresButton.Clicked
                  .Subscribe(_ => this.PushViewController(new FeedbackViewController())));

                d(HeaderView.Clicked.Subscribe(_ => GoToRepository()));

                d(this.WhenAnyValue(x => x.ViewModel.Contributors)
                  .Where(x => x.HasValue)
                  .Subscribe(x => contributors.Text = (x.Value >= 100 ? "100+" : x.Value.ToString())));

                d(this.WhenAnyValue(x => x.ViewModel.LastCommit)
                  .Where(x => x.HasValue)
                  .Subscribe(x => lastCommit.Text = x.Value.UtcDateTime.Humanize()));
            });

            Appearing
            .Take(1)
            .Select(_ => Unit.Default)
            .InvokeReactiveCommand(ViewModel.LoadCommand);
        }
Ejemplo n.º 17
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var split        = new SplitButtonElement();
            var contributors = split.AddButton("Contributors", "-");
            var lastCommit   = split.AddButton("Last Commit", "-");

            var openIssue  = new BigButtonElement("Open an Issue on GitHub", Octicon.Bug);
            var sendEmail  = new BigButtonElement("Email Support", Octicon.Mail);
            var openIssues = new BigButtonElement("Existing Issues", Octicon.IssueOpened);

            HeaderView.SubText = "This app is the product of hard work and great suggestions! Thank you to all whom provide feedback!";
            HeaderView.Image   = UIImage.FromBundle("AppIcons60x60");

            NavigationItem.BackBarButtonItem = new UIBarButtonItem {
                Title = ""
            };

            Root.Reset(
                new Section {
                split
            },
                new Section(null, "Opening an issue on the GitHub project page is the fastest way to get a response.")
            {
                openIssue, openIssues
            },
                new Section(),
                new Section(null, "Emails are answered as quickly as possible but there is only one person answering them so expect a delay.")
            {
                sendEmail
            });

            OnActivation(d =>
            {
                d(openIssue.Clicked
                  .Select(_ => new FeedbackComposerViewController())
                  .Select(viewCtrl => new ThemedNavigationController(viewCtrl))
                  .Subscribe(viewCtrl => PresentViewController(viewCtrl, true, null)));

                d(sendEmail.Clicked.Subscribe(_ => SendEmail()));

                d(this.WhenAnyValue(x => x.ViewModel.Title)
                  .Subscribe(title => Title = title));

                d(openIssues.Clicked
                  .Subscribe(_ => this.PushViewController(new FeedbackViewController())));

                d(HeaderView.Clicked.Subscribe(_ => GoToRepository()));

                d(this.WhenAnyValue(x => x.ViewModel.Contributors)
                  .Where(x => x.HasValue)
                  .Subscribe(x => contributors.Text = (x.Value >= 100 ? "100+" : x.Value.ToString())));

                d(this.WhenAnyValue(x => x.ViewModel.LastCommit)
                  .Where(x => x.HasValue)
                  .Subscribe(x => lastCommit.Text = x.Value.UtcDateTime.Humanize()));
            });

            Appearing
            .Take(1)
            .Select(_ => Unit.Default)
            .InvokeReactiveCommand(ViewModel.LoadCommand);
        }