-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
RefreshWebViewGallery.xaml.cs
76 lines (64 loc) · 1.38 KB
/
RefreshWebViewGallery.xaml.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
using System;
using System.Collections.Generic;
using System.Windows.Input;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Controls.GalleryPages.RefreshViewGalleries
{
[Preserve(AllMembers = true)]
public partial class RefreshWebViewGallery : ContentPage
{
public RefreshWebViewGallery()
{
InitializeComponent();
BindingContext = new RefreshWebViewGalleryViewModel();
}
}
[Preserve(AllMembers = true)]
public class RefreshWebViewGalleryViewModel : BindableObject
{
const int RefreshDuration = 2;
readonly Random _random;
bool _isRefresing;
string _url;
public RefreshWebViewGalleryViewModel()
{
_random = new Random();
LoadUrl();
}
public bool IsRefreshing
{
get { return _isRefresing; }
set
{
_isRefresing = value;
OnPropertyChanged();
}
}
public string Url
{
get { return _url; }
set
{
_url = value;
OnPropertyChanged();
}
}
public ICommand RefreshCommand => new Command(ExecuteRefresh);
void LoadUrl()
{
var urls = new List<string> { "https://dotnet.microsoft.com/apps/xamarin", "https://devblogs.microsoft.com/xamarin/" };
int index = _random.Next(urls.Count);
Url = urls[index];
}
void ExecuteRefresh()
{
IsRefreshing = true;
Device.StartTimer(TimeSpan.FromSeconds(RefreshDuration), () =>
{
LoadUrl();
IsRefreshing = false;
return false;
});
}
}
}