Skip to content

Commit 52ec788

Browse files
authored
Close Bluetooth connections option (#60)
* Added settings option to close Bluetooth connections upon going to Discovery page * Correct misspelling
1 parent 536168a commit 52ec788

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

BluetoothLEExplorer/BluetoothLEExplorer/Services/SettingsServices/SettingsService.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ public bool UseCaching
7070
}
7171
}
7272

73+
/// <summary>
74+
/// Gets or sets a value indicating whether connections should be closed upon going back to Discovery page.
75+
/// </summary>
76+
public bool CloseConnections
77+
{
78+
get
79+
{
80+
return helper.Read<bool>(nameof(CloseConnections), true);
81+
}
82+
83+
set
84+
{
85+
helper.Write(nameof(CloseConnections), value);
86+
}
87+
}
88+
7389
/// <summary>
7490
/// Gets or sets the application theme
7591
/// </summary>

BluetoothLEExplorer/BluetoothLEExplorer/ViewModels/DiscoverViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@ public override async Task OnNavigatedToAsync(object parameter, NavigationMode m
338338

339339
Context.BluetoothLEDevices.CollectionChanged += BluetoothLEDevices_CollectionChanged;
340340
GridFilter = "";
341-
Context.ReleaseAllResources();
341+
if (Services.SettingsServices.SettingsService.Instance.CloseConnections)
342+
{
343+
Context.ReleaseAllResources();
344+
}
342345
UpdateDeviceList();
343346

344347
await Task.CompletedTask;

BluetoothLEExplorer/BluetoothLEExplorer/ViewModels/SettingsPageViewModel.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public bool UseShellBackButton
7171
RaisePropertyChanged();
7272
}
7373
}
74+
7475
/// <summary>
7576
/// Gets or sets a value indicating whether caching should be used
7677
/// </summary>
@@ -88,6 +89,23 @@ public bool UseCachingButton
8889
}
8990
}
9091

92+
/// <summary>
93+
/// Gets or sets a value indicating whether connections should be closed upon going back to Discovery page
94+
/// </summary>
95+
public bool CloseConnectionsButton
96+
{
97+
get
98+
{
99+
return settings.CloseConnections;
100+
}
101+
102+
set
103+
{
104+
settings.CloseConnections = value;
105+
RaisePropertyChanged();
106+
}
107+
}
108+
91109
/// <summary>
92110
/// Gets or sets a value indicating whether light theme should be used
93111
/// </summary>

BluetoothLEExplorer/BluetoothLEExplorer/Views/SettingsPage.xaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,18 @@
7979
OffContent="Dark theme" OnContent="Light theme"
8080
RelativePanel.AlignLeftWithPanel="True"
8181
RelativePanel.Below="UseShellDrawnBackButtonToggleSwtich" />
82-
82+
8383
<ToggleSwitch x:Name="UseCachingToggleSwitch" Header="Use Caching"
8484
IsOn="{Binding UseCachingButton, Mode=TwoWay}"
8585
OffContent="Will make over the air requests if necessary based on GattRobustCaching if supported." OnContent="Will use locally cached values where possible."
8686
RelativePanel.AlignLeftWithPanel="True"
8787
RelativePanel.Below="UseLightThemeToggleSwitch" />
88+
89+
<ToggleSwitch x:Name="CloseConnectionsToggleSwitch" Header="Close Connections"
90+
IsOn="{Binding CloseConnectionsButton, Mode=TwoWay}"
91+
OffContent="Leave Bluetooth connections open while navigating the app." OnContent="Close Bluetooth connections upon navigating to Discovery page."
92+
RelativePanel.AlignLeftWithPanel="True"
93+
RelativePanel.Below="UseCachingToggleSwitch" />
8894
</RelativePanel>
8995

9096
</ScrollViewer>

0 commit comments

Comments
 (0)