Skip to content

Commit

Permalink
Planning
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Aug 27, 2024
1 parent 1b4138d commit 62a033f
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 40 deletions.
7 changes: 7 additions & 0 deletions Shiny.sln
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shiny.Firebase.Analytics.iO
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shiny.Firebase.Messaging.iOS.Binding", "src\Shiny.Firebase.Messaging.iOS.Binding\Shiny.Firebase.Messaging.iOS.Binding.csproj", "{F7E69503-E920-4E1E-8F7C-358DD7982738}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shiny.Ble.SetupAccessory", "src\Shiny.Ble.SetupAccessory\Shiny.Ble.SetupAccessory.csproj", "{117DC567-07E2-47BB-A8D8-65ED6C362DF8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -227,6 +229,10 @@ Global
{F7E69503-E920-4E1E-8F7C-358DD7982738}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7E69503-E920-4E1E-8F7C-358DD7982738}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7E69503-E920-4E1E-8F7C-358DD7982738}.Release|Any CPU.Build.0 = Release|Any CPU
{117DC567-07E2-47BB-A8D8-65ED6C362DF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{117DC567-07E2-47BB-A8D8-65ED6C362DF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{117DC567-07E2-47BB-A8D8-65ED6C362DF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{117DC567-07E2-47BB-A8D8-65ED6C362DF8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -261,6 +267,7 @@ Global
{A44BB6F8-283F-4FD7-9955-41B6B515AC98} = {6374E4D9-1BD8-4880-B603-AFDEA8345D7E}
{95304E51-AD99-41EA-A007-16F6FDCEC779} = {6374E4D9-1BD8-4880-B603-AFDEA8345D7E}
{F7E69503-E920-4E1E-8F7C-358DD7982738} = {6374E4D9-1BD8-4880-B603-AFDEA8345D7E}
{117DC567-07E2-47BB-A8D8-65ED6C362DF8} = {6374E4D9-1BD8-4880-B603-AFDEA8345D7E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {135D86AF-4EC4-4AA0-BD06-75C410F3EA08}
Expand Down
10 changes: 10 additions & 0 deletions src/Shiny.Ble.SetupAccessory/IAccessorySetupDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;
using Shiny.BluetoothLE;

namespace Shiny;


public interface IAccessorySetupDelegate
{
Task OnSetup(IPeripheral peripheral);
}
10 changes: 10 additions & 0 deletions src/Shiny.Ble.SetupAccessory/IAccessorySetupService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;

namespace Shiny;


public interface IAccessorySetupService
{
Task Listen();
Task Stop();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Shiny;

public class AndroidSetupAccessory
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Shiny;

// https://developer.apple.com/documentation/accessorysetupkit/
//https://www.youtube.com/watch?v=z0YDOmkVMmg
public class IosAccessorySetup
{

}
12 changes: 12 additions & 0 deletions src/Shiny.Ble.SetupAccessory/SetupAccessoryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.Extensions.DependencyInjection;

namespace Shiny;

public static class SetupAccessoryExtensions
{
public static IServiceCollection AddSetupAccessoryKit(this IServiceCollection services)
{

return services;
}
}
12 changes: 12 additions & 0 deletions src/Shiny.Ble.SetupAccessory/Shiny.Ble.SetupAccessory.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(DefaultTargetFrameworks);$(WindowsTarget)</TargetFrameworks>
<Description>Shiny BLE Setup Accessory Kit</Description>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Shiny.Core\Shiny.Core.csproj" />
<ProjectReference Include="..\Shiny.BluetoothLE\Shiny.BluetoothLE.csproj" />
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions src/Shiny.Core/ShinyConfigurator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.Extensions.DependencyInjection;

namespace Shiny;

public class ShinyConfigurator
{
// UseShiny off MauiBuilder would call this
public ShinyConfigurator(IServiceCollection services)
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,44 @@
namespace Shiny.Notifications;


public class AndroidNotificationManager
public class AndroidNotificationManager(
AndroidPlatform platform,
IChannelManager channelManager,
ISerializer serializer
)
{
public NotificationManagerCompat NativeManager { get; }
readonly AndroidPlatform platform;
readonly IChannelManager channelManager;
readonly ISerializer serializer;
public NotificationManagerCompat NativeManager => NotificationManagerCompat.From(platform.AppContext);


public AndroidNotificationManager(
AndroidPlatform platform,
IChannelManager channelManager,
ISerializer serializer
)
AlarmManager? alarms;
public AlarmManager Alarms
{
this.platform = platform;
this.NativeManager = NotificationManagerCompat.From(this.platform.AppContext);
this.channelManager = channelManager;
this.serializer = serializer;
}
get
{
if (this.alarms == null || this.alarms.Handle == IntPtr.Zero)
this.alarms = platform.GetSystemService<AlarmManager>(Context.AlarmService);

return this.alarms;
}
}


public virtual void Send(AndroidNotification notification)
{
var channel = this.channelManager.Get(notification.Channel!);
var channel = channelManager.Get(notification.Channel!);
var builder = this.CreateNativeBuilder(notification, channel!);
this.NativeManager.Notify(notification.Id, builder.Build());
}


public virtual NotificationCompat.Builder CreateNativeBuilder(AndroidNotification notification, Channel channel)
{
var builder = new NotificationCompat.Builder(this.platform.AppContext, channel.Identifier);
var builder = new NotificationCompat.Builder(platform.AppContext, channel.Identifier);
this.ApplyChannel(builder, notification, channel);

builder
.SetContentTitle(notification.Title)
.SetContentIntent(this.GetLaunchPendingIntent(notification))
.SetSmallIcon(this.platform.GetSmallIconResource(notification.SmallIconResourceName))
.SetSmallIcon(platform.GetSmallIconResource(notification.SmallIconResourceName))
.SetAutoCancel(notification.AutoCancel)
.SetOngoing(notification.OnGoing);

Expand All @@ -58,7 +58,7 @@ public virtual NotificationCompat.Builder CreateNativeBuilder(AndroidNotificatio
builder.SetGroup(notification.Thread);

//if (!notification.LocalAttachmentPath.IsEmpty())
// this.platform.TrySetImage(notification.LocalAttachmentPath, builder);
// platform.TrySetImage(notification.LocalAttachmentPath, builder);

//if (notification.BadgeCount != null)
//{
Expand All @@ -78,14 +78,14 @@ public virtual NotificationCompat.Builder CreateNativeBuilder(AndroidNotificatio

if (!notification.LargeIconResourceName.IsEmpty())
{
var iconId = this.platform.GetResourceIdByName(notification.LargeIconResourceName!);
var iconId = platform.GetResourceIdByName(notification.LargeIconResourceName!);
if (iconId > 0)
builder.SetLargeIcon(BitmapFactory.DecodeResource(this.platform.AppContext.Resources, iconId));
builder.SetLargeIcon(BitmapFactory.DecodeResource(platform.AppContext.Resources, iconId));
}

if (!notification.ColorResourceName.IsEmpty())
{
var color = this.platform.GetColorResourceId(notification.ColorResourceName!);
var color = platform.GetColorResourceId(notification.ColorResourceName!);
builder.SetColor(color);
}
return builder;
Expand All @@ -108,34 +108,30 @@ public void CancelAlarm(Notification notification)


protected virtual PendingIntent GetAlarmPendingIntent(Notification notification)
=> this.platform.GetBroadcastPendingIntent<ShinyNotificationBroadcastReceiver>(
=> platform.GetBroadcastPendingIntent<ShinyNotificationBroadcastReceiver>(
ShinyNotificationBroadcastReceiver.AlarmIntentAction,
PendingIntentFlags.UpdateCurrent,
0,
intent => intent.PutExtra(AndroidNotificationProcessor.IntentNotificationKey, notification.Id)
);


AlarmManager? alarms;
public AlarmManager Alarms => this.alarms ??= this.platform.GetSystemService<AlarmManager>(Context.AlarmService);



public virtual PendingIntent GetLaunchPendingIntent(AndroidNotification notification)
{
Intent launchIntent;

if (notification.LaunchActivityType == null)
{
launchIntent = this.platform!
launchIntent = platform
.AppContext!
.PackageManager!
.GetLaunchIntentForPackage(this.platform!.AppContext.PackageName!)!
.GetLaunchIntentForPackage(platform!.AppContext.PackageName!)!
.SetFlags(notification.LaunchActivityFlags);
}
else
{
launchIntent = new Intent(
this.platform.AppContext,
platform.AppContext,
notification.LaunchActivityType
);
}
Expand All @@ -146,20 +142,20 @@ public virtual PendingIntent GetLaunchPendingIntent(AndroidNotification notifica
if ((notification.LaunchActivityFlags & ActivityFlags.ClearTask) != 0)
{
pendingIntent = TaskStackBuilder
.Create(this.platform.AppContext)
.Create(platform.AppContext)
.AddNextIntent(launchIntent)
.GetPendingIntent(
notification.Id,
(int)this.platform.GetPendingIntentFlags(PendingIntentFlags.OneShot)
(int)platform.GetPendingIntentFlags(PendingIntentFlags.OneShot)
)!;
}
else
{
pendingIntent = PendingIntent.GetActivity(
this.platform.AppContext!,
platform.AppContext!,
notification.Id,
launchIntent!,
this.platform.GetPendingIntentFlags(PendingIntentFlags.OneShot)
platform.GetPendingIntentFlags(PendingIntentFlags.OneShot)
)!;
}
return pendingIntent;
Expand Down Expand Up @@ -202,7 +198,7 @@ public virtual void ApplyChannel(NotificationCompat.Builder builder, Notificatio

protected virtual void PopulateIntent(Intent intent, Notification notification)
{
var content = this.serializer.Serialize(notification);
var content = serializer.Serialize(notification);
intent.PutExtra(AndroidNotificationProcessor.IntentNotificationKey, content);
}

Expand All @@ -211,7 +207,7 @@ protected virtual void PopulateIntent(Intent intent, Notification notification)
protected virtual PendingIntent CreateActionIntent(Notification notification, ChannelAction action)
{
counter++;
return this.platform.GetBroadcastPendingIntent<ShinyNotificationBroadcastReceiver>(
return platform.GetBroadcastPendingIntent<ShinyNotificationBroadcastReceiver>(
ShinyNotificationBroadcastReceiver.EntryIntentAction,
PendingIntentFlags.UpdateCurrent,
counter,
Expand All @@ -227,7 +223,7 @@ protected virtual PendingIntent CreateActionIntent(Notification notification, Ch
protected virtual NotificationCompat.Action CreateAction(Notification notification, ChannelAction action)
{
var pendingIntent = this.CreateActionIntent(notification, action);
var iconId = this.platform.GetResourceIdByName(action.Identifier);
var iconId = platform.GetResourceIdByName(action.Identifier);
var nativeAction = new NotificationCompat.Action.Builder(iconId, action.Title, pendingIntent).Build();

return nativeAction;
Expand All @@ -241,7 +237,7 @@ protected virtual NotificationCompat.Action CreateTextReply(Notification notific
.SetLabel(action.Title)
.Build();

var iconId = this.platform.GetResourceIdByName(action.Identifier);
var iconId = platform.GetResourceIdByName(action.Identifier);
var nativeAction = new NotificationCompat.Action.Builder(iconId, action.Title, pendingIntent)
.SetAllowGeneratedReplies(true)
.AddRemoteInput(input)
Expand Down

0 comments on commit 62a033f

Please sign in to comment.