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 pathPullRequestFilesView.cs
More file actions
85 lines (74 loc) · 2.98 KB
/
PullRequestFilesView.cs
File metadata and controls
85 lines (74 loc) · 2.98 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
using CodeHub.iOS.ViewControllers;
using CodeHub.Core.ViewModels.PullRequests;
using UIKit;
using System;
using CodeHub.iOS.DialogElements;
using CodeHub.iOS.ViewControllers.Source;
using CodeHub.iOS.ViewControllers.PullRequests;
namespace CodeHub.iOS.Views.PullRequests
{
public class PullRequestFilesView : ViewModelCollectionDrivenDialogViewController
{
public new PullRequestFilesViewModel ViewModel
{
get { return (PullRequestFilesViewModel)base.ViewModel; }
set { base.ViewModel = value; }
}
public PullRequestFilesView()
{
Title = "Files";
EmptyView = new Lazy<UIView>(() =>
new EmptyListView(Octicon.FileCode.ToEmptyListImage(), "There are no files."));
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var weakVm = new WeakReference<PullRequestFilesViewModel>(ViewModel);
var weakVc = new WeakReference<PullRequestFilesView>(this);
BindCollection(ViewModel.Files, x =>
{
var name = x.Filename.Substring(x.Filename.LastIndexOf("/", StringComparison.Ordinal) + 1);
var el = new StringElement(name, x.Status, UITableViewCellStyle.Subtitle);
el.Image = Octicon.FileCode.ToImage();
el.Accessory = UITableViewCellAccessory.DisclosureIndicator;
el.Clicked.Subscribe(_ => weakVc.Get()?.GoToFile(x));
return el;
});
}
private void GoToFile(GitHubSharp.Models.CommitModel.CommitFileModel file)
{
if (file.Patch == null)
{
var viewController = new FileSourceViewController(
ViewModel.Username, ViewModel.Repository, file.Filename, ViewModel.Sha, Utilities.ShaType.Hash);
this.PushViewController(viewController);
}
else
{
var viewController = new PullRequestDiffViewController(
ViewModel.Username, ViewModel.Repository, (int)ViewModel.PullRequestId, file.Filename,
file.Patch, ViewModel.Sha);
this.PushViewController(viewController);
}
}
public override DialogViewController.Source CreateSizingSource()
{
return new CustomSource(this);
}
private class CustomSource : DialogViewController.Source
{
public CustomSource(PullRequestFilesView parent)
: base(parent)
{
}
public override void WillDisplayHeaderView(UITableView tableView, UIView headerView, nint section)
{
var x = headerView as UITableViewHeaderFooterView;
if (x != null)
{
x.TextLabel.LineBreakMode = UILineBreakMode.HeadTruncation;
}
}
}
}
}