From 0678f9a91f0dd14120c4879cb3eaa5e0965d5a60 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Sat, 25 Nov 2023 10:46:26 -0500 Subject: [PATCH] Improve testing model --- .../Sample.Maui/CurrentPermissionPage.xaml | 36 ++++++---- .../Sample.Maui/CurrentPermissionViewModel.cs | 71 +++++++++++++++---- 2 files changed, 81 insertions(+), 26 deletions(-) diff --git a/samples/Sample.Maui/CurrentPermissionPage.xaml b/samples/Sample.Maui/CurrentPermissionPage.xaml index 4867cd81b..b72c644d2 100644 --- a/samples/Sample.Maui/CurrentPermissionPage.xaml +++ b/samples/Sample.Maui/CurrentPermissionPage.xaml @@ -6,18 +6,28 @@ x:Class="Sample.CurrentPermissionPage" Title="Current Permissions"> - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/samples/Sample.Maui/CurrentPermissionViewModel.cs b/samples/Sample.Maui/CurrentPermissionViewModel.cs index b26892816..6f1069e53 100644 --- a/samples/Sample.Maui/CurrentPermissionViewModel.cs +++ b/samples/Sample.Maui/CurrentPermissionViewModel.cs @@ -17,28 +17,73 @@ BaseServices services { this.Refresh = ReactiveCommand.Create(() => { - this.BleClient = bleManager.CurrentAccess; - this.BleHostAdvertised = bleHostingManager.AdvertisingAccessStatus; - this.BleHostGatt = bleHostingManager.GattAccessStatus; - this.GpsInApp = gpsManager.GetCurrentStatus(GpsRequest.Foreground); - this.GpsBackground = gpsManager.GetCurrentStatus(GpsRequest.Realtime(false)); - this.Geofencing = geofenceManager.CurrentStatus; + this.PermissionSet = new List { + new PermissionViewModel( + "BLE Client", + () => bleManager.CurrentAccess, + () => bleManager.RequestAccess().ToTask() + ), + new PermissionViewModel( + "BLE Host - Advertising", + () => bleHostingManager.AdvertisingAccessStatus, + () => bleHostingManager.RequestAccess(true, false) + ), + new PermissionViewModel( + "BLE Host - GATT", + () => bleHostingManager.GattAccessStatus, + () => bleHostingManager.RequestAccess(false, true) + ), + new PermissionViewModel( + "GPS - In App", + () => gpsManager.GetCurrentStatus(GpsRequest.Foreground), + () => gpsManager.RequestAccess(GpsRequest.Foreground) + ), + new PermissionViewModel( + "GPS - Background", + () => gpsManager.GetCurrentStatus(GpsRequest.Realtime(false)), + () => gpsManager.RequestAccess(GpsRequest.Realtime(false)) + ), + new PermissionViewModel( + "Geofencing", + () => geofenceManager.CurrentStatus, + () => geofenceManager.RequestAccess() + ) + }; + this.RaisePropertyChanged(nameof(this.PermissionSet)); }); } public ICommand Refresh { get; } - [Reactive] public AccessState BleClient { get; private set; } - [Reactive] public AccessState BleHostGatt { get; private set; } - [Reactive] public AccessState BleHostAdvertised { get; private set; } - [Reactive] public AccessState GpsInApp { get; private set; } - [Reactive] public AccessState GpsBackground { get; private set; } - [Reactive] public AccessState Geofencing { get; private set; } - + public List PermissionSet { get; private set; } public override void OnAppearing() { base.OnAppearing(); this.Refresh.Execute(null); } +} + + +public class PermissionViewModel : ReactiveObject +{ + public PermissionViewModel( + string description, + Func getCurrent, + Func> requestAccess + ) + { + this.Description = description; + this.Status = getCurrent.Invoke(); + this.Request = ReactiveCommand.CreateFromTask(async () => + { + await requestAccess.Invoke(); + this.Status = getCurrent(); + }); + } + + + public ICommand Request { get; } + public string Description { get; } + [Reactive] public AccessState Status { get; private set; } } \ No newline at end of file