Exemplo n.º 1
1
        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);
                }));
            });
        }
Exemplo n.º 2
0
 internal CommitCommentItemViewModel(GitHubSharp.Models.CommentModel comment)
 {
     Avatar = new GitHubAvatar(comment?.User?.AvatarUrl);
     Actor = comment?.User?.Login;
     Body = comment.BodyHtml;
     UtcCreatedAt = comment.CreatedAt.UtcDateTime;
 }
Exemplo n.º 3
0
        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...");
        }
Exemplo n.º 4
0
 internal UserItemViewModel(string name, string avatarUrl, bool organization, Action gotoAction)
 {
     Name = name;
     Avatar = new GitHubAvatar(avatarUrl);
     IsOrganization = organization;
     GoToCommand = ReactiveCommand.Create().WithSubscription(_ => gotoAction());
 }
Exemplo n.º 5
0
 internal IssueCommentItemViewModel(GitHubSharp.Models.IssueCommentModel comment)
 {
     Comment = comment.BodyHtml;
     Actor = comment?.User?.Login;
     AvatarUrl = new GitHubAvatar(comment?.User?.AvatarUrl);
     CreatedAt = comment.CreatedAt;
 }
Exemplo n.º 6
0
 internal IssueCommentItemViewModel(string body, string login, string avatar, DateTimeOffset createdAt)
 {
     Comment = body;
     Actor = login;
     AvatarUrl = new GitHubAvatar(avatar);
     CreatedAt = createdAt;
 }
Exemplo n.º 7
0
 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;
 }
Exemplo n.º 8
0
 internal PullRequestItemViewModel(PullRequestModel pullRequest) 
 {
     var user = pullRequest.User ?? new BasicUserModel();
     Title = pullRequest.Title ?? "No Title";
     Avatar = new GitHubAvatar(user.AvatarUrl);
     Details = string.Format("#{0} opened {1} by {2}", pullRequest.Number, pullRequest.CreatedAt.UtcDateTime.Humanize(), user.Login);
     GoToCommand = ReactiveCommand.Create();
 }
Exemplo n.º 9
0
 internal IssueAssigneeItemViewModel(Octokit.User user)
 {
     Name = user.Login;
     User = user;
     Avatar = new GitHubAvatar(user.AvatarUrl);
     GoToCommand = ReactiveCommand.Create()
         .WithSubscription(_ => IsSelected = !IsSelected);
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
0
 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;
 }
Exemplo n.º 12
0
 public void Set(string title, string description, DateTimeOffset time, GitHubAvatar avatar)
 {
     ContentConstraint.Constant = string.IsNullOrEmpty(description) ? 0f : DefaultContentConstraintSize;
     TitleLabel.Text = title;
     ContentLabel.Text = description;
     TimeLabel.Text = time.Humanize();
     MainImageView.SetAvatar(avatar);
 }
Exemplo n.º 13
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;
 }
Exemplo n.º 14
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);
 }
Exemplo n.º 15
0
 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;
 }
Exemplo n.º 16
0
        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();
        }
Exemplo n.º 17
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;
        }
        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;
            });
        }
Exemplo n.º 19
0
        internal RepositoryItemViewModel(Octokit.Repository repository, bool showOwner, Action<RepositoryItemViewModel> gotoCommand)
        {
            if (!string.IsNullOrEmpty(repository.Description) && repository.Description.IndexOf(':') >= 0)
                Description = Emojis.FindAndReplace(repository.Description);
            else
                Description = repository.Description;

            Repository = repository;
            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().WithSubscription(x => gotoCommand(this));
        }
Exemplo n.º 20
0
        internal CommitItemViewModel(CommitModel commit, Action<CommitItemViewModel> action)
        {
            var msg = commit.With(x => x.Commit).With(x => x.Message, () => string.Empty);
            var firstLine = msg.IndexOf("\n", StringComparison.Ordinal);
            var description = firstLine > 0 ? msg.Substring(0, firstLine) : msg;
            _description = new Lazy<string>(() => Emojis.FindAndReplace(description));

            var time = DateTimeOffset.MinValue;
            if (commit.Commit.Committer != null)
                time = commit.Commit.Committer.Date;
            Time = time.UtcDateTime.Humanize();

            Name = commit.GenerateCommiterName();
            Avatar = new GitHubAvatar(commit.GenerateGravatarUrl());
            Commit = commit;
            GoToCommand = ReactiveCommand.Create().WithSubscription(_ => action(this));
        }
Exemplo n.º 21
0
        internal RepositoryItemViewModel(string name, string owner, string imageUrl,
                                         string description, int stars, int forks,
                                         bool showOwner, Action<RepositoryItemViewModel> gotoCommand)
        {
            if (!string.IsNullOrEmpty(description) && description.IndexOf(':') >= 0)
            {
                description = Emojis.FindAndReplace(description);
            }

            Name = name;
            Owner = owner;
            Avatar = new GitHubAvatar(imageUrl);
            Description = description;
            Stars = stars;
            Forks = forks;
            ShowOwner = showOwner;
            GoToCommand = ReactiveCommand.Create().WithSubscription(x => gotoCommand(this));
        }
Exemplo n.º 22
0
        private async Task Load()
        {
            var account = await _accountsService.GetDefault();

            // Account no longer exists
            if (account == null)
            {
                await GoToAccountsOrNewUser();
                return;
            }

            try
            {
                Status = string.Format("Logging in {0}", account.Username);
                Avatar = new GitHubAvatar(account.AvatarUrl);

                IsLoggingIn = true;
                await _sessionService.SetSessionAccount(account);
                NavigateTo(this.CreateViewModel<MenuViewModel>());
                StarOrWatch();
            }
            catch (UnauthorizedException)
            {
                _alertDialogFactory.Alert("Unable to login!", "Your credentials are no longer valid for this account.")
                    .ToObservable()
                    .ObserveOn(RxApp.MainThreadScheduler)
                    .Subscribe(_ => NavigateTo(this.CreateViewModel<AccountsViewModel>()));
            }
            catch (Exception e)
            {
                _alertDialogFactory.Alert("Unable to login!", e.Message)
                    .ToObservable()
                    .ObserveOn(RxApp.MainThreadScheduler)
                    .Subscribe(_ => NavigateTo(this.CreateViewModel<AccountsViewModel>()));
            }
            finally
            {
                IsLoggingIn = false;
            }
        }
Exemplo n.º 23
0
        public static void SetAvatar(this UIImageView @this, GitHubAvatar avatar, int? size = 64)
        {
            @this.Image = Images.LoginUserUnknown;

            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.LoginUserUnknown;
                        @this.BeginInvokeOnMainThread(() =>
                            UIView.Transition(@this, 0.4f, UIViewAnimationOptions.TransitionCrossDissolve, () => @this.Image = img, null));
                    }
                });
            }
        }
Exemplo n.º 24
0
        public void Bind(string name, string name2, string name3, string description, string repoOwner, GitHubAvatar imageUrl)
        {
            Caption.Text = name;
            Label1.Text = name2;
            Label3.Text = name3;
            Description.Hidden = description == null;
            Description.Text = description ?? string.Empty;

            RepoName.Hidden = repoOwner == null;
            UserImage.Hidden = RepoName.Hidden;
            RepoName.Text = repoOwner ?? string.Empty;

            BigImage.Image = Images.Avatar;

            try
            {
                var uri = imageUrl.ToUri(64)?.AbsoluteUri;
                if (uri != null)
                    BigImage.SetImage(new NSUrl(uri), Images.Avatar);
            }
            catch
            {
            }
        }
Exemplo n.º 25
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);
                });
            }
        }
Exemplo n.º 26
0
 public void Set(string title, DateTimeOffset time, GitHubAvatar avatar)
 {
     TitleLabel.Text = title;
     TimeLabel.Text = time.Humanize();
     MainImageView.SetAvatar(avatar);
 }