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

Commit 8f4bd87

Browse files
committed
More work in notifications
1 parent 9364c7e commit 8f4bd87

3 files changed

Lines changed: 75 additions & 4 deletions

File tree

CodeHub.Core/ViewModels/NotificationsViewModel.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class NotificationsViewModel : LoadableViewModel
1818
private readonly FilterableCollectionViewModel<NotificationModel, NotificationsFilterModel> _notifications;
1919
private ICommand _readAllCommand;
2020
private ICommand _readCommand;
21+
private ICommand _readReposCommand;
2122
private int _shownIndex;
2223
private bool _isMarking;
2324

@@ -48,12 +49,17 @@ public bool IsMarking
4849

4950
public ICommand ReadCommand
5051
{
51-
get { return _readCommand ?? (_readCommand = new MvxCommand<NotificationModel>(x => Read(x)));}
52+
get { return _readCommand ?? (_readCommand = new MvxCommand<NotificationModel>(Read));}
5253
}
5354

55+
public ICommand ReadRepositoriesCommand
56+
{
57+
get { return _readReposCommand ?? (_readReposCommand = new MvxCommand<string>(MarkRepoAsRead)); }
58+
}
59+
5460
public ICommand ReadAllCommand
5561
{
56-
get { return _readAllCommand ?? (_readAllCommand = new MvxCommand(() => MarkAllAsRead(), () => ShownIndex != 2 && !IsLoading && !IsMarking)); }
62+
get { return _readAllCommand ?? (_readAllCommand = new MvxCommand(MarkAllAsRead, () => ShownIndex != 2 && !IsLoading && !IsMarking && Notifications.Any())); }
5763
}
5864

5965
public ICommand GoToNotificationCommand
@@ -132,6 +138,36 @@ private async void Read(NotificationModel model)
132138
}
133139
}
134140

141+
private async void MarkRepoAsRead(string repo)
142+
{
143+
var items = Notifications.Items.Where(x => string.Equals(x.Repository.FullName, repo, StringComparison.OrdinalIgnoreCase)).ToList();
144+
145+
try
146+
{
147+
IsMarking = true;
148+
149+
foreach (var notification in items)
150+
{
151+
try
152+
{
153+
await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Notifications[notification.Id].MarkAsRead());
154+
notification.Unread = false;
155+
}
156+
catch
157+
{
158+
//Ignore?
159+
}
160+
}
161+
162+
Notifications.Items.RemoveRange(items);
163+
UpdateAccountNotificationsCount();
164+
}
165+
finally
166+
{
167+
IsMarking = false;
168+
}
169+
}
170+
135171
private async void MarkAllAsRead()
136172
{
137173
// Make sure theres some sort of notification

CodeHub.iOS/Views/NotificationsView.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,42 @@ public override void ViewDidLoad()
6262
var set = this.CreateBindingSet<NotificationsView, NotificationsViewModel>();
6363
set.Bind(_viewSegment).To(x => x.ShownIndex);
6464
set.Apply();
65-
}
65+
}
66+
67+
protected override Section CreateSection(string text)
68+
{
69+
return new Section(new MarkReadSection(text, this, _viewSegment.SelectedSegment != 2));
70+
}
71+
72+
private class MarkReadSection : UITableViewHeaderFooterView
73+
{
74+
readonly UIButton _button;
75+
readonly NotificationsView _parent;
76+
public MarkReadSection(string text, NotificationsView parent, bool button)
77+
: base(new System.Drawing.RectangleF(0, 0, 320, 28f))
78+
{
79+
_parent = parent;
80+
TextLabel.Text = text;
81+
82+
if (button)
83+
{
84+
_button = new UIButton(UIButtonType.RoundedRect);
85+
_button.SetImage(Theme.CurrentTheme.CheckButton, UIControlState.Normal);
86+
//_button.Frame = new System.Drawing.RectangleF(320f - 42f, 1f, 26f, 26f);
87+
_button.TintColor = UIColor.FromRGB(50, 50, 50);
88+
_button.TouchUpInside += (sender, e) => ((NotificationsViewModel)_parent.ViewModel).ReadRepositoriesCommand.Execute(text);
89+
Add(_button);
90+
}
91+
}
92+
93+
public override void LayoutSubviews()
94+
{
95+
base.LayoutSubviews();
96+
97+
if (_button != null)
98+
_button.Frame = new System.Drawing.RectangleF(Frame.Width - 42f, 1, 26, 26);
99+
}
100+
}
66101

67102
public override void ViewWillAppear(bool animated)
68103
{

0 commit comments

Comments
 (0)