This repository has been archived by the owner on Jul 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainPage.xaml.cs
94 lines (78 loc) · 2.76 KB
/
MainPage.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Linq;
using Tizen.Wearable.CircularUI.Forms;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace WakeOnLan
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainPage : CirclePage
{
public MainPage()
{
InitializeComponent();
PcList.ItemsSource = LanPc.List;
RefreshPlaceholder();
}
async private void ListItemTapped(object sender, ItemTappedEventArgs e)
{
var result = await WolProvider.WakeUp(((LanPc)e.Item).MacAddress);
Toast.DisplayText(result ?
Resx.AppResources.SendSuccess
: Resx.AppResources.SendError);
}
async private void ToolbarAddClicked(object sender, EventArgs e)
{
var page = new AddPage();
page.ItemAdded += RefreshPlaceholder;
var nav = new NavigationPage(page);
NavigationPage.SetHasNavigationBar(nav, false);
await Navigation.PushModalAsync(nav);
}
private void ToolbarDeleteClicked(object sender, EventArgs e)
{
var selectedPcs = LanPc.List.Where(x => x.Selected).ToList();
var leftButton = new MenuItem() { Icon = new FileImageSource { File = "back.png" } };
var rightButton = new MenuItem() { Icon = new FileImageSource { File = "delete.png" } };
var confirmPopup = new TwoButtonPopup
{
Title = Resx.AppResources.Delete,
Text = string.Format(Resx.AppResources.DeleteConfirm, selectedPcs.Count),
FirstButton = leftButton,
SecondButton = rightButton,
};
leftButton.Command = new Command(() => confirmPopup.Dismiss());
rightButton.Command = new Command(() =>
{
PcList.BeginRefresh();
foreach (var i in selectedPcs)
LanPc.List.Remove(i);
PcList.EndRefresh();
RefreshPlaceholder();
confirmPopup.Dismiss();
});
confirmPopup.Show();
}
async private void ToolbarPowerClicked(object sender, EventArgs e)
{
foreach (var i in LanPc.List.Where(x => x.Selected))
{
await WolProvider.WakeUp(i.MacAddress);
i.Selected = false;
}
}
private void RefreshPlaceholder()
{
if (LanPc.List.Count == 0)
{
EmptyPlaceholder.IsVisible = true;
PcList.IsVisible = false;
}
else
{
EmptyPlaceholder.IsVisible = false;
PcList.IsVisible = true;
}
}
}
}