This repository was archived by the owner on Jul 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 609
Expand file tree
/
Copy pathUserExploreViewController.cs
More file actions
84 lines (70 loc) · 2.59 KB
/
UserExploreViewController.cs
File metadata and controls
84 lines (70 loc) · 2.59 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Reactive.Linq;
using CodeHub.Core.ViewModels.Search;
using CodeHub.iOS.TableViewSources;
using CodeHub.iOS.ViewControllers.Users;
using CodeHub.iOS.Views;
using CoreGraphics;
using ReactiveUI;
using UIKit;
namespace CodeHub.iOS.ViewControllers.Search
{
public class UserExploreViewController : TableViewController
{
private readonly UISearchBar _searchBar = new UISearchBar(new CGRect(0, 0, 320, 44));
private readonly LoadingIndicatorView _loading = new LoadingIndicatorView();
private readonly Lazy<UIView> emptyView = new Lazy<UIView>((() =>
new EmptyListView(Octicon.Person.ToEmptyListImage(), "There are no users.")));
public UserExploreViewModel ViewModel { get; } = new UserExploreViewModel();
public UserExploreViewController()
: base(UITableViewStyle.Plain)
{
Title = "Users";
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
TableView.TableHeaderView = _searchBar;
TableView.Source = new UserTableViewSource(TableView, ViewModel.Items);
this.WhenActivated(d =>
{
d(_searchBar.GetChangedObservable()
.Subscribe(x => ViewModel.SearchText = x));
d(_searchBar.GetSearchObservable()
.InvokeReactiveCommand(ViewModel.SearchCommand));
d(ViewModel.SearchCommand.IsExecuting
.Subscribe(Searching));
d(ViewModel.RepositoryItemSelected
.Select(x => new UserViewController(x.User))
.Subscribe(x => NavigationController.PushViewController(x, true)));
d(ViewModel.SearchCommand.Subscribe(_ => SearchComplete()));
});
}
private void SearchComplete()
{
if (ViewModel.Items.Count == 0)
{
TableView.BackgroundView = emptyView.Value;
TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
}
else
{
TableView.BackgroundView = null;
TableView.SeparatorStyle = UITableViewCellSeparatorStyle.SingleLine;
}
}
private void Searching(bool searching)
{
_loading.SetLoading(searching);
if (searching)
{
TableView.TableFooterView = _loading;
TableView.BackgroundView = null;
}
else
{
TableView.TableFooterView = null;
}
}
}
}