Exemplo n.º 1
0
        protected MarkdownComposerViewModel(IStatusIndicatorService status, IAlertDialogService alert, IJsonHttpClientService jsonClient)
        {
            var saveCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Text).Select(x => !string.IsNullOrEmpty(x)),
                t => Save());

            saveCommand.IsExecuting.Where(x => x).Subscribe(_ => status.Show("Saving..."));
            saveCommand.IsExecuting.Where(x => !x).Subscribe(_ => status.Hide());
            saveCommand.Subscribe(x => DismissCommand.ExecuteIfCan());
            SaveCommand = saveCommand;

            PostToImgurCommand =
                ReactiveCommand.CreateAsyncTask(async data =>
            {
                var uploadData = data as byte[];
                if (uploadData == null)
                {
                    throw new Exception("There is no data to upload!");
                }

                return(await jsonClient.Post <ImgurModel>("https://api.imgur.com/3/image",
                                                          new { image = Convert.ToBase64String(uploadData) },
                                                          new Dictionary <string, string> {
                    { "Authorization", "Client-ID " + AuthorizationClientId }
                }));
            });

            PostToImgurCommand.IsExecuting.Where(x => x).Subscribe(_ => status.Show("Uploading..."));
            PostToImgurCommand.IsExecuting.Where(x => !x).Subscribe(_ => status.Hide());
            PostToImgurCommand.ThrownExceptions.SubscribeSafe(e => alert.Alert("Error", "Unable to upload image: " + e.Message));
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            MainImageView.Image = Images.PurchaseIcon;
            MainImageView.Layer.CornerRadius  = 32f;
            MainImageView.Layer.MasksToBounds = true;

            PurchaseButton.SetBackgroundImage(Images.GreyButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);
            PurchaseButton.Layer.ShadowColor   = UIColor.Black.CGColor;
            PurchaseButton.Layer.ShadowOffset  = new CGSize(0, 1);
            PurchaseButton.Layer.ShadowOpacity = 0.3f;
            PurchaseButton.TouchUpInside      += (sender, e) => ViewModel.PurchaseCommand.ExecuteIfCan();

            CancelButton.TouchUpInside  += (sender, e) => ViewModel.DismissCommand.ExecuteIfCan();
            RestoreButton.TouchUpInside += (sender, e) => ViewModel.RestoreCommand.ExecuteIfCan();

            Observable.Merge(ViewModel.PurchaseCommand.IsExecuting, ViewModel.RestoreCommand.IsExecuting).Skip(1).Subscribe(x =>
            {
                if (x)
                {
                    _statusIndicatorService.Show("Enabling...");
                }
                else
                {
                    _statusIndicatorService.Hide();
                }
            });

            ViewModel.WhenAnyValue(x => x.Price)
            .Where(x => x != null)
            .Subscribe(x => PurchaseButton.SetTitle("Purchase! (" + x + ")", UIControlState.Normal));
        }
Exemplo n.º 3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ViewModel.WhenAnyValue(x => x.Username).Subscribe(x => User.Text     = x);
            ViewModel.WhenAnyValue(x => x.Password).Subscribe(x => Password.Text = x);
            ViewModel.WhenAnyValue(x => x.Domain).Subscribe(x => Domain.Text     = x);

            User.EditingChanged += (sender, args) =>
                                   ViewModel.Username = User.Text;
            Password.EditingChanged += (sender, args) =>
                                       ViewModel.Password = Password.Text;
            Domain.EditingChanged += (sender, args) =>
                                     ViewModel.Domain = Domain.Text;

            LoginButton.TouchUpInside += (sender, args) => ViewModel.LoginCommand.Execute(null);

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

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

            LoginButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
            LoginButton.SetBackgroundImage(Images.GreyButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal);

            //Set some generic shadowing
            LoginButton.Layer.ShadowColor   = UIColor.Black.CGColor;
            LoginButton.Layer.ShadowOffset  = new SizeF(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 SizeF(View.Frame.Width, LoginButton.Frame.Bottom + 10f);
        }
Exemplo n.º 4
0
        private async void UploadImage(UIImage img)
        {
            _statusIndicatorService.Show("Uploading...");

            try
            {
                var returnData = await Task.Run <byte[]>(() =>
                {
                    using (var w = new WebClient())
                    {
                        var data         = img.AsJPEG();
                        byte[] dataBytes = new byte[data.Length];
                        System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));

                        w.Headers.Set("Authorization", "Client-ID aa5d7d0bc1dffa6");

                        var values = new NameValueCollection
                        {
                            { "image", Convert.ToBase64String(dataBytes) }
                        };

                        return(w.UploadValues("https://api.imgur.com/3/image", values));
                    }
                });


                var json       = IoC.Resolve <IJsonSerializationService>();
                var imgurModel = json.Deserialize <ImgurModel>(System.Text.Encoding.UTF8.GetString(returnData));
                TextView.InsertText("![](" + imgurModel.Data.Link + ")");
            }
            catch (Exception e)
            {
                _alertDialogService.Alert("Error", "Unable to upload image: " + e.Message);
            }
            finally
            {
                _statusIndicatorService.Hide();
            }
        }
Exemplo n.º 5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

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

            foreach (var c in Foundation.NSHttpCookieStorage.SharedStorage.Cookies)
            {
                Foundation.NSHttpCookieStorage.SharedStorage.DeleteCookie(c);
            }
            Foundation.NSUrlCache.SharedCache.RemoveAllCachedResponses();
            Web.LoadRequest(new Foundation.NSUrlRequest(new Foundation.NSUrl(ViewModel.LoginUrl)));
        }
Exemplo n.º 6
0
        public override void ViewDidLoad()
        {
            Title = "Login";
            NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, (s, e) => ShowExtraMenu());

            base.ViewDidLoad();

            if (!ViewModel.IsEnterprise || ViewModel.AttemptedAccount != null)
            {
                LoadRequest();
            }

            ViewModel.LoginCommand.IsExecuting.Skip(1).Subscribe(x =>
            {
                if (x)
                {
                    _statusIndicatorService.Show("Logging in...");
                }
                else
                {
                    _statusIndicatorService.Hide();
                }
            });
        }
Exemplo n.º 7
0
 public static IDisposable Activate(this IStatusIndicatorService @this, string text)
 {
     @this.Show(text);
     return(Disposable.Create(@this.Hide));
 }
Exemplo n.º 8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var updatedGistObservable = ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null);

            var headerSection = new Section(HeaderView);
            var filesSection  = new Section("Files");

            var split    = new SplitButtonElement();
            var files    = split.AddButton("Files", "-");
            var comments = split.AddButton("Comments", "-");
            var forks    = split.AddButton("Forks", "-");

            headerSection.Add(split);

            var commentsSection = new Section("Comments");
            var commentsElement = new WebElement("comments");

            commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan;
            commentsSection.Add(commentsElement);

            var detailsSection = new Section();
            var splitElement1  = new SplitElement();

            splitElement1.Button1 = new SplitElement.SplitButton(Images.Locked, string.Empty);
            splitElement1.Button2 = new SplitElement.SplitButton(Images.Language, string.Empty);
            detailsSection.Add(splitElement1);

            var splitElement2 = new SplitElement();

            splitElement2.Button1 = new SplitElement.SplitButton(Images.Update, string.Empty);
            splitElement2.Button2 = new SplitElement.SplitButton(Images.Star2, string.Empty);
            detailsSection.Add(splitElement2);

            var owner = new StyledStringElement("Owner", string.Empty)
            {
                Image = Images.Person
            };

            owner.Tapped += () => ViewModel.GoToUserCommand.ExecuteIfCan();
            detailsSection.Add(owner);

            updatedGistObservable.SubscribeSafe(x =>
            {
                var publicGist    = x.Public.HasValue && x.Public.Value;
                var revisionCount = x.History == null ? 0 : x.History.Count;

                splitElement1.Button1.Text  = publicGist ? "Public" : "Private";
                splitElement1.Button1.Image = publicGist ? Images.Unlocked : Images.Locked;
                splitElement1.Button2.Text  = revisionCount + " Revisions";
                splitElement2.Button1.Text  = x.UpdatedAt.ToLocalTime().ToString("MM/dd/yy");
            });

            updatedGistObservable.SubscribeSafe(x =>
            {
                if (x.Owner == null)
                {
                    owner.Value     = "Anonymous";
                    owner.Accessory = UITableViewCellAccessory.None;
                }
                else
                {
                    owner.Value     = x.Owner.Login;
                    owner.Accessory = UITableViewCellAccessory.DisclosureIndicator;
                }

                Root.Reload(owner);
            });

            ViewModel.WhenAnyValue(x => x.IsStarred).Where(x => x.HasValue).Subscribe(x =>
            {
                splitElement2.Button2.Text  = x.Value ? "Starred!" : "Unstarred";
                splitElement2.Button2.Image = x.Value ? Images.Star : Images.Star2;
            });

            Root.Reset(headerSection, detailsSection, filesSection);

            updatedGistObservable.SubscribeSafe(x =>
            {
                HeaderView.SubText = x.Description;
                if (x.Owner != null)
                {
                    HeaderView.ImageUri = x.Owner.AvatarUrl;
                }
                Root.Reload(headerSection);
            });

            updatedGistObservable.Select(x => x.Files == null ? 0 : x.Files.Count()).SubscribeSafe(x => files.Text = x.ToString());
            updatedGistObservable.SubscribeSafe(x => comments.Text = x.Comments.ToString());
            updatedGistObservable.Select(x => x.Forks == null ? 0 : x.Forks.Count()).SubscribeSafe(x => forks.Text = x.ToString());

            updatedGistObservable.Subscribe(x =>
            {
                var elements = new List <Element>();
                foreach (var file in x.Files.Keys)
                {
                    var sse = new StyledStringElement(file, x.Files[file].Size + " bytes", UITableViewCellStyle.Subtitle)
                    {
                        Accessory     = UITableViewCellAccessory.DisclosureIndicator,
                        LineBreakMode = UILineBreakMode.TailTruncation,
                        Lines         = 1
                    };

                    var fileSaved     = file;
                    var gistFileModel = x.Files[fileSaved];

                    //              if (string.Equals(gistFileModel.Language, "markdown", StringComparison.OrdinalIgnoreCase))
                    //                  sse.Tapped += () => ViewModel.GoToViewableFileCommand.Execute(gistFileModel);
                    //              else
                    sse.Tapped += () => ViewModel.GoToFileSourceCommand.Execute(gistFileModel);
                    elements.Add(sse);
                }

                filesSection.Reset(elements);
            });
//
//            updatedGistObservable.Take(1).Subscribe(_ => Root.Add(filesSection));


            ViewModel.Comments.Changed.Subscribe(_ =>
            {
                var commentModels = ViewModel.Comments.Select(x =>
                                                              new Comment(x.User.AvatarUrl, x.User.Login, x.BodyHtml, x.CreatedAt.ToDaysAgo()));
                var razorView = new CommentsView {
                    Model = commentModels
                };
                var html = razorView.GenerateString();
                commentsElement.Value = html;
            });

            ViewModel.Comments.Changed.Take(1).Select(x => ViewModel.Comments).Where(x => x.Count > 0)
            .Subscribe(_ => Root.Insert(Root.Count, commentsSection));


            ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null).Subscribe(gist =>
            {
                if (string.Equals(_applicationService.Account.Username, ViewModel.Gist.Owner.Login, StringComparison.OrdinalIgnoreCase))
                {
                    NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Compose, (s, e) => { });

//                              try
//					{
//						var data = await this.DoWorkAsync("Loading...", () => app.Client.ExecuteAsync(app.Client.Gists[ViewModel.Id].Get()));
//						var gistController = new EditGistController(data.Data);
//						gistController.Created = editedGist => ViewModel.Gist = editedGist;
//						var navController = new UINavigationController(gistController);
//						PresentViewController(navController, true, null);
//
//					}
//					catch (Exception ex)
//					{
//						MonoTouch.Utilities.ShowAlert("Error", ex.Message);
//					}
                }
                else
                {
                    NavigationItem.RightBarButtonItem =
                        new UIBarButtonItem(Theme.CurrentTheme.ForkButton, UIBarButtonItemStyle.Plain, (s, e) =>
                                            ViewModel.ForkCommand.ExecuteIfCan());
                    NavigationItem.RightBarButtonItem.EnableIfExecutable(ViewModel.ForkCommand.CanExecuteObservable);
                }
            });

            ViewModel.ForkCommand.IsExecuting.Subscribe(x =>
            {
                if (x)
                {
                    _statusIndicatorService.Show("Forking...");
                }
                else
                {
                    _statusIndicatorService.Hide();
                }
            });
        }
Exemplo n.º 9
0
        public override void ViewDidLoad()
        {
            Title = "Login";
            NavigationItem.LeftBarButtonItem = new UIBarButtonItem(Images.BackButton, UIBarButtonItemStyle.Plain, (s, e) => ViewModel.DismissCommand.ExecuteIfCan());

            base.ViewDidLoad();

            ViewModel.LoginCommand.IsExecuting.Skip(1).Subscribe(x =>
            {
                if (x)
                {
                    _statusIndicatorService.Show("Logging in...");
                }
                else
                {
                    _statusIndicatorService.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.ValueChanged += (sender, args) => ViewModel.Username = User.Text;
            ViewModel.WhenAnyValue(x => x.Username).Subscribe(x => User.Text = x);

            Password.ValueChanged += (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();



            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 SizeF(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 SizeF(View.Frame.Width, LoginButton.Frame.Bottom + 10f);
        }
Exemplo n.º 10
0
        public GistViewModel(IApplicationService applicationService, IShareService shareService,
                             IActionMenuService actionMenuService, IStatusIndicatorService statusIndicatorService)
        {
            Comments = new ReactiveList <GistCommentModel>();

            Title = "Gist";

            GoToUrlCommand = this.CreateUrlCommand();

            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(_ => shareService.ShareUrl(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         = CreateViewModel <GistViewModel>();
                vm.Id          = forkedGist.Id;
                vm.Gist        = forkedGist;
                ShowViewModel(vm);
            });

            ForkCommand.IsExecuting.Subscribe(x =>
            {
                if (x)
                {
                    statusIndicatorService.Show("Forking...");
                }
                else
                {
                    statusIndicatorService.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(this.ShowWebBrowser);

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

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

            AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm = CreateViewModel <GistCommentViewModel>();
                vm.Id  = Id;
                vm.CommentAdded.Subscribe(Comments.Add);
                ShowViewModel(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).FireAndForget();
                Comments.SimpleCollectionLoad(applicationService.Client.Gists[Id].GetComments(), forceCacheInvalidation).FireAndForget();
                return(t1);
            });
        }
Exemplo n.º 11
0
        public LoginViewModel(ILoginService loginFactory,
                              IAccountsService accountsService,
                              IActionMenuService actionMenuService,
                              IStatusIndicatorService statusIndicatorService,
                              IAlertDialogService alertDialogService)
        {
            _loginFactory = loginFactory;

            Title = "Login";

            GoToOldLoginWaysCommand = ReactiveCommand.Create();
            GoToOldLoginWaysCommand.Subscribe(_ => ShowViewModel(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)
                {
                    statusIndicatorService.Show("Logging in...");
                }
                else
                {
                    statusIndicatorService.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 => DismissCommand.ExecuteIfCan());
        }
Exemplo n.º 12
0
 private void EnablePushNotifications(object sender, EventArgs e)
 {
     _statusIndicatorService.Show("Enabling...");
     _featuresService.Activate(FeatureIds.EnterpriseSupport);
 }
Exemplo n.º 13
0
        public override void ViewDidLoad()
        {
            Title = "Edit Issue";

            base.ViewDidLoad();

            NavigationItem.RightBarButtonItem = new UIBarButtonItem(Theme.CurrentTheme.SaveButton, UIBarButtonItemStyle.Plain, (s, e) => {
                View.EndEditing(true);
                ViewModel.SaveCommand.ExecuteIfCan();
            });
            NavigationItem.RightBarButtonItem.EnableIfExecutable(ViewModel.SaveCommand.CanExecuteObservable);

            var title = new InputElement("Title", string.Empty, string.Empty);

            title.Changed += (sender, e) => ViewModel.Title = title.Value;

            var assignedTo = new StyledStringElement("Responsible", "Unassigned", UITableViewCellStyle.Value1);

            assignedTo.Accessory = UITableViewCellAccessory.DisclosureIndicator;
            assignedTo.Tapped   += () => ViewModel.GoToAssigneeCommand.Execute(null);

            var milestone = new StyledStringElement("Milestone", "None", UITableViewCellStyle.Value1);

            milestone.Accessory = UITableViewCellAccessory.DisclosureIndicator;
            milestone.Tapped   += () => ViewModel.GoToMilestonesCommand.Execute(null);

            var labels = new StyledStringElement("Labels", "None", UITableViewCellStyle.Value1);

            labels.Accessory = UITableViewCellAccessory.DisclosureIndicator;
            labels.Tapped   += () => ViewModel.GoToLabelsCommand.Execute(null);

            var content = new MultilinedElement("Description");

            content.Tapped += () => ViewModel.GoToDescriptionCommand.ExecuteIfCan();

            var state = new BooleanElement("Open", true);

            state.ValueChanged += (sender, e) => ViewModel.IsOpen = state.Value;

            ViewModel.WhenAnyValue(x => x.Issue.Title).Subscribe(x => title.Value = x);
            ViewModel.WhenAnyValue(x => x.Content).Subscribe(x => content.Value   = x);

            ViewModel.WhenAnyValue(x => x.AssignedTo).Subscribe(x => {
                assignedTo.Value = x == null ? "Unassigned" : x.Login;
                if (assignedTo.GetRootElement() != null)
                {
                    Root.Reload(assignedTo, UITableViewRowAnimation.None);
                }
            });

            ViewModel.WhenAnyValue(x => x.Milestone).Subscribe(x => {
                milestone.Value = x == null ? "None" : x.Title;
                if (assignedTo.GetRootElement() != null)
                {
                    Root.Reload(milestone, UITableViewRowAnimation.None);
                }
            });

            ViewModel.WhenAnyValue(x => x.Labels).Subscribe(x =>
            {
                labels.Value = (ViewModel.Labels == null && ViewModel.Labels.Length == 0) ?
                               "None" : string.Join(", ", ViewModel.Labels.Select(i => i.Name));

                if (assignedTo.GetRootElement() != null)
                {
                    Root.Reload(labels, UITableViewRowAnimation.None);
                }
            });

            ViewModel.WhenAnyValue(x => x.IsOpen).Subscribe(x =>
            {
                state.Value = x;
                if (assignedTo.GetRootElement() != null)
                {
                    Root.Reload(state, UITableViewRowAnimation.None);
                }
            });

            ViewModel.SaveCommand.IsExecuting.Subscribe(x =>
            {
                if (x)
                {
                    _statusIndicatorService.Show("Updating...");
                }
                else
                {
                    _statusIndicatorService.Hide();
                }
            });

            Root.Reset(new Section {
                title, assignedTo, milestone, labels
            }, new Section {
                state
            }, new Section {
                content
            });
        }
Exemplo n.º 14
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = string.Format("Gist #{0}", ViewModel.Id);
            var updatedGistObservable = ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null);

            var headerSection   = new Section(HeaderView);
            var filesSection    = new Section("Files");
            var commentsSection = new Section("Comments");

            var split    = new SplitButtonElement();
            var files    = split.AddButton("Files", "-", () => {});
            var comments = split.AddButton("Comments", "-", () => {});
            var forks    = split.AddButton("Forks", "-", () => ViewModel.GoToForksCommand.ExecuteIfCan());

            headerSection.Add(split);

            Root.Reset(headerSection, filesSection, commentsSection);

            updatedGistObservable.SubscribeSafe(x =>
            {
                HeaderView.SubText = x.Description;
                if (x.Owner != null)
                {
                    HeaderView.ImageUri = x.Owner.AvatarUrl;
                }
                ReloadData();
            });

            updatedGistObservable.SubscribeSafe(x => files.Text    = x.Files.Count.ToString());
            updatedGistObservable.SubscribeSafe(x => comments.Text = x.Comments.ToString());
            updatedGistObservable.SubscribeSafe(x => forks.Text    = x.Forks.Count.ToString());
            //updatedGistObservable.Take(1).SubscribeSafe(x => detailsSection.Visible = !string.IsNullOrEmpty(x.Description));


//            var splitElement1 = new SplitElement();
//            detailsSection.Add(splitElement1);
//
//            updatedGistObservable.Subscribe(x =>
//            {
//                splitElement1.Button1 = new SplitElement.SplitButton(x.Public.HasValue && x.Public.Value ? Images.Unlocked : Images.Locked, model.Private ? "Private" : "Public");
//                splitElement1.Button2 = new SplitElement.SplitButton(Images.Language, model.Language ?? "N/A");
//            });

//            updatedGistObservable.Take(1).Subscribe(_ => root.Add(detailsSection));
//
//
            updatedGistObservable.Subscribe(x =>
            {
                var elements = new List <Element>();
                foreach (var file in x.Files.Keys)
                {
                    var sse = new StyledStringElement(file, x.Files[file].Size + " bytes", UITableViewCellStyle.Subtitle)
                    {
                        Accessory     = UITableViewCellAccessory.DisclosureIndicator,
                        LineBreakMode = UILineBreakMode.TailTruncation,
                        Lines         = 1
                    };

                    var fileSaved     = file;
                    var gistFileModel = x.Files[fileSaved];

                    //              if (string.Equals(gistFileModel.Language, "markdown", StringComparison.OrdinalIgnoreCase))
                    //                  sse.Tapped += () => ViewModel.GoToViewableFileCommand.Execute(gistFileModel);
                    //              else
                    sse.Tapped += () => ViewModel.GoToFileSourceCommand.Execute(gistFileModel);
                    elements.Add(sse);
                }

                filesSection.Reset(elements);
            });
//
//            updatedGistObservable.Take(1).Subscribe(_ => Root.Add(filesSection));

//
//            ViewModel.Comments.Changed.Subscribe(_ =>
//            {
//                foreach (var comment in ViewModel.Comments)
//                {
//                    var el = new NameTimeStringElement
//                    {
//                        Name = "Anonymous",
//                        Image = Theme.CurrentTheme.AnonymousUserImage,
//                        String = comment.Body,
//                        Time = comment.CreatedAt.ToDaysAgo(),
//                    };
//
//                    if (comment.User != null)
//                    {
//                        el.Name = comment.User.Login;
//                        el.ImageUri = new Uri(comment.User.AvatarUrl);
//                    }
//
//                    commentsSection.Add(el);
//                }
//            });
//
//            ViewModel.Comments.Changed.Skip(1).Take(1).Subscribe(_ => Root.Insert(Root.Count, commentsSection));

//
            //Sometimes there's no user!
//            d.Name = (model.Owner == null) ? "Anonymous" : model.Owner.Login;
//            d.ImageUri = (model.Owner == null) ? null : new Uri(model.Owner.AvatarUrl);
//
//            sec.Add(d);
//
//            var sec2 = new Section("Files");
//            root.Add(sec2);
//
//            if (ViewModel.Comments.Count > 0)
//            {
//                var sec3 = new Section("Comments");
//                foreach (var comment in ViewModel.Comments)
//                {
//                    var el = new NameTimeStringElement
//                    {
//                        Name = "Anonymous",
//                        Image = Theme.CurrentTheme.AnonymousUserImage,
//                        String = comment.Body,
//                        Time = comment.CreatedAt.ToDaysAgo(),
//                    };
//
//                    if (comment.User != null)
//                    {
//                        el.Name = comment.User.Login;
//                        el.ImageUri = new Uri(comment.User.AvatarUrl);
//                    }
//
//                    sec3.Add(el);
//                }
//                root.Add(sec3);
//            }


            ViewModel.WhenAnyValue(x => x.Gist).Where(x => x != null).Subscribe(gist =>
            {
                if (string.Equals(_applicationService.Account.Username, ViewModel.Gist.Owner.Login, StringComparison.OrdinalIgnoreCase))
                {
                    NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Compose, (s, e) => { });

//                              try
//					{
//						var data = await this.DoWorkAsync("Loading...", () => app.Client.ExecuteAsync(app.Client.Gists[ViewModel.Id].Get()));
//						var gistController = new EditGistController(data.Data);
//						gistController.Created = editedGist => ViewModel.Gist = editedGist;
//						var navController = new UINavigationController(gistController);
//						PresentViewController(navController, true, null);
//
//					}
//					catch (Exception ex)
//					{
//						MonoTouch.Utilities.ShowAlert("Error", ex.Message);
//					}
                }
                else
                {
                    NavigationItem.RightBarButtonItem =
                        new UIBarButtonItem(Theme.CurrentTheme.ForkButton, UIBarButtonItemStyle.Plain, (s, e) =>
                                            ViewModel.ForkCommand.ExecuteIfCan());
                    NavigationItem.RightBarButtonItem.EnableIfExecutable(ViewModel.ForkCommand.CanExecuteObservable);
                }
            });


//            ViewModel.WhenAnyValue(x => x.IsStarred).Subscribe(isStarred =>
//            {
//                _starButton.Enabled = isStarred.HasValue;
//                _starButton.SetImage((isStarred.HasValue && isStarred.Value) ? Images.Gist.StarHighlighted : Images.Gist.Star, UIControlState.Normal);
//                _starButton.SetNeedsDisplay();
//            });
//
            ViewModel.ForkCommand.IsExecuting.Subscribe(x =>
            {
                if (x)
                {
                    _statusIndicatorService.Show("Forking...");
                }
                else
                {
                    _statusIndicatorService.Hide();
                }
            });
        }