Skip to content

Commit 3e259e1

Browse files
committed
Merge branch 'master' into v3.0
2 parents 6726941 + 2d50ac4 commit 3e259e1

File tree

10 files changed

+104
-48
lines changed

10 files changed

+104
-48
lines changed

samples/Sample.Maui/Gps/MyGpsDelegate.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,35 @@
33
namespace Sample.Gps;
44

55

6-
public partial class MyGpsDelegate : IGpsDelegate
6+
public partial class MyGpsDelegate : GpsDelegate
77
{
88
readonly SampleSqliteConnection conn;
9-
public MyGpsDelegate(SampleSqliteConnection conn) => this.conn = conn;
9+
public MyGpsDelegate(ILogger<MyGpsDelegate> logger, SampleSqliteConnection conn) : base(logger)
10+
{
11+
this.conn = conn;
12+
this.MinimumDistance = Distance.FromMeters(10);
13+
this.MinimumTime = TimeSpan.FromSeconds(10);
14+
}
1015

11-
public Task OnReading(GpsReading reading) => this.conn.Log(
16+
protected override Task OnGpsReading(GpsReading reading) => this.conn.Log(
1217
"GPS",
1318
$"{reading.Position.Latitude} / {reading.Position.Longitude} - H: {reading.Heading}",
1419
$"Accuracy: {reading.PositionAccuracy} - SP: {reading.Speed}",
1520
reading.Timestamp
1621
);
1722
}
23+
//public partial class MyGpsDelegate : IGpsDelegate
24+
//{
25+
// readonly SampleSqliteConnection conn;
26+
// public MyGpsDelegate(SampleSqliteConnection conn) => this.conn = conn;
27+
28+
// public Task OnReading(GpsReading reading) => this.conn.Log(
29+
// "GPS",
30+
// $"{reading.Position.Latitude} / {reading.Position.Longitude} - H: {reading.Heading}",
31+
// $"Accuracy: {reading.PositionAccuracy} - SP: {reading.Speed}",
32+
// reading.Timestamp
33+
// );
34+
//}
1835

1936
#if ANDROID
2037
public partial class MyGpsDelegate : IAndroidForegroundServiceDelegate

samples/Sample.Maui/Jobs/SampleJob.cs

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,52 @@
1-
using System;
2-
using System.Threading;
3-
using System.Threading.Tasks;
4-
using Shiny;
5-
using Shiny.Jobs;
1+
using Shiny.Jobs;
62
using Shiny.Notifications;
73

84
namespace Sample;
95

106

11-
public class SampleJob : IJob
7+
public partial class SampleJob : Job
128
{
139
readonly INotificationManager notificationManager;
14-
public SampleJob(INotificationManager notificationManager)
15-
=> this.notificationManager = notificationManager;
1610

17-
// TODO: test new object binding
11+
public SampleJob(ILogger<SampleJob> logger, INotificationManager notificationManager) : base(logger)
12+
{
13+
this.notificationManager = notificationManager;
14+
this.MinimumTime = TimeSpan.FromSeconds(50);
15+
}
1816

19-
public async Task Run(JobInfo jobInfo, CancellationToken cancelToken)
17+
protected override async Task Run(CancellationToken cancelToken)
2018
{
2119
await this.notificationManager.Send(
2220
"Jobs",
23-
$"Job Started - {jobInfo.Identifier}"
21+
$"Job Started - {this.JobInfo!.Identifier}"
2422
);
25-
//await Task.Delay(TimeSpan.FromSeconds(seconds), cancelToken);
2623

2724
await this.notificationManager.Send(
2825
"Jobs",
29-
$"Job Finished - {jobInfo.Identifier}"
26+
$"Job Finished - {this.JobInfo!.Identifier}"
3027
);
3128
}
3229
}
30+
31+
//public class SampleJob : IJob
32+
//{
33+
// readonly INotificationManager notificationManager;
34+
// public SampleJob(INotificationManager notificationManager)
35+
// => this.notificationManager = notificationManager;
36+
37+
// // TODO: test new object binding
38+
39+
// public async Task Run(JobInfo jobInfo, CancellationToken cancelToken)
40+
// {
41+
// await this.notificationManager.Send(
42+
// "Jobs",
43+
// $"Job Started - {jobInfo.Identifier}"
44+
// );
45+
// //await Task.Delay(TimeSpan.FromSeconds(seconds), cancelToken);
46+
47+
// await this.notificationManager.Send(
48+
// "Jobs",
49+
// $"Job Finished - {jobInfo.Identifier}"
50+
// );
51+
// }
52+
//}

samples/Sample.Maui/MauiProgram.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static MauiAppBuilder RegisterLogging(this MauiAppBuilder builder)
4545
static MauiAppBuilder RegisterShinyServices(this MauiAppBuilder builder)
4646
{
4747
var s = builder.Services;
48-
s.AddJob(typeof(SampleJob));
48+
s.AddJob(typeof(SampleJob), runInForeground: true);
4949

5050
// shiny.jobs
5151
//s.AddJobs();

src/Shiny.BluetoothLE.Hosting/Platforms/Apple/BleHostingManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using System.Reactive.Linq;
6+
using Foundation;
67
using CoreBluetooth;
78
using CoreLocation;
8-
using Foundation;
99

1010
namespace Shiny.BluetoothLE.Hosting;
1111

1212

1313
public partial class BleHostingManager : IBleHostingManager
1414
{
15-
CBPeripheralManager _manager;
15+
CBPeripheralManager manager;
1616
protected CBPeripheralManager Manager
1717
{
1818
get
1919
{
20-
this._manager ??= new();
21-
return this._manager;
20+
this.manager ??= new();
21+
return this.manager;
2222
}
2323
}
2424

src/Shiny.BluetoothLE.Hosting/Platforms/Shared/BleHostingManager.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#if ANDROID
1414
using Java.Util;
1515
using Shiny.BluetoothLE.Hosting.Internals;
16-
using Shiny.Reflection;
1716
#endif
1817

1918
namespace Shiny.BluetoothLE.Hosting;
@@ -40,16 +39,23 @@ IServiceProvider services
4039
#if ANDROID
4140
this.context = new GattServerContext(platform);
4241
#endif
43-
this.keyStore = keyStore;
4442
this.logger = logger;
43+
this.keyStore = keyStore;
4544
this.gattChars = services.GetLazyService<IEnumerable<BleGattCharacteristic>>();
4645
}
4746

4847

48+
const string REG_KEY = "BleHostingManager.IsRegisteredServicesAttached";
4949
public bool IsRegisteredServicesAttached
5050
{
51-
get => this.keyStore.DefaultStore.Get<bool>(nameof(this.IsRegisteredServicesAttached), false);
52-
private set => this.keyStore.DefaultStore.Set(nameof(this.IsRegisteredServicesAttached), value);
51+
get => this.keyStore.DefaultStore.Get(REG_KEY, false);
52+
set
53+
{
54+
if (value)
55+
this.keyStore.DefaultStore.Set(REG_KEY, true);
56+
else
57+
this.keyStore.DefaultStore.Remove(REG_KEY);
58+
}
5359
}
5460

5561

@@ -64,14 +70,17 @@ public async void Start()
6470
}
6571
catch (Exception ex)
6672
{
67-
this.logger.LogWarning("Unable to reattach BLE hosted characteristics", ex);
73+
this.logger.LogWarning(ex, "Unable to reattach BLE hosted characteristics");
6874
}
6975
}
7076
}
7177

7278

7379
public async Task AttachRegisteredServices()
7480
{
81+
if (this.IsRegisteredServicesAttached)
82+
return;
83+
7584
(await this.RequestAccess()).Assert();
7685

7786
this.gattServices ??= CollectServices(this.gattChars.Value);
@@ -90,12 +99,13 @@ public void DetachRegisteredServices()
9099
if (!this.IsRegisteredServicesAttached)
91100
return;
92101

93-
this.IsRegisteredServicesAttached = false;
94102
foreach (var serviceUuid in this.gattServices!.Keys)
95103
this.RemoveService(serviceUuid);
96104

97105
foreach (var ch in this.gattChars.Value)
98106
ch.OnStop(); // TODO: error trap this for user?
107+
108+
this.IsRegisteredServicesAttached = true;
99109
}
100110

101111

@@ -194,7 +204,7 @@ await characteristic
194204
}
195205
catch (Exception ex)
196206
{
197-
this.logger.LogError("Error executing BleGattService notification subscription", ex);
207+
this.logger.LogError(ex, "Error executing BleGattService notification subscription");
198208
}
199209
}, attribute.Notifications);
200210
}
@@ -220,7 +230,7 @@ await characteristic
220230
}
221231
catch (Exception ex)
222232
{
223-
this.logger.LogError("Error executing BleGattService request", ex);
233+
this.logger.LogError(ex, "Error executing BleGattService request");
224234
if (!writeSuccess)
225235
request.Respond(GattState.Failure);
226236
}

src/Shiny.Jobs/Job.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,27 @@ public async Task Run(JobInfo jobInfo, CancellationToken cancelToken)
1616
{
1717
var fireJob = true;
1818
this.JobInfo = jobInfo;
19-
20-
try
21-
{
22-
if (this.MinimumTime != null && this.LastRunTime != null)
23-
{
24-
var timeDiff = this.LastRunTime.Value.Subtract(DateTimeOffset.UtcNow);
25-
fireJob = timeDiff >= this.MinimumTime;
26-
this.Logger.LogDebug($"Time Difference: {timeDiff} - Firing Job: {fireJob}");
27-
}
28-
29-
if (fireJob)
30-
await this.Run(cancelToken).ConfigureAwait(false);
19+
20+
if (this.MinimumTime != null && this.LastRunTime != null)
21+
{
22+
var timeDiff = DateTimeOffset.UtcNow.Subtract(this.LastRunTime.Value);
23+
fireJob = timeDiff >= this.MinimumTime;
24+
this.Logger.LogDebug($"Time Difference: {timeDiff} - Firing Job: {fireJob}");
3125
}
32-
finally
26+
27+
if (fireJob)
3328
{
34-
if (fireJob)
35-
this.LastRunTime = DateTimeOffset.UtcNow;
29+
this.Logger.LogDebug("Running Job");
30+
await this.Run(cancelToken).ConfigureAwait(false);
31+
32+
// if the job errors, we will keep trying
33+
this.LastRunTime = DateTimeOffset.UtcNow;
3634
}
3735
}
3836

3937

4038
protected abstract Task Run(CancellationToken cancelToken);
41-
protected JobInfo? JobInfo { get; private set; }
39+
protected JobInfo JobInfo { get; private set; }
4240

4341
/// <summary>
4442
/// Last runtime of this job. Null if never run before.

src/Shiny.Notifications/Platforms/Android/AndroidNotification.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Android.Content;
3+
using AndroidX.Core.App;
34

45
namespace Shiny.Notifications;
56

@@ -10,6 +11,7 @@ public class AndroidNotification : Notification
1011
public bool OnGoing { get; set; }
1112
public string? Ticket { get; set; }
1213

14+
public string? Category { get; set; }
1315
public string? SmallIconResourceName { get; set; }
1416
public string? LargeIconResourceName { get; set; }
1517
public string? ColorResourceName { get; set; }

src/Shiny.Notifications/Platforms/Android/AndroidNotificationManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public virtual NotificationCompat.Builder CreateNativeBuilder(AndroidNotificatio
5151
.SetAutoCancel(notification.AutoCancel)
5252
.SetOngoing(notification.OnGoing);
5353

54+
if (!notification.Category.IsEmpty())
55+
builder.SetCategory(notification.Category);
56+
5457
if (!notification.Thread.IsEmpty())
5558
builder.SetGroup(notification.Thread);
5659

src/Shiny.Notifications/Platforms/Android/NotificationManager.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Reactive.Threading.Tasks;
55
using System.Threading.Tasks;
66
using Android.Content;
7+
using Android.OS;
78
using Microsoft.Extensions.Logging;
89
using Shiny.Hosting;
910
using Shiny.Locations;
@@ -14,12 +15,14 @@
1415
namespace Shiny.Notifications;
1516

1617

17-
public partial class NotificationManager : INotificationManager, IAndroidLifecycle.IOnActivityNewIntent
18+
public partial class NotificationManager : INotificationManager,
19+
IAndroidLifecycle.IOnActivityOnCreate,
20+
IAndroidLifecycle.IOnActivityNewIntent
1821
{
1922
readonly Lazy<AndroidNotificationProcessor> processor;
2023
readonly AndroidPlatform platform;
21-
readonly IChannelManager channelManager;
2224
readonly AndroidNotificationManager manager;
25+
readonly IChannelManager channelManager;
2326
readonly IRepository repository;
2427
readonly IGeofenceManager geofenceManager;
2528
readonly IKeyValueStore settings;
@@ -206,4 +209,7 @@ await this.processor.Value
206209
this.logger.LogError(ex, "Error trying to process intent");
207210
}
208211
}
212+
213+
public void ActivityOnCreate(Android.App.Activity activity, Bundle? savedInstanceState)
214+
=> this.Handle(activity, activity.Intent!);
209215
}

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "3.1.1",
3+
"version": "3.1.2",
44
"assemblyVersion": {
55
"precision": "revision"
66
},

0 commit comments

Comments
 (0)