Skip to content

Commit

Permalink
code update
Browse files Browse the repository at this point in the history
  • Loading branch information
thudugala committed Feb 21, 2024
1 parent a7558ea commit e9d63d2
Show file tree
Hide file tree
Showing 38 changed files with 537 additions and 465 deletions.
9 changes: 6 additions & 3 deletions Sample/Direct Maui/LocalNotification.Sample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ private async void Button_Clicked(object sender, EventArgs e)
{
ResourceName = "colorPrimary"
},
IsProgressBarIndeterminate = false,
ProgressBarMax = 20,
ProgressBarProgress = _tapCount,
ProgressBar =
{
IsIndeterminate = false,
Max = 20,
Progress = _tapCount
},
Priority = AndroidPriority.High
//AutoCancel = false,
//Ongoing = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Plugin.LocalNotification.Platforms;
using Plugin.LocalNotification;
using Plugin.LocalNotification.Platforms;
using UserNotifications;

namespace LocalNotification.Sample;
Expand All @@ -12,7 +13,7 @@ public override void DidReceiveNotificationResponse(UNUserNotificationCenter cen
// if the Notification is type Plugin.LocalNotification.NotificationRequest
// call the base method, else handel it by your self.

var notificationRequest = TryGetDefaultIOsNotificationService().GetRequest(response.Notification.Request.Content);
var notificationRequest = LocalNotificationCenter.GetRequest(response.Notification.Request.Content);
if (notificationRequest != null)
{
base.DidReceiveNotificationResponse(center, response, completionHandler);
Expand All @@ -25,7 +26,12 @@ public override void WillPresentNotification(UNUserNotificationCenter center, UN
// if the Notification is type Plugin.LocalNotification.NotificationRequest
// call the base method, else handel it by your self.

var notificationRequest = TryGetDefaultIOsNotificationService().GetRequest(notification?.Request.Content);
if (notification is null)
{
return;
}

var notificationRequest = LocalNotificationCenter.GetRequest(notification?.Request.Content);

if (notificationRequest != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public AndroidColor(string resourceName)
/// <summary>
///
/// </summary>
public string ResourceName { get; set; }
public string ResourceName { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public AndroidIcon(string resourceName, string type)
/// <summary>
/// The name of the desired resource
/// </summary>
public string ResourceName { get; set; }
public string ResourceName { get; set; } = string.Empty;

/// <summary>
/// Optional default resource type to find, if "type/" is
Expand Down
19 changes: 19 additions & 0 deletions Source/Plugin.LocalNotification/AndroidOption/AndroidLaunch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Plugin.LocalNotification.AndroidOption
{
/// <summary>
/// Launch the App instead of posting the notification to the status bar.
/// Only for use with extremely high-priority notifications demanding the user's immediate attention,
/// such as an incoming phone call or alarm clock that the user has explicitly set to a particular time.
/// If this facility is used for something else, please give the user an option to turn it off and use a normal notification, as this can be extremely disruptive.
/// The system UI may choose to display a heads-up notification, instead of launching this app, while the user is using the device.
/// Apps targeting Android Q 10 (29) and above will have to request a permission (Manifest.permission.USE_FULL_SCREEN_INTENT) in order to use full screen intents.
/// To be launched, the notification must also be posted to a channel with importance level set to IMPORTANCE_HIGH or higher.
/// </summary>
public class AndroidLaunch
{
/// <summary>
/// Passing true will cause this notification to be sent even if other notifications are suppressed. the default is true.
/// </summary>
public bool InHighPriority { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,13 @@ public class AndroidLocalNotificationBuilder : IAndroidLocalNotificationBuilder
/// <summary>
///
/// </summary>
public IList<NotificationChannelRequest> ChannelRequestList { get; }
public IList<NotificationChannelRequest> ChannelRequestList { get; } = new List<NotificationChannelRequest>();

/// <summary>
///
/// </summary>
public IList<NotificationChannelGroupRequest> GroupChannelRequestList { get; }

/// <summary>
///
/// </summary>
public AndroidLocalNotificationBuilder()
{
ChannelRequestList = new List<NotificationChannelRequest>();
GroupChannelRequestList = new List<NotificationChannelGroupRequest>();
}

public IList<NotificationChannelGroupRequest> GroupChannelRequestList { get; } = new List<NotificationChannelGroupRequest>();

/// <inheritdoc/>
public IAndroidLocalNotificationBuilder AddChannel(NotificationChannelRequest channelRequest)
{
Expand Down
48 changes: 28 additions & 20 deletions Source/Plugin.LocalNotification/AndroidOption/AndroidOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ public class AndroidOptions
/// <summary>
/// If set, the notification icon and application name will have the provided ARGB color.
/// </summary>
public AndroidColor Color { get; set; } = new ();
public AndroidColor Color { get; set; } = new();

/// <summary>
/// if Set, find the icon by name from drawable and set it has the Large Icon to use in the notification layouts.
/// if not set, application Icon will we used.
/// </summary>
public AndroidIcon IconLargeName { get; set; } = new ();
public AndroidIcon IconLargeName { get; set; } = new();

/// <summary>
/// if Set, find the icon by name from drawable and set it has the Small Icon to use in the notification layouts.
/// if not set, application Icon will we used.
/// </summary>
public AndroidIcon IconSmallName { get; set; } = new ();
public AndroidIcon IconSmallName { get; set; } = new();

/// <summary>
/// Set this notification to be the group summary for a group of notifications.
Expand All @@ -63,9 +63,20 @@ public class AndroidOptions
public bool IsGroupSummary { get; set; }

/// <summary>
/// Set whether this progress bar is in indeterminate mode
/// Launch the App instead of posting the notification to the status bar.
/// Only for use with extremely high-priority notifications demanding the user's immediate attention,
/// such as an incoming phone call or alarm clock that the user has explicitly set to a particular time.
/// If this facility is used for something else, please give the user an option to turn it off and use a normal notification, as this can be extremely disruptive.
/// The system UI may choose to display a heads-up notification, instead of launching this app, while the user is using the device.
/// Apps targeting Android Q 10 (29) and above will have to request a permission (Manifest.permission.USE_FULL_SCREEN_INTENT) in order to use full screen intents.
/// To be launched, the notification must also be posted to a channel with importance level set to IMPORTANCE_HIGH or higher.
/// </summary>
public AndroidLaunch LaunchApp { get; set; }

/// <summary>
/// Default is true
/// </summary>
public bool? IsProgressBarIndeterminate { get; set; }
public bool LaunchAppWhenTapped { get; set; } = true;

/// <summary>
/// If set, the LED will have the provided ARGB color.
Expand All @@ -81,6 +92,11 @@ public class AndroidOptions
/// </summary>
public bool Ongoing { get; set; }

/// <summary>
///
/// </summary>
public AndroidPendingIntentFlags PendingIntentFlags { get; set; } = AndroidPendingIntentFlags.UpdateCurrent;

/// <summary>
/// Set the relative priority for this notification.
/// In Android, Only used if Android Api below 26.
Expand All @@ -89,14 +105,9 @@ public class AndroidOptions
public AndroidPriority Priority { get; set; } = AndroidPriority.Default;

/// <summary>
/// Set Upper limit of this progress bar's range
/// Set the progress this notification represents. The platform template will represent this using a ProgressBar.
/// </summary>
public int? ProgressBarMax { get; set; }

/// <summary>
/// Set progress bar's current level of progress
/// </summary>
public int? ProgressBarProgress { get; set; }
public AndroidProgressBar? ProgressBar { get; set; }

Check warning on line 110 in Source/Plugin.LocalNotification/AndroidOption/AndroidOptions.cs

View workflow job for this annotation

GitHub Actions / nuget

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 110 in Source/Plugin.LocalNotification/AndroidOption/AndroidOptions.cs

View workflow job for this annotation

GitHub Actions / nuget

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 110 in Source/Plugin.LocalNotification/AndroidOption/AndroidOptions.cs

View workflow job for this annotation

GitHub Actions / nuget

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 110 in Source/Plugin.LocalNotification/AndroidOption/AndroidOptions.cs

View workflow job for this annotation

GitHub Actions / nuget

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 110 in Source/Plugin.LocalNotification/AndroidOption/AndroidOptions.cs

View workflow job for this annotation

GitHub Actions / nuget

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 110 in Source/Plugin.LocalNotification/AndroidOption/AndroidOptions.cs

View workflow job for this annotation

GitHub Actions / nuget

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// Specifies the time at which this notification should be canceled, if it is not already canceled.
Expand All @@ -109,6 +120,8 @@ public class AndroidOptions
/// The first value indicates the number of milliseconds to wait before turning the vibrator on.
/// The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off.
/// Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.
///
/// This method was deprecated in API level 26. use NotificationChannel
/// </summary>
public long[] VibrationPattern { get; set; }

Expand All @@ -119,13 +132,8 @@ public class AndroidOptions
public AndroidVisibilityType VisibilityType { get; set; } = AndroidVisibilityType.Private;

/// <summary>
/// Default is true
/// DateTime set with When is shown in the content view.
/// </summary>
public bool LaunchAppWhenTapped { get; set; } = true;

/// <summary>
///
/// </summary>
public AndroidPendingIntentFlags PendingIntentFlags { get; set; } = AndroidPendingIntentFlags.UpdateCurrent;
public DateTime? When { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Plugin.LocalNotification.AndroidOption
{
/// <summary>
/// Set the progress this notification represents. The platform template will represent this using a ProgressBar.
/// </summary>
public class AndroidProgressBar
{
/// <summary>
/// Set whether this progress bar is in indeterminate mode
/// </summary>
public bool IsIndeterminate { get; set; }

/// <summary>
/// Set Upper limit of this progress bar's range
/// </summary>
public int Max { get; set; }

/// <summary>
/// Set progress bar's current level of progress
/// </summary>
public int Progress { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ public class AndroidScheduleOptions
}

var repeatInterval = GetNotifyRepeatInterval(repeatType, notifyRepeatInterval);
if (repeatInterval is null)
if (repeatInterval == TimeSpan.Zero)
{
return null;
}

var newNotifyTime = notifyTime.Value.Add(repeatInterval.Value);
var newNotifyTime = notifyTime.Value.Add(repeatInterval);
var nowTime = DateTime.Now.AddSeconds(10);
while (newNotifyTime <= nowTime)
{
newNotifyTime = newNotifyTime.Add(repeatInterval.Value);
newNotifyTime = newNotifyTime.Add(repeatInterval);
}
return newNotifyTime;
}
Expand All @@ -49,9 +49,9 @@ public class AndroidScheduleOptions
/// internal use, only for Android
/// </summary>
/// <returns></returns>
internal TimeSpan? GetNotifyRepeatInterval(NotificationRepeat repeatType, TimeSpan? notifyRepeatInterval)
internal TimeSpan GetNotifyRepeatInterval(NotificationRepeat repeatType, TimeSpan? notifyRepeatInterval)
{
TimeSpan? repeatInterval = null;
var repeatInterval = TimeSpan.Zero;
switch (repeatType)
{
case NotificationRepeat.Daily:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
public interface IAndroidLocalNotificationBuilder
{
/// <summary>
/// A representation of settings that apply to a collection of similarly themed notifications
/// A representation of settings that apply to a collection of similarly themed notifications.
/// Create Notification Channel when API >= 26.
/// </summary>
/// <param name="channelRequest"></param>
/// <returns></returns>
IAndroidLocalNotificationBuilder AddChannel(NotificationChannelRequest channelRequest);

/// <summary>
/// A grouping of related notification channels. e.g., channels that all belong to a single account.
/// Create Notification Channel Group when API >= 26.
/// If you'd like to further organize the appearance of your channels in the settings UI, you can create channel groups.
/// This is a good idea when your app supports multiple user accounts (such as for work profiles),
/// so you can create a notification channel group for each account.
/// This way, users can easily identify and control multiple notification channels that have identical names.
/// </summary>
/// <param name="groupChannelRequest"></param>
/// <returns></returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@
/// </summary>
public class NotificationChannelGroupRequest
{
private string group = AndroidOptions.DefaultGroupId;
private string name = AndroidOptions.DefaultGroupName;

/// <summary>
/// The id of the group. Must be unique per package. the value may be truncated if it is too long
/// </summary>
public string Group { get; set; } = AndroidOptions.DefaultGroupId;

public string Group
{
get => string.IsNullOrWhiteSpace(group) ? AndroidOptions.DefaultGroupId : group;
set => group = string.IsNullOrWhiteSpace(value) ? AndroidOptions.DefaultGroupId : value;
}
/// <summary>
/// The user visible name of the group, The recommended maximum length is 40 characters; the value may be truncated if it is too long.
/// </summary>
public string Name { get; set; } = AndroidOptions.DefaultGroupName;
public string Name
{
get => string.IsNullOrWhiteSpace(name) ? AndroidOptions.DefaultGroupName : name;
set => name = string.IsNullOrWhiteSpace(value) ? AndroidOptions.DefaultGroupName : value;
}

/// <summary>
/// Constructor to pass values directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
/// </summary>
public class NotificationChannelRequest
{
private string id = AndroidOptions.DefaultChannelId;
private string name = AndroidOptions.DefaultChannelName;

/// <summary>
/// Sets or gets, the level of interruption of this notification channel.
/// </summary>
Expand All @@ -14,33 +17,41 @@ public class NotificationChannelRequest
/// Sets or gets, The id of the channel. Must be unique per package. The value may be truncated if it is too lon
/// Also, NotificationRequest.Android.ChannelId must be set to the same Id to target this channel.
/// </summary>
public string Id { get; set; } = AndroidOptions.DefaultChannelId;
public string Id
{
get => string.IsNullOrWhiteSpace(id) ? AndroidOptions.DefaultChannelId : id;
set => id = string.IsNullOrWhiteSpace(value) ? AndroidOptions.DefaultChannelId : value;
}

/// <summary>
/// Sets or gets, the user visible name of this channel, default is General.
/// </summary>
public string Name { get; set; } = AndroidOptions.DefaultChannelName;
public string Name
{
get => string.IsNullOrWhiteSpace(name) ? AndroidOptions.DefaultChannelName : name;
set => name = string.IsNullOrWhiteSpace(value) ? AndroidOptions.DefaultChannelName : value;
}

/// <summary>
/// Sets or gets, the user visible description of this channel.
/// </summary>
public string Description { get; set; }
public string Description { get; set; } = string.Empty;

/// <summary>
/// Sets or gets, what group this channel belongs to.
/// </summary>
public string Group { get; set; }
public string Group { get; set; } = string.Empty;

/// <summary>
/// Sets or gets, the notification light color for notifications posted to this channel,
/// if the device supports that feature
/// </summary>
public AndroidColor LightColor { get; set; }
public AndroidColor LightColor { get; set; } = new();

/// <summary>
/// Sound file name for the notification.
/// </summary>
public string Sound { get; set; }
public string Sound { get; set; } = string.Empty;

/// <summary>
/// Sets or gets, Sets whether notification posted to this channel should play sound.
Expand Down Expand Up @@ -75,6 +86,6 @@ public class NotificationChannelRequest
/// <summary>
/// Sets or gets, Sets whether notification posted to this channel can bypass DND (Do Not Disturb) mode.
/// </summary>
public bool CanBypassDnd { get; set; } = false;
public bool CanBypassDnd { get; set; } = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public class NotificationEventArgs : System.EventArgs
/// <summary>
/// Returning notification.
/// </summary>
public NotificationRequest Request { get; set; }
public NotificationRequest Request { get; set; } = new();
}
}
Loading

0 comments on commit e9d63d2

Please sign in to comment.