48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using FieldLogger.Models;
|
|
using FieldLogger.Services;
|
|
|
|
namespace FieldLogger.ViewModels;
|
|
|
|
public sealed partial class SettingsViewModel : ObservableObject
|
|
{
|
|
private readonly DeviceConnectionManager _manager;
|
|
|
|
public DeviceConnectionManager Manager => _manager;
|
|
|
|
public string AppVersion => AppInfo.Current.VersionString;
|
|
|
|
public SettingsViewModel(DeviceConnectionManager manager)
|
|
{
|
|
_manager = manager;
|
|
}
|
|
|
|
[RelayCommand]
|
|
private Task ChangeLocatorAsync() => Shell.Current.GoToAsync($"devicescan?kind={DeviceKind.Locator}");
|
|
|
|
[RelayCommand]
|
|
private Task ChangeGpsAsync() => Shell.Current.GoToAsync($"devicescan?kind={DeviceKind.RtkGps}");
|
|
|
|
[RelayCommand]
|
|
private Task OpenDebugAsync() => Shell.Current.GoToAsync("debug");
|
|
|
|
[RelayCommand]
|
|
private async Task ForgetLocatorAsync()
|
|
{
|
|
if (await ConfirmForgetAsync(_manager.LocatorName ?? "locating receiver"))
|
|
await _manager.ForgetDeviceAsync(DeviceKind.Locator);
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task ForgetGpsAsync()
|
|
{
|
|
if (await ConfirmForgetAsync(_manager.GpsName ?? "RTK GPS receiver"))
|
|
await _manager.ForgetDeviceAsync(DeviceKind.RtkGps);
|
|
}
|
|
|
|
private static Task<bool> ConfirmForgetAsync(string name) =>
|
|
Shell.Current.DisplayAlert("Forget Device",
|
|
$"Forget \"{name}\"? The app will no longer auto-connect to it.", "Forget", "Cancel");
|
|
}
|