Esempio n. 1
0
        public static IDisposable BindCommand <T>(this StringElement stringElement, IReactiveCommand <T> cmd)
        {
            var d1 = stringElement.Clicked.InvokeCommand(cmd);
            var d2 = cmd.CanExecuteObservable.Subscribe(x => stringElement.SelectionStyle = (x ? null : (UITableViewCellSelectionStyle?)UITableViewCellSelectionStyle.None));

            return(new CompositeDisposable(d1, d2));
        }
Esempio n. 2
0
 public static IDisposable BindDisclosure(this StringElement stringElement, IObservable <bool> value)
 {
     return(value.SubscribeSafe(x => {
         stringElement.SelectionStyle = x ? UITableViewCellSelectionStyle.Blue : UITableViewCellSelectionStyle.None;
         stringElement.Accessory = x ? UITableViewCellAccessory.DisclosureIndicator : UITableViewCellAccessory.None;
     }));
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var vm = (OrganizationViewModel) ViewModel;

            HeaderView.SetImage(null, Images.Avatar);
            Title = vm.Name;
            HeaderView.Text = vm.Name;

            var members = new StringElement("Members", Octicon.Person.ToImage());
            var teams = new StringElement("Teams", Octicon.Organization.ToImage());
            var followers = new StringElement("Followers", Octicon.Heart.ToImage());
            var events = new StringElement("Events", Octicon.Rss.ToImage());
            var repos = new StringElement("Repositories", Octicon.Repo.ToImage());
            var gists = new StringElement("Gists", Octicon.Gist.ToImage());
            Root.Reset(new Section(new UIView(new CGRect(0, 0, 0, 20f))) { members, teams }, new Section { events, followers }, new Section { repos, gists });

            OnActivation(d =>
            {
                d(members.Clicked.BindCommand(vm.GoToMembersCommand));
                d(teams.Clicked.BindCommand(vm.GoToTeamsCommand));
                d(followers.Clicked.BindCommand(vm.GoToFollowersCommand));
                d(events.Clicked.BindCommand(vm.GoToEventsCommand));
                d(repos.Clicked.BindCommand(vm.GoToRepositoriesCommand));
                d(gists.Clicked.BindCommand(vm.GoToGistsCommand));

                d(vm.Bind(x => x.Organization, true).Where(x => x != null).Subscribe(x =>
                {
                    HeaderView.SubText = string.IsNullOrWhiteSpace(x.Name) ? x.Login : x.Name;
                    HeaderView.SetImage(x.AvatarUrl, Images.Avatar);
                    RefreshHeaderView();
                }));
            });
        }
        private async Task LoadLanguages()
        {
            var lRepo = new LanguageRepository();
            var langs = await lRepo.GetLanguages();

            var sec = new Section();

            langs.Insert(0, new Language("All Languages", null));
            sec.AddAll(langs.Select(x =>
            {
                var el = new StringElement(x.Name) { Accessory = UITableViewCellAccessory.None };
                el.Clicked.Subscribe(_ => _languageSubject.OnNext(x));
                return el;
            }));

            Root.Reset(sec);

            if (SelectedLanguage != null)
            {
                var el = sec.Elements.OfType<StringElement>().FirstOrDefault(x => string.Equals(x.Caption, SelectedLanguage.Name));
                if (el != null)
                    el.Accessory = UITableViewCellAccessory.Checkmark;

                var indexPath = el?.IndexPath;
                if (indexPath != null)
                    TableView.ScrollToRow(indexPath, UITableViewScrollPosition.Middle, false);
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            var model = _filterController.Filter.Clone();

            var save = new StringElement("Save as Default") { Accessory = UITableViewCellAccessory.None };
            save.Clicked.Subscribe(_ =>
            {
                _filterController.ApplyFilter(CreateFilterModel(), true);
                CloseViewController();
            });

            //Load the root
            var sections = new [] {
                new Section("Filter") {
                    (_filter = CreateEnumElement("Type", model.FilterType)),
                    (_open = new BooleanElement("Open?", model.Open)),
                    (_labels = new EntryElement("Labels", "bug,ui,@user", model.Labels) { TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None }),
                },
                new Section("Order By") {
                    (_sort = CreateEnumElement("Field", model.SortType)),
                    (_asc = new BooleanElement("Ascending", model.Ascending))
                },
                new Section() {
                    save,
                }
            };

            Root.Reset(sections);
        }
Esempio n. 6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            TableView.RowHeight = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 44f;

            var vm = (IssueAddViewModel)ViewModel;
            var saveButton = new UIBarButtonItem { Image = Images.Buttons.SaveButton };
            NavigationItem.RightBarButtonItem = saveButton;

            var title = new EntryElement("Title", string.Empty, string.Empty);
            var assignedTo = new StringElement("Responsible", "Unassigned", UITableViewCellStyle.Value1);
            var milestone = new StringElement("Milestone", "None", UITableViewCellStyle.Value1);
            var labels = new StringElement("Labels", "None", UITableViewCellStyle.Value1);
            var content = new MultilinedElement("Description");

            Root.Reset(new Section { title, assignedTo, milestone, labels }, new Section { content });

            OnActivation(d =>
            {
                d(vm.Bind(x => x.IssueTitle, true).Subscribe(x => title.Value = x));
                d(title.Changed.Subscribe(x => vm.IssueTitle = x));

                d(vm.Bind(x => x.Content, true).Subscribe(x => content.Details = x));
                d(labels.Clicked.Subscribe(_ => vm.GoToLabelsCommand.Execute(null)));
                d(milestone.Clicked.Subscribe(_ => vm.GoToMilestonesCommand.Execute(null)));
                d(assignedTo.Clicked.Subscribe(_ => vm.GoToAssigneeCommand.Execute(null)));
                d(vm.Bind(x => x.IsSaving).SubscribeStatus("Saving..."));

                d(vm.Bind(x => x.AssignedTo, true).Subscribe(x => {
                    assignedTo.Value = x == null ? "Unassigned" : x.Login;
                }));

                d(vm.Bind(x => x.Milestone, true).Subscribe(x => {
                    milestone.Value = x == null ? "None" : x.Title;
                }));

                d(vm.BindCollection(x => x.Labels, true).Subscribe(_ => {
                    labels.Value = vm.Labels.Items.Count == 0 ? "None" : string.Join(", ", vm.Labels.Items.Select(i => i.Name));
                }));

                d(saveButton.GetClickedObservable().Subscribe(_ => {
                    View.EndEditing(true);
                    vm.SaveCommand.Execute(null);
                }));

                d(content.Clicked.Subscribe(_ => {
                    var composer = new MarkdownComposerViewController { Title = "Issue Description", Text = content.Details };
                    composer.NewComment(this, (text) => {
                        vm.Content = text;
                        composer.CloseComposer();
                    });
                }));
            });
        }
Esempio n. 7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var vm = (ChangesetBranchesViewModel) ViewModel;
            var weakVm = new WeakReference<ChangesetBranchesViewModel>(vm);
            BindCollection(vm.Branches, x => {
                var e = new StringElement(x.Name);
                e.Clicked.Subscribe(_ => weakVm.Get()?.GoToBranchCommand.Execute(x));
                return e;
            });
        }
Esempio n. 8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var vm = (TeamsViewModel) ViewModel;
            var weakVm = new WeakReference<TeamsViewModel>(vm);
            this.BindCollection(vm.Teams, x => {
                var e = new StringElement(x.Name);
                e.Clicked.Subscribe(_ => weakVm.Get()?.GoToTeamCommand.Execute(x));
                return e;
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            var model = _filterController.Filter.Clone();

            var save = new StringElement("Save as Default") { Accessory = UITableViewCellAccessory.None };
            save.Clicked.Subscribe(_ =>
            {
                _filterController.ApplyFilter(CreateFilterModel(), true);
                CloseViewController();
            });

            //Load the root
            var root = new [] {
                new Section("Filter") {
                    (_open = new BooleanElement("Open?", model.Open)),
                    (_labels = new EntryElement("Labels", "bug,ui,@user", model.Labels) { TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None }),
                    (_mentioned = new EntryElement("Mentioned", "User", model.Mentioned) { TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None }),
                    (_creator = new EntryElement("Creator", "User", model.Creator) { TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None }),
                    (_assignee = new EntryElement("Assignee", "User", model.Assignee) { TextAlignment = UITextAlignment.Right, AutocorrectionType = UITextAutocorrectionType.No, AutocapitalizationType = UITextAutocapitalizationType.None }),
                    (_milestone = new StringElement("Milestone", "None", UITableViewCellStyle.Value1)),
                },
                new Section("Order By") {
                    (_sort = CreateEnumElement("Field", model.SortType)),
                    (_asc = new BooleanElement("Ascending", model.Ascending))
                },
                new Section(string.Empty, "Saving this filter as a default will save it only for this repository.") {
                    save
                }
            };

            RefreshMilestone();

            _milestone.Accessory = UITableViewCellAccessory.DisclosureIndicator;
            _milestone.Clicked.Subscribe(_ => {
                var ctrl = new IssueMilestonesFilterViewController(_user, _repo, _milestoneHolder != null);

                ctrl.MilestoneSelected = (title, num, val) => {
                    if (title == null && num == null && val == null)
                        _milestoneHolder = null;
                    else
                        _milestoneHolder = new IssuesFilterModel.MilestoneKeyValue { Name = title, Value = val, IsMilestone = num.HasValue };
                    RefreshMilestone();
                    NavigationController.PopViewController(true);
                };
                NavigationController.PushViewController(ctrl, true);
            });

            Root.Reset(root);
        }
Esempio n. 10
0
        public override void ViewDidLoad()
        {
            Title = "Notifications";

            base.ViewDidLoad();

            _segmentBarButton.Width = View.Frame.Width - 10f;
            ToolbarItems = new [] { new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace), _segmentBarButton, new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace) };

            var checkButton = new UIBarButtonItem { Image = Images.Buttons.CheckButton };
            NavigationItem.RightBarButtonItem = checkButton;

            var vm = (NotificationsViewModel)ViewModel;
            var weakVm = new WeakReference<NotificationsViewModel>(vm);

            BindCollection(vm.Notifications, x =>
            {
                var el = new StringElement(x.Subject.Title, x.UpdatedAt.Humanize(), UITableViewCellStyle.Subtitle) { Accessory = UITableViewCellAccessory.DisclosureIndicator };

                var subject = x.Subject.Type.ToLower();
                if (subject.Equals("issue"))
                    el.Image = Octicon.IssueOpened.ToImage();
                else if (subject.Equals("pullrequest"))
                    el.Image = Octicon.GitPullRequest.ToImage();
                else if (subject.Equals("commit"))
                    el.Image = Octicon.GitCommit.ToImage();
                else if (subject.Equals("release"))
                    el.Image = Octicon.Tag.ToImage();
                else
                    el.Image = Octicon.Alert.ToImage();

                el.Clicked.Subscribe(MakeCallback(weakVm, x));
                return el;
            });

            var o = Observable.FromEventPattern(t => vm.ReadAllCommand.CanExecuteChanged += t, t => vm.ReadAllCommand.CanExecuteChanged -= t);

            OnActivation(d =>
            {
                d(checkButton.GetClickedObservable().BindCommand(vm.ReadAllCommand));
                d(vm.Bind(x => x.IsMarking).SubscribeStatus("Marking..."));
                d(vm.Bind(x => x.ShownIndex, true).Subscribe(x => _viewSegment.SelectedSegment = (nint)x));
                d(_viewSegment.GetChangedObservable().Subscribe(x => vm.ShownIndex = x));
                d(o.Subscribe(_ => NavigationItem.RightBarButtonItem.Enabled = vm.ReadAllCommand.CanExecute(null)));
            });
        }
        public IssueMilestonesFilterViewController(string user, string repo, bool alreadySelected)
            : base(UIKit.UITableViewStyle.Plain)
        {
            _username = user;
            _repository = repo;
            Title = "Milestones";
            SearchPlaceholder = "Search Milestones";

            var clearMilestone = new MilestoneModel { Title = "Clear milestone filter" };
            var noMilestone = new MilestoneModel { Title = "Issues with no milestone" };
            var withMilestone = new MilestoneModel { Title = "Issues with milestone" };

            _milestones.CollectionChanged += (sender, e) => {
                var items = _milestones.ToList();

                items.Insert(0, noMilestone);
                items.Insert(1, withMilestone);

                if (alreadySelected)
                    items.Insert(0, clearMilestone);

                var sec = new Section();
                foreach (var item in items)
                {
                    var x = item;
                    var element = new StringElement(x.Title);
                    element.Clicked.Subscribe(_ => {
                        if (MilestoneSelected != null)
                        {
                            if (x == noMilestone)
                                MilestoneSelected(x.Title, null, "none");
                            else if (x == withMilestone)
                                MilestoneSelected(x.Title, null, "*");
                            else if (x == clearMilestone)
                                MilestoneSelected(null, null, null);
                            else
                                MilestoneSelected(x.Title, x.Number, x.Number.ToString());
                        }
                    });
                    sec.Add(element);
                }

                InvokeOnMainThread(() => Root.Reset(sec));
            };
        }
        public MultipleChoiceViewController(string title, object obj)
            : base(UITableViewStyle.Grouped)
        {
            _obj = obj;
            Title = title;

            var sec = new Section();
            var fields = obj.GetType().GetProperties();
            foreach (var s in fields)
            {
                var copy = s;
                var accessory = (bool)s.GetValue(_obj) ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None;
                var e = new StringElement(s.Name) { Accessory = accessory };
                e.Clicked.Subscribe(_ => OnValueSelected(copy));
                sec.Add(e);
            }
            Root.Add(sec);
        }
Esempio n. 13
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var vm = (BranchesAndTagsViewModel)ViewModel;
            var weakVm = new WeakReference<BranchesAndTagsViewModel>(vm);

            BindCollection(vm.Items, x => {
                var e = new StringElement(x.Name);
                e.Clicked.Subscribe(MakeCallback(weakVm, x));
                return e;
            });

            OnActivation(d =>
            {
                d(vm.Bind(x => x.SelectedFilter, true).Subscribe(x => _viewSegment.SelectedSegment = (nint)x));
                d(_viewSegment.GetChangedObservable().Subscribe(_ => vm.SelectedFilter = (int)_viewSegment.SelectedSegment));
            });
        }
Esempio n. 14
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            HeaderView.SetImage(null, Images.Avatar);
            HeaderView.Text = ViewModel.Username;

            var split = new SplitButtonElement();
            var followers = split.AddButton("Followers", "-");
            var following = split.AddButton("Following", "-");

            var events = new StringElement("Events", Octicon.Rss.ToImage());
            var organizations = new StringElement("Organizations", Octicon.Organization.ToImage());
            var repos = new StringElement("Repositories", Octicon.Repo.ToImage());
            var gists = new StringElement("Gists", Octicon.Gist.ToImage());
            Root.Add(new [] { new Section { split }, new Section { events, organizations, repos, gists } });

            ViewModel.Bind(x => x.User).Subscribe(x => {
                followers.Text = x?.Followers.ToString() ?? "-";
                following.Text = x?.Following.ToString() ?? "-";
                HeaderView.SubText = string.IsNullOrWhiteSpace(x?.Name) ? null : x.Name;
                HeaderView.SetImage(x?.AvatarUrl, Images.Avatar);
                RefreshHeaderView();
            });

            OnActivation(d =>
            {
                d(followers.Clicked.BindCommand(ViewModel.GoToFollowersCommand));
                d(following.Clicked.BindCommand(ViewModel.GoToFollowingCommand));
                d(events.Clicked.BindCommand(ViewModel.GoToEventsCommand));
                d(organizations.Clicked.BindCommand(ViewModel.GoToOrganizationsCommand));
                d(repos.Clicked.BindCommand(ViewModel.GoToRepositoriesCommand));
                d(gists.Clicked.BindCommand(ViewModel.GoToGistsCommand));
                d(ViewModel.Bind(x => x.Title, true).Subscribe(x => Title = x));
            });
        }
Esempio n. 15
0
        private void CreateTable()
        {
            var application = Mvx.Resolve<IApplicationService>();
            var vm = (SettingsViewModel)ViewModel;
            var currentAccount = application.Account;
            var accountSection = new Section("Account");

            var showOrganizationsInEvents = new BooleanElement("Show Organizations in Events", currentAccount.ShowOrganizationsInEvents);
            showOrganizationsInEvents.Changed.Subscribe(x => {
                currentAccount.ShowOrganizationsInEvents = x;
                application.Accounts.Update(currentAccount);
            });

            var showOrganizations = new BooleanElement("List Organizations in Menu", currentAccount.ExpandOrganizations);
            showOrganizations.Changed.Subscribe(x => { 
                currentAccount.ExpandOrganizations = x;
                application.Accounts.Update(currentAccount);
            });

            var repoDescriptions = new BooleanElement("Show Repo Descriptions", currentAccount.ShowRepositoryDescriptionInList);
            repoDescriptions.Changed.Subscribe(x => {
                currentAccount.ShowRepositoryDescriptionInList = x;
                application.Accounts.Update(currentAccount);
            });

            var startupView = new StringElement("Startup View", vm.DefaultStartupViewName, UITableViewCellStyle.Value1)
            { 
                Accessory = UITableViewCellAccessory.DisclosureIndicator,
            };
            startupView.Clicked.BindCommand(vm.GoToDefaultStartupViewCommand);

            var pushNotifications = new BooleanElement("Push Notifications", vm.PushNotificationsEnabled);
            pushNotifications.Changed.Subscribe(e => vm.PushNotificationsEnabled = e);
            accountSection.Add(pushNotifications);
       
            var source = new StringElement("Source Code");
            source.Clicked.BindCommand(vm.GoToSourceCodeCommand);

            var follow = new StringElement("Follow On Twitter");
            follow.Clicked.Subscribe(_ => UIApplication.SharedApplication.OpenUrl(new NSUrl("https://twitter.com/CodeHubapp")));

            var rate = new StringElement("Rate This App");
            rate.Clicked.Subscribe(_ => UIApplication.SharedApplication.OpenUrl(new NSUrl("https://itunes.apple.com/us/app/codehub-github-for-ios/id707173885?mt=8")));

            var aboutSection = new Section("About", "Thank you for downloading. Enjoy!") { source, follow, rate };
        
            if (vm.ShouldShowUpgrades)
            {
                var upgrades = new StringElement("Upgrades");
                upgrades.Clicked.BindCommand(vm.GoToUpgradesCommand);
                aboutSection.Add(upgrades);
            }

            var appVersion = new StringElement("App Version", UIApplication.SharedApplication.GetVersion())
            { 
                Accessory = UITableViewCellAccessory.None,
                SelectionStyle = UITableViewCellSelectionStyle.None
            };

            aboutSection.Add(appVersion);

            //Assign the root
            Root.Reset(accountSection, new Section("Appearance") { showOrganizationsInEvents, showOrganizations, repoDescriptions, startupView }, aboutSection);
        }
Esempio n. 16
0
        protected void UpdateView()
        {
            ICollection<Section> sections = new LinkedList<Section>();
            var section = new Section();
            sections.Add(section);

            var desc = new MultilinedElement("Description", ViewModel.Description);
            desc.Clicked.Subscribe(_ => ChangeDescription());
            section.Add(desc);

            var pub = new BooleanElement("Public", ViewModel.Public); 
            pub.Changed.Subscribe(x => ViewModel.Public = x);
            section.Add(pub);

            var fileSection = new Section();
            sections.Add(fileSection);

            foreach (var file in ViewModel.Files.Keys)
            {
                var key = file;
                if (string.IsNullOrEmpty(ViewModel.Files[file]))
                    continue;

                var size = System.Text.Encoding.UTF8.GetByteCount(ViewModel.Files[file]);
                var el = new StringElement(file, size + " bytes", UITableViewCellStyle.Subtitle) { Accessory = UITableViewCellAccessory.DisclosureIndicator };
                el.Clicked.Subscribe(_ => {
                    if (!ViewModel.Files.ContainsKey(key))
                        return;
                    var createController = new GistFileEditViewController { Filename = key, Content = ViewModel.Files[key] };
                    createController.SaveCommand.Subscribe(__ => NavigationController.PopToViewController(this, true));
                    createController.Save = (name, content) => {

                        if (string.IsNullOrEmpty(name))
                            throw new InvalidOperationException("Please enter a name for the file");

                        //If different name & exists somewhere else
                        if (!name.Equals(key) && ViewModel.Files.ContainsKey(name))
                            throw new InvalidOperationException("A filename by that type already exists");

                        ViewModel.Files.Remove(key);
                        ViewModel.Files[name] = content;
                        ViewModel.Files = ViewModel.Files; // Trigger refresh
                    };

                    NavigationController.PushViewController(createController, true);
                });
                fileSection.Add(el);
            }

            var add = new StringElement("Add New File");
            add.Clicked.Subscribe(_ => AddFile());
            fileSection.Add(add);

            Root.Reset(sections);
        }
Esempio n. 17
0
 public static StringElement BindCommand(this StringElement stringElement, Func <IReactiveCommand> cmd)
 {
     stringElement.Tapped = () => cmd().ExecuteIfCan();
     return(stringElement);
 }
Esempio n. 18
0
 public static StringElement BindDisclosure(this StringElement stringElement, IObservable <bool> value)
 {
     value.Subscribe(x => stringElement.Accessory = x ? UIKit.UITableViewCellAccessory.DisclosureIndicator : UIKit.UITableViewCellAccessory.None);
     return(stringElement);
 }
Esempio n. 19
0
 public static StringElement BindValue(this StringElement stringElement, IObservable <string> value)
 {
     value.Subscribe(x => stringElement.Value = x);
     return(stringElement);
 }
Esempio n. 20
0
 public static IDisposable BindCommand <T>(this StringElement stringElement, IReactiveCommand <T> cmd)
 {
     return(stringElement.Clicked.InvokeCommand(cmd));
 }
Esempio n. 21
0
 public static IDisposable BindValue <T>(this StringElement stringElement, IObservable <T> value)
 {
     return(value.SubscribeSafe(x => stringElement.Value = x.ToString()));
 }
Esempio n. 22
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _splitButton1 = _split.AddButton("Comments", "-");
            _splitButton2 = _split.AddButton("Participants", "-");

            Title = "Issue #" + ViewModel.Id;
            HeaderView.SetImage(null, Images.Avatar);
            HeaderView.Text = Title;

            Appeared.Take(1)
                .Select(_ => Observable.Timer(TimeSpan.FromSeconds(0.2f)))
                .Switch()
                .ObserveOn(RxApp.MainThreadScheduler)
                .Select(_ => ViewModel.Bind(x => x.IsClosed, true).Where(x => x.HasValue).Select(x => x.Value))
                .Switch()
                .Subscribe(x => 
                {
                    HeaderView.SubImageView.TintColor = x ? UIColor.FromRGB(0xbd, 0x2c, 0) : UIColor.FromRGB(0x6c, 0xc6, 0x44);
                    HeaderView.SetSubImage((x ? Octicon.IssueClosed :Octicon.IssueOpened).ToImage());
                });

            _milestoneElement = new StringElement("Milestone", "No Milestone", UITableViewCellStyle.Value1) {Image = Octicon.Milestone.ToImage() };
            _assigneeElement = new StringElement("Assigned", "Unassigned", UITableViewCellStyle.Value1) {Image = Octicon.Person.ToImage() };
            _labelsElement = new StringElement("Labels", "None", UITableViewCellStyle.Value1) {Image = Octicon.Tag.ToImage() };
            _addCommentElement = new StringElement("Add Comment") { Image = Octicon.Pencil.ToImage() };

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

            ViewModel.Bind(x => x.IsModifying).SubscribeStatus("Loading...");

            ViewModel.Bind(x => x.Issue).Subscribe(x =>
            {
                _assigneeElement.Value = x.Assignee != null ? x.Assignee.Login : "******";
                _milestoneElement.Value = x.Milestone != null ? x.Milestone.Title : "No Milestone";
                _labelsElement.Value = x.Labels.Count == 0 ? "None" : string.Join(", ", x.Labels.Select(i => i.Name));

                var model = new DescriptionModel(ViewModel.MarkdownDescription, (int)UIFont.PreferredSubheadline.PointSize, true);
                var markdown = new MarkdownView { Model = model };
                var html = markdown.GenerateString();
                _descriptionElement.SetValue(string.IsNullOrEmpty(ViewModel.MarkdownDescription) ? null : html);

                HeaderView.Text = x.Title;
                HeaderView.SubText = "Updated " + x.UpdatedAt.Humanize();
                HeaderView.SetImage(x.User?.AvatarUrl, Images.Avatar);
                RefreshHeaderView();

                Render();
            });

            ViewModel.BindCollection(x => x.Comments).Subscribe(_ => RenderComments());
            ViewModel.BindCollection(x => x.Events).Subscribe(_ => RenderComments());
            ViewModel.Bind(x => x.ShouldShowPro).Subscribe(x => {
                if (x) this.ShowPrivateView(); 
            });

            OnActivation(d =>
            {
                d(_milestoneElement.Clicked.BindCommand(ViewModel.GoToMilestoneCommand));
                d(_assigneeElement.Clicked.BindCommand(ViewModel.GoToAssigneeCommand));
                d(_labelsElement.Clicked.BindCommand(ViewModel.GoToLabelsCommand));
                d(_addCommentElement.Clicked.Subscribe(_ => AddCommentTapped()));
                d(_descriptionElement.UrlRequested.BindCommand(ViewModel.GoToUrlCommand));
                d(_commentsElement.UrlRequested.BindCommand(ViewModel.GoToUrlCommand));
                d(actionButton.GetClickedObservable().Subscribe(ShowExtraMenu));
                d(HeaderView.Clicked.BindCommand(ViewModel.GoToOwner));

                d(ViewModel.Bind(x => x.IsCollaborator, true).Subscribe(x => {
                    foreach (var i in new [] { _assigneeElement, _milestoneElement, _labelsElement })
                        i.Accessory = x ? UITableViewCellAccessory.DisclosureIndicator : UITableViewCellAccessory.None;
                }));

                d(ViewModel.Bind(x => x.IsLoading).Subscribe(x => actionButton.Enabled = !x));
            });
        }
Esempio n. 23
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Gist";

            var editButton = NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action);

            HeaderView.SetImage(null, Images.Avatar);
            HeaderView.Text = "Gist #" + ViewModel.Id;
            HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);

            Appeared.Take(1)
                .Select(_ => Observable.Timer(TimeSpan.FromSeconds(0.35f)).Take(1))
                .Switch()
                .Select(_ => ViewModel.Bind(x => x.IsStarred, true))
                .Switch()
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(x => HeaderView.SetSubImage(x ? Octicon.Star.ToImage() : null));

            TableView.RowHeight = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 44f;

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

            _splitRow1 = new SplitViewElement(Octicon.Lock.ToImage(), Octicon.Package.ToImage());
            _splitRow2 = new SplitViewElement(Octicon.Calendar.ToImage(), Octicon.Star.ToImage());
            _ownerElement = new StringElement("Owner", string.Empty, UITableViewCellStyle.Value1) { 
                Image = Octicon.Person.ToImage(),
                Accessory = UITableViewCellAccessory.DisclosureIndicator
            };

            OnActivation(d =>
            {
                d(editButton.GetClickedObservable().Subscribe(_ => ShareButtonTap(editButton)));
                d(_ownerElement.Clicked.BindCommand(ViewModel.GoToUserCommand));

                d(ViewModel.Bind(x => x.IsStarred, true).Subscribe(isStarred => _splitRow2.Button2.Text = isStarred ? "Starred" : "Not Starred"));

                d(ViewModel.BindCollection(x => x.Comments, true).Subscribe(_ => RenderGist()));
                d(HeaderView.Clicked.BindCommand(ViewModel.GoToUserCommand));

                d(ViewModel.Bind(x => x.Gist, true).Where(x => x != null).Subscribe(gist =>
                {
                    _splitRow1.Button1.Text = (gist.Public ?? true) ? "Public" : "Private";
                    _splitRow1.Button2.Text = (gist.History?.Count ?? 0) + " Revisions";
                    _splitRow2.Button1.Text = gist.CreatedAt.Day + " Days Old";
                    _ownerElement.Value = gist.Owner?.Login ?? "Unknown";
                    files.Text = gist.Files.Count.ToString();
                    comments.Text = gist.Comments.ToString();
                    forks.Text = gist.Forks.Count.ToString();
                    HeaderView.SubText = gist.Description;
                    HeaderView.Text = gist.Files?.Select(x => x.Key).FirstOrDefault() ?? HeaderView.Text;
                    HeaderView.SetImage(gist.Owner?.AvatarUrl, Images.Avatar);
                    RenderGist();
                    RefreshHeaderView();
                }));
            });
        }