Ejemplo n.º 1
0
        public SourceTreeViewController(
            string username,
            string repository,
            string path,
            string sha,
            ShaType shaType,
            IApplicationService applicationService = null,
            IFeaturesService featuresService       = null)
            : base(style: UITableViewStyle.Plain)
        {
            _username   = username;
            _repository = repository;
            _path       = path;
            _sha        = sha;
            _shaType    = shaType;

            applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();
            featuresService    = featuresService ?? Locator.Current.GetService <IFeaturesService>();

            var loadContents = ReactiveCommand.CreateFromTask((string shaRef) =>
            {
                if (string.IsNullOrEmpty(path))
                {
                    return(applicationService
                           .GitHubClient.Repository.Content
                           .GetAllContentsByRef(username, repository, shaRef));
                }

                return(applicationService
                       .GitHubClient.Repository.Content
                       .GetAllContentsByRef(username, repository, path, shaRef));
            });

            loadContents
            .ThrownExceptions
            .Do(_ => SetErrorView())
            .Select(HandleLoadError)
            .SelectMany(Interactions.Errors.Handle)
            .Subscribe();

            OnActivation(d =>
            {
                d(_titleView
                  .GetClickedObservable()
                  .Subscribe(_ => ShowBranchSelector()));
            });

            Appearing
            .Select(_ => _sha)
            .Where(x => !string.IsNullOrEmpty(x))
            .DistinctUntilChanged()
            .Do(_ => SetLoading(true))
            .InvokeReactiveCommand(loadContents);

            loadContents
            .Do(_ => SetLoading(false))
            .Subscribe(SetElements);

            NavigationItem.TitleView = _titleView;
        }
        public EnterpriseSupportViewController(IAlertDialogService alertDialogService = null)
        {
            _alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>();

            Appearing
            .Select(_ => NavigationController)
            .Where(x => x != null)
            .Subscribe(x => x.NavigationBar.ShadowImage = new UIImage());
        }
        public EnterpriseSupportViewController(IAlertDialogFactory alertDialogFactory)
        {
            this.WhenAnyValue(x => x.ViewModel.SubmitFeedbackCommand)
            .Switch()
            .Subscribe(_ => {
                var ctrl = new MFMailComposeViewController();
                ctrl.SetSubject("CodeHub Support");
                ctrl.SetToRecipients(new [] { "*****@*****.**" });
                ctrl.Finished += (sender, e) => DismissViewController(true, () => {
                    if (e.Result == MFMailComposeResult.Sent)
                    {
                        alertDialogFactory.Alert("Sent!", "Thanks for your feedback!");
                    }
                });
                PresentViewController(ctrl, true, null);
            });

            Appearing
            .Select(_ => NavigationController)
            .Where(x => x != null)
            .Subscribe(x => x.NavigationBar.ShadowImage = new UIImage());
        }
Ejemplo n.º 4
0
        public SourceTreeViewController(
            string username,
            string repository,
            string path,
            string sha,
            ShaType shaType,
            IApplicationService applicationService = null,
            IFeaturesService featuresService       = null)
            : base(style: UITableViewStyle.Plain)
        {
            _username   = username;
            _repository = repository;
            _path       = path;
            _sha        = sha;
            _shaType    = shaType;

            _addFileCommand = ReactiveCommand.Create(
                ShowAddSource,
                this.WhenAnyValue(x => x.CanAddFile, x => x.ShaType)
                .Select(x => x.Item1 && x.Item2 == ShaType.Branch));

            applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();
            featuresService    = featuresService ?? Locator.Current.GetService <IFeaturesService>();

            _loadContents = ReactiveCommand.CreateFromTask(async(string shaRef) =>
            {
                if (ShaType == ShaType.Branch)
                {
                    var repo   = await applicationService.GitHubClient.Repository.Get(username, repository);
                    CanAddFile = repo.Permissions.Push;
                }
                else
                {
                    CanAddFile = false;
                }

                var encodedShaRef = System.Web.HttpUtility.UrlEncode(shaRef);

                if (string.IsNullOrEmpty(path))
                {
                    return(await applicationService
                           .GitHubClient.Repository.Content
                           .GetAllContentsByRef(username, repository, encodedShaRef));
                }

                return(await applicationService
                       .GitHubClient.Repository.Content
                       .GetAllContentsByRef(username, repository, path, encodedShaRef));
            });

            var addFileButton = new UIBarButtonItem(UIBarButtonSystemItem.Add);

            NavigationItem.RightBarButtonItem = addFileButton;

            _loadContents
            .ThrownExceptions
            .Do(_ => SetErrorView())
            .Select(HandleLoadError)
            .SelectMany(Interactions.Errors.Handle)
            .Subscribe();

            OnActivation(d =>
            {
                d(_titleView
                  .GetClickedObservable()
                  .Subscribe(_ => ShowBranchSelector()));

                d(_addFileCommand
                  .CanExecute
                  .Subscribe(x => addFileButton.Enabled = x));

                d(addFileButton
                  .GetClickedObservable()
                  .Select(_ => Unit.Default)
                  .InvokeReactiveCommand(_addFileCommand));
            });

            Appearing
            .Select(_ => _sha)
            .Where(x => !string.IsNullOrEmpty(x))
            .DistinctUntilChanged()
            .Do(_ => SetLoading(true))
            .InvokeReactiveCommand(_loadContents);

            _loadContents
            .Do(_ => SetLoading(false))
            .Subscribe(SetElements);

            NavigationItem.TitleView = _titleView;
        }