Skip to content

Commit 8722637

Browse files
committed
Settings_General: (un)register listeners on navigation
1 parent e8a331d commit 8722637

File tree

4 files changed

+63
-39
lines changed

4 files changed

+63
-39
lines changed

SimpleWeather.Windows/Controls/DevKeyEntry.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<StackPanel>
1313
<Border
14-
MinWidth="260"
14+
Width="320"
1515
Padding="10,4"
1616
HorizontalAlignment="Left"
1717
BorderBrush="DarkGray"

SimpleWeather.Windows/Preferences/DevSettingsPage.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<mtuc:SettingsCard Header="Tomorrow.io Key">
4343
<controls:DevKeyEntry API="{x:Bind weather:WeatherAPI.TomorrowIo, Mode=OneTime}" />
4444
</mtuc:SettingsCard>
45+
<mtuc:SettingsCard Header="Google Weather Key">
46+
<controls:DevKeyEntry API="{x:Bind weather:WeatherAPI.Google, Mode=OneTime}" />
47+
</mtuc:SettingsCard>
4548
<mtuc:SettingsCard Header="Google Pollen Key">
4649
<controls:DevKeyEntry API="{x:Bind weather:WeatherAPI.Google_Pollen, Mode=OneTime}" />
4750
</mtuc:SettingsCard>

SimpleWeather.Windows/Preferences/Settings_General.xaml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,24 @@
6767
DisplayMemberPath="Display"
6868
SelectedValuePath="Value">
6969
<controls:ComboBoxItem Display="{helpers:StringRes Name='summary_default'}" Value="" />
70-
<controls:ComboBoxItem Value="en-US"/>
71-
<controls:ComboBoxItem Value="ar-SA"/>
72-
<controls:ComboBoxItem Value="de"/>
73-
<controls:ComboBoxItem Value="de-AT"/>
74-
<controls:ComboBoxItem Value="en"/>
75-
<controls:ComboBoxItem Value="es"/>
76-
<controls:ComboBoxItem Value="fr"/>
77-
<controls:ComboBoxItem Value="hu"/>
78-
<controls:ComboBoxItem Value="id"/>
79-
<controls:ComboBoxItem Value="lt"/>
80-
<controls:ComboBoxItem Value="nl"/>
81-
<controls:ComboBoxItem Value="pl"/>
82-
<controls:ComboBoxItem Value="ro"/>
83-
<controls:ComboBoxItem Value="ru"/>
84-
<controls:ComboBoxItem Value="sk"/>
85-
<controls:ComboBoxItem Value="tr"/>
86-
<controls:ComboBoxItem Value="vi"/>
87-
<controls:ComboBoxItem Value="zh-Hans"/>
70+
<controls:ComboBoxItem Value="en-US" />
71+
<controls:ComboBoxItem Value="ar-SA" />
72+
<controls:ComboBoxItem Value="de" />
73+
<controls:ComboBoxItem Value="de-AT" />
74+
<controls:ComboBoxItem Value="en" />
75+
<controls:ComboBoxItem Value="es" />
76+
<controls:ComboBoxItem Value="fr" />
77+
<controls:ComboBoxItem Value="hu" />
78+
<controls:ComboBoxItem Value="id" />
79+
<controls:ComboBoxItem Value="lt" />
80+
<controls:ComboBoxItem Value="nl" />
81+
<controls:ComboBoxItem Value="pl" />
82+
<controls:ComboBoxItem Value="ro" />
83+
<controls:ComboBoxItem Value="ru" />
84+
<controls:ComboBoxItem Value="sk" />
85+
<controls:ComboBoxItem Value="tr" />
86+
<controls:ComboBoxItem Value="vi" />
87+
<controls:ComboBoxItem Value="zh-Hans" />
8888
</ComboBox>
8989
</mtuic:SettingsCard>
9090

@@ -158,7 +158,7 @@
158158
</mtuic:SettingsCard.Description>
159159
<Border
160160
x:Name="KeyBorder"
161-
MinWidth="260"
161+
Width="320"
162162
Padding="10,4"
163163
BorderBrush="DarkGray"
164164
BorderThickness="2">

SimpleWeather.Windows/Preferences/Settings_General.xaml.cs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Microsoft.UI.Xaml.Controls;
66
using Microsoft.UI.Xaml.Media;
77
using Microsoft.UI.Xaml.Navigation;
8-
using SimpleWeather.Controls;
98
using SimpleWeather.Extras;
109
using SimpleWeather.NET.BackgroundTasks;
1110
using SimpleWeather.NET.Controls;
@@ -21,11 +20,9 @@
2120
using SimpleWeather.Weather_API.WeatherData;
2221
using SimpleWeather.WeatherData;
2322
using System.Globalization;
24-
using System.Linq;
2523
using Windows.ApplicationModel;
2624
using Windows.Devices.Geolocation;
2725
using ComboBoxItem = SimpleWeather.Controls.ComboBoxItem;
28-
using ResStrings = SimpleWeather.Resources.Strings.Resources;
2926

3027
namespace SimpleWeather.NET.Preferences
3128
{
@@ -71,21 +68,6 @@ public Settings_General()
7168

7269
RestoreSettings();
7370

74-
// Event Listeners
75-
FollowGPS.Toggled += FollowGPS_Toggled;
76-
AlertSwitch.Toggled += AlertSwitch_Toggled;
77-
APIComboBox.SelectionChanged += APIComboBox_SelectionChanged;
78-
RefreshComboBox.SelectionChanged += RefreshComboBox_SelectionChanged;
79-
RadarComboBox.SelectionChanged += RadarComboBox_SelectionChanged;
80-
PersonalKeySwitch.Toggled += PersonalKeySwitch_Toggled;
81-
ThemeComboBox.SelectionChanged += ThemeComboBox_SelectionChanged;
82-
LanguageComboBox.SelectionChanged += LanguageComboBox_SelectionChanged;
83-
DailyNotifSwitch.Toggled += DailyNotifSwitch_Toggled;
84-
DailyNotifTimePicker.SelectedTimeChanged += DailyNotifTimePicker_SelectedTimeChanged;
85-
PoPChanceNotifSwitch.Toggled += PoPChanceNotifSwitch_Toggled;
86-
PoPChancePct.SelectionChanged += PoPChancePct_SelectionChanged;
87-
MinAlertSeverity.SelectionChanged += MinAlertSeverity_SelectionChanged;
88-
8971
AnalyticsLogger.LogEvent("Settings_General");
9072
}
9173

@@ -238,6 +220,40 @@ private void RestoreSettings()
238220
});
239221
}
240222

223+
private void RegisterListeners()
224+
{
225+
FollowGPS.Toggled += FollowGPS_Toggled;
226+
AlertSwitch.Toggled += AlertSwitch_Toggled;
227+
APIComboBox.SelectionChanged += APIComboBox_SelectionChanged;
228+
RefreshComboBox.SelectionChanged += RefreshComboBox_SelectionChanged;
229+
RadarComboBox.SelectionChanged += RadarComboBox_SelectionChanged;
230+
PersonalKeySwitch.Toggled += PersonalKeySwitch_Toggled;
231+
ThemeComboBox.SelectionChanged += ThemeComboBox_SelectionChanged;
232+
LanguageComboBox.SelectionChanged += LanguageComboBox_SelectionChanged;
233+
DailyNotifSwitch.Toggled += DailyNotifSwitch_Toggled;
234+
DailyNotifTimePicker.SelectedTimeChanged += DailyNotifTimePicker_SelectedTimeChanged;
235+
PoPChanceNotifSwitch.Toggled += PoPChanceNotifSwitch_Toggled;
236+
PoPChancePct.SelectionChanged += PoPChancePct_SelectionChanged;
237+
MinAlertSeverity.SelectionChanged += MinAlertSeverity_SelectionChanged;
238+
}
239+
240+
private void UnregisterListeners()
241+
{
242+
FollowGPS.Toggled -= FollowGPS_Toggled;
243+
AlertSwitch.Toggled -= AlertSwitch_Toggled;
244+
APIComboBox.SelectionChanged -= APIComboBox_SelectionChanged;
245+
RefreshComboBox.SelectionChanged -= RefreshComboBox_SelectionChanged;
246+
RadarComboBox.SelectionChanged -= RadarComboBox_SelectionChanged;
247+
PersonalKeySwitch.Toggled -= PersonalKeySwitch_Toggled;
248+
ThemeComboBox.SelectionChanged -= ThemeComboBox_SelectionChanged;
249+
LanguageComboBox.SelectionChanged -= LanguageComboBox_SelectionChanged;
250+
DailyNotifSwitch.Toggled -= DailyNotifSwitch_Toggled;
251+
DailyNotifTimePicker.SelectedTimeChanged -= DailyNotifTimePicker_SelectedTimeChanged;
252+
PoPChanceNotifSwitch.Toggled -= PoPChanceNotifSwitch_Toggled;
253+
PoPChancePct.SelectionChanged -= PoPChancePct_SelectionChanged;
254+
MinAlertSeverity.SelectionChanged -= MinAlertSeverity_SelectionChanged;
255+
}
256+
241257
public Task<bool> OnBackRequested()
242258
{
243259
var provider = APIComboBox.SelectedValue.ToString();
@@ -261,6 +277,8 @@ public void OnNavigatedToPage(NavigationEventArgs e)
261277
App.Current.UnregisterSettingsListener();
262278
SettingsManager.OnSettingsChanged += Settings_OnSettingsChanged;
263279
RestoreSettings();
280+
// Event Listeners
281+
RegisterListeners();
264282
}
265283

266284
public void OnNavigatedFromPage(NavigationEventArgs e)
@@ -279,9 +297,10 @@ public void OnNavigatingFromPage(NavigatingCancelEventArgs e)
279297
}
280298
else
281299
{
282-
// Unsubscribe from event
300+
// Unsubscribe from events
283301
App.Current.RegisterSettingsListener();
284302
SettingsManager.OnSettingsChanged -= Settings_OnSettingsChanged;
303+
UnregisterListeners();
285304

286305
ProcessQueue();
287306
}
@@ -390,6 +409,8 @@ private Task ShowKeyEntryDialog()
390409
{
391410
return DispatcherQueue.EnqueueAsync(async () =>
392411
{
412+
if (this.XamlRoot == null) return;
413+
393414
var keydialog = new KeyEntryDialog(APIComboBox.SelectedValue.ToString())
394415
{
395416
RequestedTheme = Shell.Instance.AppFrame.RequestedTheme,

0 commit comments

Comments
 (0)