-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFriendsViewModel.cs
58 lines (51 loc) · 1.57 KB
/
FriendsViewModel.cs
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
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using interfacebased.FriendDetail;
using interfacebased.Services;
using observingobjects;
namespace interfacebased.FriendsList
{
public class FriendsViewModel : BaseViewModel, IFriendsViewModel
{
private readonly IFriendsService m_friendsService;
private bool m_isBusy;
private FriendViewModel m_selectedFriend;
public FriendsViewModel(IFriendsService friendsService)
{
m_friendsService = friendsService;
Friends = new ObservableCollection<FriendViewModel>();
}
public async Task Initialize(IHandleFriendChanged friendChangedHandler)
{
try
{
IsBusy = true;
var friendsFetched = await m_friendsService.Get();
foreach (var friend in friendsFetched)
{
Friends.Add(new FriendViewModel(friend, friendChangedHandler));
}
}
catch (Exception exception)
{
//Log it, fix it or show it
}
finally
{
IsBusy = false;
}
}
public ObservableCollection<FriendViewModel> Friends { get; }
public FriendViewModel SelectedFriend
{
get => m_selectedFriend;
set => SetProperty(ref m_selectedFriend, value);
}
public bool IsBusy
{
get => m_isBusy;
set => SetProperty(ref m_isBusy, value);
}
}
}