-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
137 additions
and
76 deletions.
There are no files selected for viewing
6 changes: 2 additions & 4 deletions
6
src/Shiny.BluetoothLE/Platforms/Android/AndroidConnectionConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
using Android.Bluetooth; | ||
|
||
namespace Shiny.BluetoothLE; | ||
namespace Shiny.BluetoothLE; | ||
|
||
|
||
public record AndroidConnectionConfig( | ||
bool AutoConnect = true, | ||
GattConnectionPriority ConnectionPriority = GattConnectionPriority.Balanced | ||
Android.Bluetooth.GattConnectionPriority ConnectionPriority = Android.Bluetooth.GattConnectionPriority.Balanced | ||
) : ConnectionConfig( | ||
AutoConnect | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/Shiny.Push/Platforms/Android/AndroidPushNotification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using Android.App; | ||
using Android.Content; | ||
using AndroidX.Core.App; | ||
using Firebase.Messaging; | ||
|
||
namespace Shiny.Push; | ||
|
||
|
||
public record AndroidPushNotification( | ||
Notification? Notification, | ||
RemoteMessage NativeMessage, | ||
FirebaseConfig Config, | ||
AndroidPlatform Platform | ||
) : PushNotification(NativeMessage.Data, Notification) | ||
{ | ||
|
||
public NotificationCompat.Builder CreateBuilder() | ||
{ | ||
var not = this.NativeMessage.GetNotification(); | ||
var channelId = not.ChannelId ?? this.Config.DefaultChannel?.Id; | ||
var builder = new NotificationCompat.Builder(this.Platform.AppContext, channelId!)!; | ||
|
||
if (not != null) | ||
{ | ||
var intent = new Intent(not.ClickAction ?? ShinyPushIntents.NotificationClickAction); | ||
foreach (var item in this.NativeMessage.Data) | ||
intent.PutExtra(item.Key, item.Value); | ||
|
||
var pendingIntent = PendingIntent.GetActivity( | ||
this.Platform.AppContext, | ||
99, | ||
intent, | ||
PendingIntentFlags.OneShot | PendingIntentFlags.Immutable | ||
); | ||
|
||
builder | ||
.SetContentTitle(not.Title) | ||
.SetContentIntent(pendingIntent); | ||
|
||
if (!not.Body.IsEmpty()) | ||
builder.SetContentText(not.Body); | ||
|
||
if (!not.Ticker.IsEmpty()) | ||
builder.SetTicker(not.Ticker); | ||
|
||
if (not.Icon.IsEmpty()) | ||
{ | ||
var id = this.Platform.GetDrawableByName("notification"); | ||
if (id > 0) | ||
{ | ||
builder.SetSmallIcon(id); | ||
} | ||
else if (this.Platform.AppContext.ApplicationInfo!.Icon > 0) | ||
{ | ||
builder.SetSmallIcon(this.Platform.AppContext.ApplicationInfo!.Icon); | ||
} | ||
} | ||
else | ||
{ | ||
var drawableId = this.Platform.GetDrawableByName(not.Icon); | ||
builder.SetSmallIcon(drawableId); | ||
} | ||
|
||
if (!not.Color.IsEmpty()) | ||
{ | ||
var colorId = this.Platform | ||
.AppContext | ||
.Resources! | ||
.GetIdentifier( | ||
not.Color, | ||
"color", | ||
this.Platform.AppContext.PackageName | ||
); | ||
|
||
builder.SetColor(colorId); | ||
} | ||
} | ||
return builder; | ||
} | ||
|
||
|
||
public void Notify(int notificationId, NotificationCompat.Builder builder) | ||
{ | ||
using var service = this.Platform.GetSystemService<NotificationManager>(Context.NotificationService); | ||
service.Notify(notificationId, builder.Build()); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// This will create the default builder and send it | ||
/// </summary> | ||
public void SendDefault(int notificationId) | ||
{ | ||
var builder = this.CreateBuilder(); | ||
this.Notify(notificationId, builder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters