internal IssueAssigneeItemViewModel(Octokit.User user)
 {
     Name        = user.Login;
     Avatar      = new GitHubAvatar(user.AvatarUrl);
     GoToCommand = ReactiveCommand.Create()
                   .WithSubscription(_ => IsSelected = !IsSelected);
 }
Exemple #2
0
        public RepositoryItemViewModel(Octokit.Repository repository, bool showOwner, bool showDescription, Action <RepositoryItemViewModel> gotoCommand)
        {
            if (showDescription)
            {
                if (!string.IsNullOrEmpty(repository.Description) && repository.Description.IndexOf(':') >= 0)
                {
                    Description = Emojis.FindAndReplace(repository.Description);
                }
                else
                {
                    Description = repository.Description;
                }
            }
            else
            {
                Description = null;
            }

            Name        = repository.Name;
            Owner       = repository.Owner?.Login ?? string.Empty;
            Avatar      = new GitHubAvatar(repository.Owner?.AvatarUrl);
            Stars       = repository.StargazersCount.ToString();
            Forks       = repository.ForksCount.ToString();
            ShowOwner   = showOwner;
            GoToCommand = ReactiveCommand.Create(() => gotoCommand?.Invoke(this));
        }
Exemple #3
0
 internal UserItemViewModel(Octokit.User user, Action <UserItemViewModel> gotoAction)
 {
     Login       = user.Login;
     Name        = user.Name;
     Avatar      = new GitHubAvatar(user.AvatarUrl);
     GoToCommand = ReactiveCommand.Create(() => gotoAction?.Invoke(this));
 }
Exemple #4
0
 internal PullRequestItemViewModel(PullRequestModel pullRequest, Action gotoAction)
 {
     Title       = pullRequest.Title ?? "No Title";
     Avatar      = new GitHubAvatar(pullRequest.User.AvatarUrl);
     Details     = string.Format("#{0} opened {1} by {2}", pullRequest.Number, pullRequest.CreatedAt.UtcDateTime.Humanize(), pullRequest.User.Login);
     GoToCommand = ReactiveCommand.Create().WithSubscription(_ => gotoAction());
 }
Exemple #5
0
    public static Uri ToUri(this GitHubAvatar @this, int?size = null)
    {
        if (@this == null || @this.AvatarUrl == null)
        {
            return(null);
        }

        try
        {
            var baseUri = new UriBuilder(@this.AvatarUrl);

            if (size == null)
            {
                return(baseUri.Uri);
            }

            var queryToAppend = "size=" + size.Value;
            if (baseUri.Query != null && baseUri.Query.Length > 1)
            {
                baseUri.Query = baseUri.Query.Substring(1) + "&" + queryToAppend;
            }
            else
            {
                baseUri.Query = queryToAppend;
            }
            return(baseUri.Uri);
        }
        catch
        {
            return(null);
        }
    }
 internal CommitCommentItemViewModel(GitHubSharp.Models.CommentModel comment)
 {
     Avatar       = new GitHubAvatar(comment.With(y => y.User).With(y => y.AvatarUrl));
     Actor        = comment.With(x => x.User).With(x => x.Login);
     Body         = comment.BodyHtml;
     UtcCreatedAt = comment.CreatedAt.UtcDateTime;
 }
Exemple #7
0
        public static void SetAvatar(this UIImageView @this, GitHubAvatar avatar, int?size = 64)
        {
            @this.Image = Images.Avatar;

            if (avatar == null)
            {
                return;
            }

            var avatarUri = avatar.ToUri(size);

            if (avatarUri != null)
            {
                @this.SetImage(new NSUrl(avatarUri.AbsoluteUri), Images.LoginUserUnknown, (img, err, type, imageUrl) => {
                    if (img == null || err != null)
                    {
                        return;
                    }

                    if (type == SDImageCacheType.None)
                    {
                        @this.Image = Images.Avatar;
                        @this.BeginInvokeOnMainThread(() =>
                                                      UIView.Transition(@this, 0.25f, UIViewAnimationOptions.TransitionCrossDissolve, () => @this.Image = img, null));
                    }
                });
            }
        }
Exemple #8
0
 internal CommitCommentItemViewModel(GitHubSharp.Models.CommentModel comment)
 {
     Avatar       = new GitHubAvatar(comment?.User?.AvatarUrl);
     Actor        = comment?.User?.Login;
     Body         = comment.BodyHtml;
     UtcCreatedAt = comment.CreatedAt.UtcDateTime;
 }
 internal IssueCommentItemViewModel(GitHubSharp.Models.IssueCommentModel comment)
 {
     Comment   = comment.BodyHtml;
     Actor     = comment.With(x => x.User).With(x => x.Login);
     AvatarUrl = new GitHubAvatar(comment.With(x => x.User).With(x => x.AvatarUrl));
     CreatedAt = comment.CreatedAt;
 }
Exemple #10
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            var vm     = (RepositoriesTrendingViewModel)ViewModel;
            var weakVm = new WeakReference <RepositoriesTrendingViewModel>(vm);

            TableView.RowHeight          = UITableView.AutomaticDimension;
            TableView.EstimatedRowHeight = 64f;
            TableView.SeparatorInset     = new UIEdgeInsets(0, 56f, 0, 0);

            vm.Bind(x => x.Repositories).Subscribe(repos => {
                var repositories = repos ?? Enumerable.Empty <Tuple <string, IList <RepositoryModel> > >();
                Root.Reset(repositories.Select(x => {
                    var s = new Section(CreateHeaderView(x.Item1));
                    s.Reset(x.Item2.Select(repo => {
                        var description = vm.ShowRepositoryDescription ? repo.Description : string.Empty;
                        var avatar      = new GitHubAvatar(repo.Owner?.AvatarUrl);
                        var sse         = new RepositoryElement(repo.Name, repo.StargazersCount, repo.Forks, description, repo.Owner?.Login, avatar)
                        {
                            ShowOwner = true
                        };
                        sse.Tapped += MakeCallback(weakVm, repo);
                        return(sse);
                    }));
                    return(s);
                }));
            });

            OnActivation(d => {
                d(_trendingTitleButton.GetClickedObservable().Subscribe(_ => ShowLanguages()));
                d(vm.Bind(x => x.SelectedLanguage, true).Subscribe(l => _trendingTitleButton.Text = l.Name));
            });
        }
Exemple #11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            var vm     = (RepositoriesExploreViewModel)ViewModel;
            var search = (UISearchBar)TableView.TableHeaderView;

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

            var weakVm = new WeakReference <RepositoriesExploreViewModel>(vm);

            BindCollection(vm.Repositories, repo =>
            {
                var description = vm.ShowRepositoryDescription ? repo.Description : string.Empty;
                var avatar      = new GitHubAvatar(repo.Owner?.AvatarUrl);
                var sse         = new RepositoryElement(repo.Name, repo.StargazersCount, repo.ForksCount, description, repo.Owner.Login, avatar)
                {
                    ShowOwner = true
                };
                sse.Tapped += MakeCallback(weakVm, repo);
                return(sse);
            });

            OnActivation(d =>
            {
                d(search.GetChangedObservable().Subscribe(x => vm.SearchText = x));
                d(vm.Bind(x => x.IsSearching).SubscribeStatus("Searching..."));
                d(search.GetSearchObservable().Subscribe(_ => {
                    search.ResignFirstResponder();
                    vm.SearchCommand.Execute(null);
                }));
            });
        }
Exemple #12
0
 internal UserItemViewModel(string name, string avatarUrl, bool organization, Action gotoAction)
 {
     Name           = name;
     Avatar         = new GitHubAvatar(avatarUrl);
     IsOrganization = organization;
     GoToCommand    = ReactiveCommand.Create().WithSubscription(_ => gotoAction());
 }
Exemple #13
0
        public void UpdatedImage(Uri uri)
        {
            if (uri == null)
            {
                AssignUnknownUserImage();
            }
            else
            {
                // Wipe out old avatars
                var avatar      = new GitHubAvatar(uri);
                var avatarSizes = new [] { avatar.ToUri(), avatar.ToUri(64) };
                foreach (var avatarUrl in avatarSizes.Select(x => new NSUrl(x.AbsoluteUri)))
                {
                    var cacheKey = SDWebImageManager.SharedManager.CacheKey(avatarUrl);
                    if (cacheKey != null)
                    {
                        SDWebImageManager.SharedManager.ImageCache.RemoveImage(cacheKey);
                    }
                }

                _imgView.SetImage(new NSUrl(uri.AbsoluteUri), Images.LoginUserUnknown, (img, err, cache, _) => {
                    _imgView.Image = Images.LoginUserUnknown;
                    UIView.Transition(_imgView, 0.25f, UIViewAnimationOptions.TransitionCrossDissolve, () => _imgView.Image = img, null);
                });
            }
        }
Exemple #14
0
 internal IssueCommentItemViewModel(GitHubSharp.Models.IssueCommentModel comment)
 {
     Comment   = comment.BodyHtml;
     Actor     = comment?.User?.Login;
     AvatarUrl = new GitHubAvatar(comment?.User?.AvatarUrl);
     CreatedAt = comment.CreatedAt;
 }
Exemple #15
0
 internal IssueCommentItemViewModel(string body, string login, string avatar, DateTimeOffset createdAt)
 {
     Comment   = body;
     Actor     = login;
     AvatarUrl = new GitHubAvatar(avatar);
     CreatedAt = createdAt;
 }
Exemple #16
0
 public void Set(string title, string description, DateTimeOffset time, GitHubAvatar avatar)
 {
     TitleLabel.Text            = title;
     ContentLabel.Text          = description;
     TimeLabel.Text             = time.Humanize();
     ContentConstraint.Constant = string.IsNullOrEmpty(description) ? 0f : DefaultContentConstraintSize;
     MainImageView.SetAvatar(avatar);
 }
 internal IssueEventItemViewModel(Octokit.EventInfo issueEvent)
 {
     Actor     = issueEvent.With(x => x.Actor).With(x => x.Login, () => "Deleted User");
     AvatarUrl = new GitHubAvatar(issueEvent.With(x => x.Actor).With(x => x.AvatarUrl));
     CreatedAt = issueEvent.CreatedAt;
     Commit    = issueEvent.CommitId;
     EventInfo = issueEvent;
 }
Exemple #18
0
 public GistItemViewModel(string title, string avatarUrl, string description, DateTimeOffset updatedAt, Action <GistItemViewModel> gotoAction)
 {
     Title       = title;
     Description = description;
     UpdatedAt   = updatedAt;
     GoToCommand = ReactiveCommand.Create().WithSubscription(x => gotoAction(this));
     Avatar      = new GitHubAvatar(avatarUrl);
 }
Exemple #19
0
 internal IssueEventItemViewModel(Octokit.EventInfo issueEvent)
 {
     Actor     = issueEvent?.Actor?.Login ?? "Deleted User";
     AvatarUrl = new GitHubAvatar(issueEvent?.Actor?.AvatarUrl);
     CreatedAt = issueEvent.CreatedAt;
     Commit    = issueEvent.CommitId;
     EventInfo = issueEvent;
 }
 public RepositoryElement(string name, int followers, int forks, string description, string owner, GitHubAvatar avatar)
 {
     _name        = name;
     _followers   = followers;
     _forks       = forks;
     _description = description;
     _owner       = owner;
     _avatar      = avatar;
     ShowOwner    = true;
 }
 public GistItemViewModel(Gist gist, Action <GistItemViewModel> gotoAction)
 {
     Gist          = gist;
     Id            = gist.Id;
     Title         = GetGistTitle(gist);
     Description   = string.IsNullOrEmpty(gist.Description) ? "Gist " + gist.Id : gist.Description;
     Avatar        = new GitHubAvatar(gist.Owner?.AvatarUrl);
     UpdatedAt     = gist.UpdatedAt;
     UpdatedString = UpdatedAt.Humanize();
     GoToCommand   = ReactiveCommand.Create(() => gotoAction(this));
 }
        internal PullRequestItemViewModel(PullRequest pullRequest)
        {
            PullRequest = pullRequest;

            var login  = pullRequest?.User.Login ?? "Unknonwn User";
            var avatar = pullRequest?.User.AvatarUrl;

            Title       = pullRequest.Title ?? "No Title";
            Avatar      = new GitHubAvatar(avatar);
            Details     = string.Format("#{0} opened {1} by {2}", pullRequest.Number, pullRequest.CreatedAt.UtcDateTime.Humanize(), login);
            GoToCommand = ReactiveCommand.Create();
        }
Exemple #23
0
        public CommitElement(CommitModel model, Action action)
        {
            _model  = model;
            _action = action;
            _avatar = new GitHubAvatar(_model.GenerateGravatarUrl());
            _name   = _model.GenerateCommiterName();

            var msg       = _model?.Commit?.Message ?? string.Empty;
            var firstLine = msg.IndexOf("\n", StringComparison.Ordinal);

            _description = firstLine > 0 ? msg.Substring(0, firstLine) : msg;
        }
        private static Element CreateElement(Tuple <EventModel, BaseEventsViewModel.EventBlock> e)
        {
            try
            {
                if (e.Item2 == null)
                {
                    return(null);
                }

                var imgKey = ChooseImage(e.Item1);
                var img    = Octicon.Alert;
                if (_eventToImage.ContainsKey(imgKey))
                {
                    img = _eventToImage[imgKey];
                }

                var avatar       = e.Item1.Actor != null ? e.Item1.Actor.AvatarUrl : null;
                var headerBlocks = new List <NewsFeedElement.TextBlock>();
                foreach (var h in e.Item2.Header)
                {
                    Action act         = null;
                    var    anchorBlock = h as BaseEventsViewModel.AnchorBlock;
                    if (anchorBlock != null)
                    {
                        act = anchorBlock.Tapped;
                    }
                    headerBlocks.Add(new NewsFeedElement.TextBlock(h.Text, act));
                }

                var bodyBlocks = new List <NewsFeedElement.TextBlock>();
                foreach (var h in e.Item2.Body)
                {
                    Action act         = null;
                    var    anchorBlock = h as BaseEventsViewModel.AnchorBlock;
                    if (anchorBlock != null)
                    {
                        act = anchorBlock.Tapped;
                    }
                    var block = new NewsFeedElement.TextBlock(h.Text, act);
                    bodyBlocks.Add(block);
                }

                var weakTapped   = new WeakReference <Action>(e.Item2.Tapped);
                var githubAvatar = new GitHubAvatar(avatar).ToUri(64)?.AbsoluteUri;
                return(new NewsFeedElement(githubAvatar, e.Item1.CreatedAt, headerBlocks, bodyBlocks, img.ToImage(), () => weakTapped.Get()?.Invoke(), e.Item2.Multilined));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to add event: " + ex.Message);
                return(null);
            }
        }
Exemple #25
0
        public UserElement(string username, string firstName, string lastName, GitHubAvatar avatar)
            : base(username, string.Empty, UITableViewCellStyle.Subtitle)
        {
            var realName = firstName ?? "" + " " + (lastName ?? "");

            if (!string.IsNullOrWhiteSpace(realName))
            {
                Value = realName;
            }
            Accessory = UITableViewCellAccessory.DisclosureIndicator;
            Image     = Images.Avatar;
            ImageUri  = avatar.ToUri(64);
        }
Exemple #26
0
        public static void SetAvatar(this UIImageView @this, GitHubAvatar avatar, int?size = 64)
        {
            var avatarUri = avatar.ToUri(size);

            if (avatarUri == null)
            {
                @this.Image = Images.LoginUserUnknown;
            }
            else
            {
                @this.SetImage(new NSUrl(avatarUri.AbsoluteUri), Images.LoginUserUnknown);
            }
        }
 internal RepositoryItemViewModel(string name, string owner, string imageUrl,
                                  string description, int stars, int forks,
                                  bool showOwner, Action <RepositoryItemViewModel> gotoCommand)
 {
     Name        = name;
     Owner       = owner;
     Avatar      = new GitHubAvatar(imageUrl);
     Description = description;
     Stars       = stars;
     Forks       = forks;
     ShowOwner   = showOwner;
     GoToCommand = ReactiveCommand.Create().WithSubscription(x => gotoCommand(this));
 }
Exemple #28
0
        protected Element CreateElement(RepositoryModel repo)
        {
            var description = ViewModel.ShowRepositoryDescription ? Emojis.FindAndReplace(repo.Description) : string.Empty;
            var avatar      = new GitHubAvatar(repo.Owner?.AvatarUrl);
            var vm          = new WeakReference <RepositoriesViewModel>(ViewModel);
            var sse         = new RepositoryElement(repo.Name, repo.Watchers, repo.Forks, description, repo.Owner.Login, avatar)
            {
                ShowOwner = ViewModel.ShowRepositoryOwner
            };

            sse.Tapped += () => vm.Get()?.GoToRepositoryCommand.Execute(repo);
            return(sse);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

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

            BindCollection(vm.Users, x =>
            {
                var avatar = new GitHubAvatar(x.AvatarUrl);
                var e      = new UserElement(x.Login, string.Empty, string.Empty, avatar);
                e.Clicked.Subscribe(_ => weakVm.Get()?.GoToUserCommand.Execute(x));
                return(e);
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var vm = (IssueAssignedToViewModel)ViewModel;

            BindCollection(vm.Users, x =>
            {
                var avatar = new GitHubAvatar(x.AvatarUrl);
                var el     = new UserElement(x.Login, string.Empty, string.Empty, avatar);
                el.Clicked.Subscribe(_ => {
                    if (vm.SelectedUser != null && string.Equals(vm.SelectedUser.Login, x.Login))
                    {
                        vm.SelectedUser = null;
                    }
                    else
                    {
                        vm.SelectedUser = x;
                    }
                });

                if (vm.SelectedUser != null && string.Equals(vm.SelectedUser.Login, x.Login, StringComparison.OrdinalIgnoreCase))
                {
                    el.Accessory = UITableViewCellAccessory.Checkmark;
                }
                else
                {
                    el.Accessory = UITableViewCellAccessory.None;
                }
                return(el);
            });

            vm.Bind(x => x.SelectedUser).Subscribe(x =>
            {
                if (Root.Count == 0)
                {
                    return;
                }
                foreach (var m in Root[0].Elements.Cast <UserElement>())
                {
                    m.Accessory = (x != null && string.Equals(vm.SelectedUser.Login, m.Caption, StringComparison.OrdinalIgnoreCase)) ?
                                  UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None;
                }
            });

            vm.Bind(x => x.IsSaving).SubscribeStatus("Saving...");
        }