Skip to content
This repository was archived by the owner on Jul 2, 2022. It is now read-only.

Commit f5d152c

Browse files
committed
You can now share, comment, close, and open in github an issue from the action menu in the top right.
1 parent 8e53ca4 commit f5d152c

File tree

4 files changed

+115
-7
lines changed

4 files changed

+115
-7
lines changed

CodeHub.Core/ViewModels/Issues/IssueViewModel.cs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using CodeHub.Core.Messages;
88
using CodeFramework.Core.Services;
99
using CodeHub.Core.Services;
10+
using System;
1011

1112
namespace CodeHub.Core.ViewModels.Issues
1213
{
@@ -53,6 +54,17 @@ public IssueModel Issue
5354
}
5455
}
5556

57+
private bool _isModifying;
58+
public bool IsModifying
59+
{
60+
get { return _isModifying; }
61+
set
62+
{
63+
_isModifying = value;
64+
RaisePropertyChanged(() => IsModifying);
65+
}
66+
}
67+
5668
public ICommand GoToAssigneeCommand
5769
{
5870
get
@@ -91,11 +103,27 @@ public ICommand GoToEditCommand
91103
get
92104
{
93105
return new MvxCommand(() => {
94-
GetService<CodeFramework.Core.Services.IViewModelTxService>().Add(Issue);
106+
GetService<IViewModelTxService>().Add(Issue);
95107
ShowViewModel<IssueEditViewModel>(new IssueEditViewModel.NavObject { Username = Username, Repository = Repository, Id = Id });
96108
}, () => Issue != null);
97109
}
98-
}
110+
}
111+
112+
public ICommand ToggleStateCommand
113+
{
114+
get
115+
{
116+
return new MvxCommand(() => ToggleState(Issue.State == "open"), () => Issue != null);
117+
}
118+
}
119+
120+
public ICommand ShareCommand
121+
{
122+
get
123+
{
124+
return new MvxCommand(() => GetService<IShareService>().ShareUrl(Issue.HtmlUrl), () => Issue != null & !string.IsNullOrEmpty(Issue.HtmlUrl));
125+
}
126+
}
99127

100128
private readonly CollectionViewModel<IssueCommentModel> _comments = new CollectionViewModel<IssueCommentModel>();
101129
public CollectionViewModel<IssueCommentModel> Comments
@@ -142,6 +170,24 @@ public async Task AddComment(string text)
142170
Comments.Items.Add(comment.Data);
143171
}
144172

173+
private async Task ToggleState(bool closed)
174+
{
175+
try
176+
{
177+
IsModifying = true;
178+
var data = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Issue.Number].UpdateState(closed ? "closed" : "open"));
179+
Messenger.Publish(new IssueEditMessage(this) { Issue = data.Data });
180+
}
181+
catch (Exception e)
182+
{
183+
DisplayAlert("Unable to " + (closed ? "close" : "open") + " the item. " + e.Message);
184+
}
185+
finally
186+
{
187+
IsModifying = false;
188+
}
189+
}
190+
145191
public class NavObject
146192
{
147193
public string Username { get; set; }

CodeHub.Core/ViewModels/Issues/MyIssuesViewModel.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using System;
8+
using Cirrious.MvvmCross.Plugins.Messenger;
9+
using CodeHub.Core.Messages;
810

911
namespace CodeHub.Core.ViewModels.Issues
1012
{
1113
public class MyIssuesViewModel : BaseIssuesViewModel<MyIssuesFilterModel>
12-
{
14+
{
15+
private MvxSubscriptionToken _editToken;
16+
1317
private int _selectedFilter;
14-
1518
public int SelectedFilter
1619
{
1720
get { return _selectedFilter; }
@@ -34,7 +37,25 @@ public MyIssuesViewModel()
3437
_issues.Filter = MyIssuesFilterModel.CreateOpenFilter();
3538
else if (x == 1)
3639
_issues.Filter = MyIssuesFilterModel.CreateClosedFilter();
37-
});
40+
});
41+
42+
_editToken = Messenger.SubscribeOnMainThread<IssueEditMessage>(x =>
43+
{
44+
if (x.Issue == null)
45+
return;
46+
47+
var item = Issues.Items.FirstOrDefault(y => y.Number == x.Issue.Number);
48+
if (item == null)
49+
return;
50+
51+
var index = Issues.Items.IndexOf(item);
52+
53+
using (Issues.DeferRefresh())
54+
{
55+
Issues.Items.RemoveAt(index);
56+
Issues.Items.Insert(index, x.Issue);
57+
}
58+
});
3859
}
3960

4061
protected override List<IGrouping<string, IssueModel>> Group(IEnumerable<IssueModel> model)

CodeHub.iOS/Views/Issues/IssueView.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class IssueView : ViewModelDrivenDialogViewController
2121
protected StyledStringElement _assigneeElement;
2222
protected StyledStringElement _labelsElement;
2323
protected StyledStringElement _addCommentElement;
24+
private IHud _hud;
2425

2526
public new IssueViewModel ViewModel
2627
{
@@ -38,6 +39,7 @@ public override void ViewDidLoad()
3839
base.ViewDidLoad();
3940

4041
_header = new HeaderView();
42+
_hud = this.CreateHud();
4143

4244
var content = System.IO.File.ReadAllText("WebCell/body.html", System.Text.Encoding.UTF8);
4345
_descriptionElement = new WebElement(content, "body", false);
@@ -61,7 +63,7 @@ public override void ViewDidLoad()
6163
_addCommentElement = new StyledStringElement("Add Comment") { Image = Images.Pencil };
6264
_addCommentElement.Tapped += AddCommentTapped;
6365

64-
NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Compose, (s, e) => ViewModel.GoToEditCommand.Execute(null));
66+
NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, (s, e) => ShowExtraMenu());
6567
NavigationItem.RightBarButtonItem.Enabled = false;
6668
ViewModel.Bind(x => x.IsLoading, x =>
6769
{
@@ -71,6 +73,14 @@ public override void ViewDidLoad()
7173
}
7274
});
7375

76+
ViewModel.Bind(x => x.IsModifying, x =>
77+
{
78+
if (x)
79+
_hud.Show("Loading...");
80+
else
81+
_hud.Hide();
82+
});
83+
7484
ViewModel.Bind(x => x.Issue, x =>
7585
{
7686
_assigneeElement.Value = x.Assignee != null ? x.Assignee.Login : "Unassigned".t();
@@ -205,6 +215,37 @@ public override UIView InputAccessoryView
205215
}
206216
}
207217

218+
219+
private void ShowExtraMenu()
220+
{
221+
if (ViewModel.Issue == null)
222+
return;
223+
224+
var sheet = MonoTouch.Utilities.GetSheet(Title);
225+
var editButton = sheet.AddButton("Edit".t());
226+
var openButton = sheet.AddButton(ViewModel.Issue.State == "open" ? "Close".t() : "Open".t());
227+
var commentButton = sheet.AddButton("Comment".t());
228+
var shareButton = sheet.AddButton("Share".t());
229+
var showButton = sheet.AddButton("Show in GitHub".t());
230+
var cancelButton = sheet.AddButton("Cancel".t());
231+
sheet.CancelButtonIndex = cancelButton;
232+
sheet.DismissWithClickedButtonIndex(cancelButton, true);
233+
sheet.Clicked += (s, e) => {
234+
if (e.ButtonIndex == editButton)
235+
ViewModel.GoToEditCommand.Execute(null);
236+
else if (e.ButtonIndex == openButton)
237+
ViewModel.ToggleStateCommand.Execute(null);
238+
else if (e.ButtonIndex == shareButton)
239+
ViewModel.ShareCommand.Execute(null);
240+
else if (e.ButtonIndex == showButton)
241+
ViewModel.GoToUrlCommand.Execute(ViewModel.Issue.HtmlUrl);
242+
else if (e.ButtonIndex == commentButton)
243+
AddCommentTapped();
244+
};
245+
246+
sheet.ShowInView(this.View);
247+
}
248+
208249
private class CommentModel
209250
{
210251
public string AvatarUrl { get; set; }

lib/GitHubSharp

0 commit comments

Comments
 (0)