This repository was archived by the owner on Jul 2, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathUserViewController.cs
More file actions
61 lines (52 loc) · 2.95 KB
/
Copy pathUserViewController.cs
File metadata and controls
61 lines (52 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Reactive.Linq;
using CodeHub.Core.ViewModels.Users;
using UIKit;
using ReactiveUI;
using CodeHub.iOS.DialogElements;
namespace CodeHub.iOS.ViewControllers.Users
{
public class UserViewController : BaseDialogViewController<UserViewModel>
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
HeaderView.Image = Images.LoginUserUnknown;
HeaderView.SubImageView.TintColor = UIColor.FromRGB(243, 156, 18);
Appeared.Take(1)
.Select(_ => Observable.Timer(TimeSpan.FromSeconds(0.35f)))
.Switch()
.Select(_ => this.WhenAnyValue(x => x.ViewModel.IsFollowing).Where(x => x.HasValue))
.Switch()
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x => HeaderView.SetSubImage(x.Value ? Octicon.Star.ToImage() : null));
this.WhenAnyValue(x => x.ViewModel.IsLoggedInUser)
.Subscribe(x => NavigationItem.RightBarButtonItem = x ?
null : ViewModel.ShowMenuCommand.ToBarButtonItem(UIBarButtonSystemItem.Action));
var websiteElement = new StringElement("Website", () => ViewModel.GoToWebsiteCommand.ExecuteIfCan(), Octicon.Globe.ToImage());
var extraSection = new Section();
var split = new SplitButtonElement();
var followers = split.AddButton("Followers", "-", () => ViewModel.GoToFollowersCommand.ExecuteIfCan());
var following = split.AddButton("Following", "-", () => ViewModel.GoToFollowingCommand.ExecuteIfCan());
var events = new StringElement("Events", () => ViewModel.GoToEventsCommand.ExecuteIfCan(), Octicon.Rss.ToImage());
var organizations = new StringElement("Organizations", () => ViewModel.GoToOrganizationsCommand.ExecuteIfCan(), Octicon.Organization.ToImage());
var repos = new StringElement("Repositories", () => ViewModel.GoToRepositoriesCommand.ExecuteIfCan(), Octicon.Repo.ToImage());
var gists = new StringElement("Gists", () => ViewModel.GoToGistsCommand.ExecuteIfCan(), Octicon.Gist.ToImage());
Root.Reset(new [] { new Section { split }, new Section { events, organizations, repos, gists }, extraSection });
this.WhenAnyValue(x => x.ViewModel.User).IsNotNull().Subscribe(x =>
{
HeaderView.ImageUri = x.AvatarUrl;
followers.Text = x.Followers.ToString();
following.Text = x.Following.ToString();
HeaderView.SubText = string.IsNullOrEmpty(x.Name) ? null : x.Name;
RefreshHeaderView();
});
this.WhenAnyValue(x => x.ViewModel.HasBlog).Subscribe(x => {
if (x && websiteElement.Section == null)
extraSection.Add(websiteElement);
else if (!x && websiteElement.Section != null)
extraSection.Remove(websiteElement);
});
}
}
}

