-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.xaml.cs
More file actions
149 lines (123 loc) · 4.64 KB
/
Copy pathSettings.xaml.cs
File metadata and controls
149 lines (123 loc) · 4.64 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.Data.Xml.Dom;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.System;
using static QR_Code_Generator.MainWindow;
namespace QR_Code_Generator
{
public sealed partial class Settings : Page
{
public Settings()
{
this.InitializeComponent();
VersionTextBlock.Text = GetAppVersion();
}
public class SettingData
{
private readonly ApplicationDataContainer _local =
ApplicationData.Current.LocalSettings;
// ---- Default values ----
private const bool DefaultWifi = true;
private const bool DefaultPhone = true;
private const bool DefaultLink = true;
//Experiments
private const bool DefaultShowMassQR = false;
// ---- Publicly readable settings ----
public bool Wifi { get; private set; }
public bool Phone { get; private set; }
public bool Link { get; private set; }
public bool ShowMassQR { get; private set; }
// ---- Global access across the whole project ----
public static SettingData Current { get; } = new SettingData();
private SettingData()
{
Load();
}
// ---- Load settings (defaults + saved values) ----
private void Load()
{
Wifi = _local.Values["Wifi"] as bool? ?? DefaultWifi;
Phone = _local.Values["Phone"] as bool? ?? DefaultPhone;
Link = _local.Values["Link"] as bool? ?? DefaultLink;
ShowMassQR = _local.Values["ShowMassQR"] as bool? ?? DefaultShowMassQR;
}
// ---- Save updated values ----
public void Update(string key, bool value)
{
_local.Values[key] = value;
switch (key)
{
case "Wifi": Wifi = value; break;
case "Phone": Phone = value; break;
case "Link": Link = value; break;
case "ShowMassQR": ShowMassQR = value; break;
}
}
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
WifiCheck.IsChecked = SettingData.Current.Wifi;
PhoneCheck.IsChecked = SettingData.Current.Phone;
LinkCheck.IsChecked = SettingData.Current.Link;
//ShowMassQR.IsOn = SettingData.Current.ShowMassQR;
}
private void Checkbox1(object sender, RoutedEventArgs e)
{
var checkbox = (CheckBox)sender;
bool isChecked = checkbox.IsChecked == true;
switch (checkbox.Name)
{
case "WifiCheck":
SettingData.Current.Update("Wifi", isChecked);
break;
case "PhoneCheck":
SettingData.Current.Update("Phone", isChecked);
break;
case "LinkCheck":
SettingData.Current.Update("Link", isChecked);
break;
}
}
//Experiments
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
var toggle = (ToggleSwitch)sender;
bool isToggled = toggle.IsOn;
SettingData.Current.Update(toggle.Name, isToggled);
if (toggle.Name == "ShowMassQR")
{
// Call MainWindow to update the NavigationView
MainWindow.Instance?.RefreshNavigationView();
}
}
public static string GetAppVersion()
{
Package package = Package.Current;
PackageId packageId = package.Id;
PackageVersion version = packageId.Version;
return string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);
}
private async void OpenIssueLink_Click(object sender, RoutedEventArgs e)
{
await Launcher.LaunchUriAsync(
new Uri("https://github.com/Geomedge/QR-Code-Generator/issues/new/choose")
);
}
}
}