This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
/
HomePageViewModel.cs
82 lines (74 loc) · 2.62 KB
/
HomePageViewModel.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
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 System;
using System.Diagnostics;
using System.Net.Http;
using Acr.UserDialogs;
using Covid19Radar.Common;
using Covid19Radar.Model;
using Covid19Radar.Resources;
using Covid19Radar.Services;
using Covid19Radar.Views;
using Newtonsoft.Json.Linq;
using Prism.Navigation;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace Covid19Radar.ViewModels
{
public class HomePageViewModel : ViewModelBase
{
private readonly UserDataService userDataService;
private readonly ExposureNotificationService exposureNotificationService;
private UserDataModel userData;
private string _startDate;
private string _pastDate;
public string StartDate
{
get { return _startDate; }
set { SetProperty(ref _startDate, value); }
}
public string PastDate
{
get { return _pastDate; }
set { SetProperty(ref _pastDate, value); }
}
public HomePageViewModel(INavigationService navigationService, UserDataService userDataService, ExposureNotificationService exposureNotificationService) : base(navigationService, userDataService, exposureNotificationService)
{
Title = AppResources.HomePageTitle;
this.userDataService = userDataService;
this.exposureNotificationService = exposureNotificationService;
userData = this.userDataService.Get();
StartDate = userData.GetLocalDateString();
TimeSpan timeSpan = DateTime.UtcNow - userData.StartDateTime;
PastDate = timeSpan.Days.ToString();
}
public override async void Initialize(INavigationParameters parameters)
{
// Check Version
AppUtils.CheckVersion();
try
{
await exposureNotificationService.StartExposureNotification();
await exposureNotificationService.FetchExposureKeyAsync();
base.Initialize(parameters);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
public Command OnClickExposures => new Command(async () =>
{
var count = exposureNotificationService.GetExposureCount();
if (count > 0)
{
await NavigationService.NavigateAsync(nameof(ContactedNotifyPage));
return;
}
await NavigationService.NavigateAsync(nameof(NotContactPage));
return;
});
public Command OnClickShareApp => new Command(() =>
{
AppUtils.PopUpShare();
});
}
}