Esempio n. 1
0
 public static IDisposable AlertExecuting(this IReactiveCommand @this, IAlertDialogFactory dialogFactory, string text)
 {
     return @this.IsExecuting.Subscribe(x => {
         if (x)
             dialogFactory.Show(text);
         else
             dialogFactory.Hide();
     });
 }
Esempio n. 2
0
 public static IDisposable AlertExecuting(this IReactiveCommand @this, IAlertDialogFactory dialogFactory, string text)
 {
     return(@this.IsExecuting.Subscribe(x => {
         if (x)
         {
             dialogFactory.Show(text);
         }
         else
         {
             dialogFactory.Hide();
         }
     }));
 }
Esempio n. 3
0
 public static IDisposable Activate(this IAlertDialogFactory @this, IReactiveCommand command, string text)
 {
     return(command.IsExecuting.Subscribe(x => {
         if (x)
         {
             @this.Show(text);
         }
         else
         {
             @this.Hide();
         }
     }));
 }
Esempio n. 4
0
 public static IDisposable Activate(this IAlertDialogFactory @this, IObservable <bool> observable, string text)
 {
     return(observable.Subscribe(x => {
         if (x)
         {
             @this.Show(text);
         }
         else
         {
             @this.Hide();
         }
     }));
 }
Esempio n. 5
0
 void HandlePurchaseError(object sender, Exception e)
 {
     _alertDialogFactory.Hide();
 }
Esempio n. 6
0
        public GistViewModel(
            ISessionService sessionService, 
            IActionMenuFactory actionMenuService, 
            IAlertDialogFactory alertDialogFactory) 
        {
            Comments = new ReactiveList<GistCommentModel>();

            Title = "Gist";

            this.WhenAnyValue(x => x.Gist).Where(x => x != null && x.Files != null && x.Files.Count > 0)
                .Select(x => x.Files.First().Key).Subscribe(x => 
                    Title = x);

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null));
            ShareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, new Uri(Gist.HtmlUrl)));

            this.WhenAnyValue(x => x.Gist.Owner.AvatarUrl)
                .Select(x => new GitHubAvatar(x))
                .ToProperty(this, x => x.Avatar, out _avatar);

            ToggleStarCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue),
                async t =>
            {
                try
                {
                    if (!IsStarred.HasValue) return;
                    var request = IsStarred.Value ? sessionService.Client.Gists[Id].Unstar() : sessionService.Client.Gists[Id].Star();
                    await sessionService.Client.ExecuteAsync(request);
                    IsStarred = !IsStarred.Value;
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to start gist. Please try again.", e);
                }
            });

            ForkCommand = ReactiveCommand.CreateAsyncTask(async t => {
                var gist = await sessionService.GitHubClient.Gist.Fork(Id);
                var vm = this.CreateViewModel<GistViewModel>();
                vm.Id = gist.Id;
                vm.Gist = gist;
                NavigateTo(vm);
            });

            ForkCommand.IsExecuting.Subscribe(x =>
            {
                if (x)
                    alertDialogFactory.Show("Forking...");
                else
                    alertDialogFactory.Hide();
            });

            GoToEditCommand = ReactiveCommand.Create();
            GoToEditCommand.Subscribe(_ =>
            {
                var vm = this.CreateViewModel<GistEditViewModel>();
                vm.Gist = Gist;
                vm.SaveCommand.Subscribe(x => Gist = x);
                NavigateTo(vm);
            });

            GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl)));
            GoToHtmlUrlCommand
                .Select(_ => this.CreateViewModel<WebBrowserViewModel>())
                .Select(x => x.Init(Gist.HtmlUrl))
                .Subscribe(NavigateTo);

            GoToFileSourceCommand = ReactiveCommand.Create();
            GoToFileSourceCommand.OfType<GistFile>().Subscribe(x =>
            {
                var vm = this.CreateViewModel<GistFileViewModel>();
                vm.Id = Id;
                vm.GistFile = x;
                vm.Filename = x.Filename;
                NavigateTo(vm);
            });

            GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && x.Owner != null));
            GoToOwnerCommand
                .Select(_ => this.CreateViewModel<UserViewModel>())
                .Select(x => x.Init(Gist.Owner.Login))
                .Subscribe(NavigateTo);

            AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ =>
                NavigateTo(new ComposerViewModel("Add Comment", async x => {
                    var request = sessionService.Client.Gists[Id].CreateGistComment(x);
                    Comments.Add((await sessionService.Client.ExecuteAsync(request)).Data);
                }, alertDialogFactory)));

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Gist).Select(x => x != null), 
                sender => {
                    var menu = actionMenuService.Create();
                    if (Gist.Owner != null && string.Equals(sessionService.Account.Username, Gist.Owner.Login, StringComparison.OrdinalIgnoreCase))
                        menu.AddButton("Edit", GoToEditCommand);
                    else
                        menu.AddButton("Fork", ForkCommand);
                    menu.AddButton("Share", ShareCommand);
                    menu.AddButton("Show in GitHub", GoToHtmlUrlCommand);
                    return menu.Show(sender);
                });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                sessionService.GitHubClient.Gist.IsStarred(Id).ToBackground(x => IsStarred = x);
			    Comments.SimpleCollectionLoad(sessionService.Client.Gists[Id].GetComments());
                Gist = await sessionService.GitHubClient.Gist.Get(Id);
            });
        }
Esempio n. 7
0
        public GistViewModel(
            ISessionService sessionService,
            IActionMenuFactory actionMenuService,
            IAlertDialogFactory alertDialogFactory)
        {
            Comments = new ReactiveList <GistCommentModel>();

            Title = "Gist";

            this.WhenAnyValue(x => x.Gist).Where(x => x != null && x.Files != null && x.Files.Count > 0)
            .Select(x => x.Files.First().Key).Subscribe(x =>
                                                        Title = x);

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null));
            ShareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, new Uri(Gist.HtmlUrl)));

            this.WhenAnyValue(x => x.Gist.Owner.AvatarUrl)
            .Select(x => new GitHubAvatar(x))
            .ToProperty(this, x => x.Avatar, out _avatar);

            ToggleStarCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue),
                async t =>
            {
                try
                {
                    if (!IsStarred.HasValue)
                    {
                        return;
                    }
                    var request = IsStarred.Value ? sessionService.Client.Gists[Id].Unstar() : sessionService.Client.Gists[Id].Star();
                    await sessionService.Client.ExecuteAsync(request);
                    IsStarred = !IsStarred.Value;
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to start gist. Please try again.", e);
                }
            });

            ForkCommand = ReactiveCommand.CreateAsyncTask(async t => {
                var gist = await sessionService.GitHubClient.Gist.Fork(Id);
                var vm   = this.CreateViewModel <GistViewModel>();
                vm.Id    = gist.Id;
                vm.Gist  = gist;
                NavigateTo(vm);
            });

            ForkCommand.IsExecuting.Subscribe(x =>
            {
                if (x)
                {
                    alertDialogFactory.Show("Forking...");
                }
                else
                {
                    alertDialogFactory.Hide();
                }
            });

            GoToEditCommand = ReactiveCommand.Create();
            GoToEditCommand.Subscribe(_ =>
            {
                var vm  = this.CreateViewModel <GistEditViewModel>();
                vm.Gist = Gist;
                vm.SaveCommand.Subscribe(x => Gist = x);
                NavigateTo(vm);
            });

            GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl)));
            GoToHtmlUrlCommand
            .Select(_ => this.CreateViewModel <WebBrowserViewModel>())
            .Select(x => x.Init(Gist.HtmlUrl))
            .Subscribe(NavigateTo);

            GoToFileSourceCommand = ReactiveCommand.Create();
            GoToFileSourceCommand.OfType <GistFile>().Subscribe(x =>
            {
                var vm      = this.CreateViewModel <GistFileViewModel>();
                vm.Id       = Id;
                vm.GistFile = x;
                vm.Filename = x.Filename;
                NavigateTo(vm);
            });

            GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist.Owner).Select(x => x != null));
            GoToOwnerCommand
            .Select(_ => this.CreateViewModel <UserViewModel>())
            .Select(x => x.Init(Gist.Owner.Login))
            .Subscribe(NavigateTo);

            AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ =>
                                                                          NavigateTo(new ComposerViewModel("Add Comment", async x => {
                var request = sessionService.Client.Gists[Id].CreateGistComment(x);
                Comments.Add((await sessionService.Client.ExecuteAsync(request)).Data);
            }, alertDialogFactory)));

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Gist).Select(x => x != null),
                sender => {
                var menu = actionMenuService.Create();
                if (Gist.Owner != null && string.Equals(sessionService.Account.Username, Gist.Owner.Login, StringComparison.OrdinalIgnoreCase))
                {
                    menu.AddButton("Edit", GoToEditCommand);
                }
                else
                {
                    menu.AddButton("Fork", ForkCommand);
                }
                menu.AddButton("Share", ShareCommand);
                menu.AddButton("Show in GitHub", GoToHtmlUrlCommand);
                return(menu.Show(sender));
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                sessionService.GitHubClient.Gist.IsStarred(Id).ToBackground(x => IsStarred = x);
                Comments.SimpleCollectionLoad(sessionService.Client.Gists[Id].GetComments());
                Gist = await sessionService.GitHubClient.Gist.Get(Id);
            });
        }
Esempio n. 8
0
        public GistViewModel(IApplicationService applicationService,
                             IActionMenuFactory actionMenuService, IAlertDialogFactory alertDialogFactory)
        {
            Comments = new ReactiveList <GistCommentModel>();

            Title = "Gist";

            this.WhenAnyValue(x => x.Gist).Where(x => x != null && x.Files != null && x.Files.Count > 0)
            .Select(x => x.Files.First().Key).Subscribe(x =>
                                                        Title = x);

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null));
            ShareCommand.Subscribe(_ => actionMenuService.ShareUrl(new Uri(Gist.HtmlUrl)));

            ToggleStarCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue),
                async t =>
            {
                try
                {
                    if (!IsStarred.HasValue)
                    {
                        return;
                    }
                    var request = IsStarred.Value ? applicationService.Client.Gists[Id].Unstar() : applicationService.Client.Gists[Id].Star();
                    await applicationService.Client.ExecuteAsync(request);
                    IsStarred = !IsStarred.Value;
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to start gist. Please try again.", e);
                }
            });

            ForkCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                var data       = await applicationService.Client.ExecuteAsync(applicationService.Client.Gists[Id].ForkGist());
                var forkedGist = data.Data;
                var vm         = this.CreateViewModel <GistViewModel>();
                vm.Id          = forkedGist.Id;
                vm.Gist        = forkedGist;
                NavigateTo(vm);
            });

            ForkCommand.IsExecuting.Subscribe(x =>
            {
                if (x)
                {
                    alertDialogFactory.Show("Forking...");
                }
                else
                {
                    alertDialogFactory.Hide();
                }
            });

            GoToEditCommand = ReactiveCommand.Create();

            GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl)));
            GoToHtmlUrlCommand.Select(_ => Gist.HtmlUrl).Subscribe(x =>
            {
                var vm = this.CreateViewModel <WebBrowserViewModel>();
                vm.Url = x;
                NavigateTo(vm);
            });

            GoToFileSourceCommand = ReactiveCommand.Create();
            GoToFileSourceCommand.OfType <GistFileModel>().Subscribe(x =>
            {
                var vm      = this.CreateViewModel <GistFileViewModel>();
                vm.Id       = Id;
                vm.GistFile = x;
                vm.Filename = x.Filename;
                NavigateTo(vm);
            });

            GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && x.Owner != null));
            GoToOwnerCommand.Subscribe(x =>
            {
                var vm      = this.CreateViewModel <UserViewModel>();
                vm.Username = Gist.Owner.Login;
                NavigateTo(vm);
            });

            AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm = this.CreateViewModel <GistCommentViewModel>();
                vm.Id  = Id;
                vm.SaveCommand.Subscribe(Comments.Add);
                NavigateTo(vm);
            });

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Gist).Select(x => x != null),
                _ =>
            {
                var menu = actionMenuService.Create(Title);
                if (Gist.Owner != null && string.Equals(applicationService.Account.Username, Gist.Owner.Login, StringComparison.OrdinalIgnoreCase))
                {
                    menu.AddButton("Edit", GoToEditCommand);
                }
                else
                {
                    menu.AddButton("Fork", ForkCommand);
                }
                menu.AddButton("Share", ShareCommand);
                menu.AddButton("Show in GitHub", GoToHtmlUrlCommand);
                return(menu.Show());
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var forceCacheInvalidation = t as bool?;
                var t1 = this.RequestModel(applicationService.Client.Gists[Id].Get(), forceCacheInvalidation, response => Gist = response.Data);
                this.RequestModel(applicationService.Client.Gists[Id].IsGistStarred(), forceCacheInvalidation, response => IsStarred = response.Data);
                Comments.SimpleCollectionLoad(applicationService.Client.Gists[Id].GetComments(), forceCacheInvalidation);
                return(t1);
            });
        }
Esempio n. 9
0
        public LoginViewModel(ILoginService loginFactory,
                              IAccountsService accountsService,
                              IActionMenuFactory actionMenuService,
                              IAlertDialogFactory alertDialogService)
        {
            _loginFactory = loginFactory;

            Title = "Login";

            GoToOldLoginWaysCommand = ReactiveCommand.Create().WithSubscription(_ =>
                                                                                NavigateTo(this.CreateViewModel <AddAccountViewModel>()));

            var loginCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Code).Select(x => !string.IsNullOrEmpty(x)), _ => Login(Code));

            loginCommand.Subscribe(x => accountsService.ActiveAccount = x);
            loginCommand.Subscribe(x => MessageBus.Current.SendMessage(new LogoutMessage()));
            LoginCommand = loginCommand;

            ShowLoginOptionsCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var actionMenu = actionMenuService.Create(Title);
                actionMenu.AddButton("Login via BASIC", GoToOldLoginWaysCommand);
                return(actionMenu.Show());
            });

            LoginCommand.IsExecuting.Skip(1).Subscribe(x =>
            {
                if (x)
                {
                    alertDialogService.Show("Logging in...");
                }
                else
                {
                    alertDialogService.Hide();
                }
            });

            _loginUrl = this.WhenAnyValue(x => x.WebDomain)
                        .IsNotNull()
                        .Select(x => x.TrimEnd('/'))
                        .Select(x =>
                                string.Format(x + "/login/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
                                              ClientId, Uri.EscapeDataString(RedirectUri), Uri.EscapeDataString("user,repo,notifications,gist")))
                        .ToProperty(this, x => x.LoginUrl);

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                if (IsEnterprise && string.IsNullOrEmpty(WebDomain))
                {
                    var response = await alertDialogService.PromptTextBox("Enterprise URL",
                                                                          "Please enter the webpage address for the GitHub Enterprise installation",
                                                                          DefaultWebDomain, "Ok");
                    WebDomain = response;
                }
                else
                {
                    WebDomain = DefaultWebDomain;
                }
            });

            LoadCommand.ThrownExceptions.Take(1).Subscribe(x => Dismiss());
        }
Esempio n. 10
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ViewModel.LoginCommand.IsExecuting.Skip(1).Subscribe(x =>
            {
                if (x)
                {
                    _alertDialogService.Show("Logging in...");
                }
                else
                {
                    _alertDialogService.Hide();
                }
            });

            ViewModel.LoginCommand.ThrownExceptions.Subscribe(x =>
            {
                if (x is LoginService.TwoFactorRequiredException)
                {
                    _alertDialogService.PromptTextBox("Two Factor Authentication",
                                                      "This account requires a two factor authentication code", string.Empty, "Ok")
                    .ContinueWith(t =>
                    {
                        ViewModel.TwoFactor = t.Result;
                        ViewModel.LoginCommand.ExecuteIfCan();
                    }, TaskContinuationOptions.OnlyOnRanToCompletion);
                }
            });

            User.EditingChanged += (sender, args) => ViewModel.Username = User.Text;
            ViewModel.WhenAnyValue(x => x.Username).Subscribe(x => User.Text = x);

            Password.EditingChanged += (sender, args) => ViewModel.Password = Password.Text;
            ViewModel.WhenAnyValue(x => x.Password).Subscribe(x => Password.Text = x);

            Domain.ValueChanged += (sender, args) => ViewModel.Domain = Domain.Text;
            ViewModel.WhenAnyValue(x => x.Domain).Subscribe(x => Domain.Text = x);

            LoginButton.TouchUpInside += (sender, args) => ViewModel.LoginCommand.ExecuteIfCan();
            ViewModel.LoginCommand.CanExecuteObservable.Subscribe(x => LoginButton.Enabled = x);

            View.BackgroundColor = UIColor.FromRGB(239, 239, 244);
            Logo.Image           = Images.Logos.GitHub;

            if (ViewModel.IsEnterprise)
            {
                LoginButton.SetTitleColor(UIColor.White, UIControlState.Normal);
                LoginButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);
            }
            else
            {
                LoginButton.SetBackgroundImage(Images.Buttons.GreyButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);

                //Hide the domain, slide everything up
                Domain.Hidden = true;
                var f = User.Frame;
                f.Y       -= 39;
                User.Frame = f;

                var p = Password.Frame;
                p.Y           -= 39;
                Password.Frame = p;

                var l = LoginButton.Frame;
                l.Y -= 39;
                LoginButton.Frame = l;
            }

            //Set some generic shadowing
            LoginButton.Layer.ShadowColor   = UIColor.Black.CGColor;
            LoginButton.Layer.ShadowOffset  = new CGSize(0, 1);
            LoginButton.Layer.ShadowOpacity = 0.3f;

            Domain.ShouldReturn = delegate {
                User.BecomeFirstResponder();
                return(true);
            };

            User.ShouldReturn = delegate {
                Password.BecomeFirstResponder();
                return(true);
            };
            Password.ShouldReturn = delegate {
                Password.ResignFirstResponder();
                LoginButton.SendActionForControlEvents(UIControlEvent.TouchUpInside);
                return(true);
            };


            ScrollView.ContentSize = new CGSize(View.Frame.Width, LoginButton.Frame.Bottom + 10f);
        }