-
Notifications
You must be signed in to change notification settings - Fork 1
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
13 changed files
with
293 additions
and
6 deletions.
There are no files selected for viewing
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
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
64 changes: 64 additions & 0 deletions
64
...ekspro.RadioStorm.MAUI/Platforms/Android/Services/NotificationPermissionManagerAndroid.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,64 @@ | ||
using Android; | ||
using Android.Content; | ||
using Android.Content.PM; | ||
using AndroidX.Core.App; | ||
using AndroidX.Core.Content; | ||
|
||
#nullable disable | ||
|
||
namespace Pekspro.RadioStorm.MAUI.Platforms.Android.Services; | ||
|
||
public class NotificationPermissionManagerAndroid : INotificationPermissionManager | ||
{ | ||
private Context Context => Platform.AppContext; | ||
|
||
private global::Android.App.Activity Activity => Platform.CurrentActivity; | ||
|
||
public bool PermissionIsRequired => OperatingSystem.IsAndroidVersionAtLeast(33); | ||
|
||
public bool HasPermission | ||
{ | ||
get | ||
{ | ||
if (OperatingSystem.IsAndroidVersionAtLeast(33)) | ||
{ | ||
Permission permission = ContextCompat.CheckSelfPermission(Context, Manifest.Permission.PostNotifications); | ||
|
||
return permission == Permission.Granted; | ||
} | ||
else | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
public bool HasPermissionBeenDenied => ((MainActivity)Activity).HasNotificationPermissionBeenDenied; | ||
|
||
public bool ShouldExplainWhyPermissionsIsNeeded | ||
{ | ||
get | ||
{ | ||
if (OperatingSystem.IsAndroidVersionAtLeast(33)) | ||
{ | ||
return ActivityCompat.ShouldShowRequestPermissionRationale(Activity, Manifest.Permission.PostNotifications); | ||
} | ||
else | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
public void RequestPermission() | ||
{ | ||
if (HasPermissionBeenDenied || HasPermission) | ||
{ | ||
((MainActivity)Activity).OpenAppSettings(); | ||
} | ||
else | ||
{ | ||
((MainActivity)Activity).RequestNotificationPermission(); | ||
} | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
Source/Pekspro.RadioStorm.UI/Resources/Strings.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
14 changes: 14 additions & 0 deletions
14
Source/Pekspro.RadioStorm.UI/Utilities/INotificationPermissionManager.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,14 @@ | ||
namespace Pekspro.RadioStorm.UI.Utilities; | ||
|
||
public interface INotificationPermissionManager | ||
{ | ||
bool PermissionIsRequired { get; } | ||
|
||
bool HasPermission { get; } | ||
|
||
bool HasPermissionBeenDenied { get; } | ||
|
||
bool ShouldExplainWhyPermissionsIsNeeded { get; } | ||
|
||
void RequestPermission(); | ||
} |
3 changes: 3 additions & 0 deletions
3
Source/Pekspro.RadioStorm.UI/Utilities/NotificationPermissionChangedMessage.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,3 @@ | ||
namespace Pekspro.RadioStorm.UI.Utilities; | ||
|
||
public sealed record NotificationPermissionChangedMessage(); |
14 changes: 14 additions & 0 deletions
14
Source/Pekspro.RadioStorm.UI/Utilities/NotificationPermissionManagerDefault.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,14 @@ | ||
namespace Pekspro.RadioStorm.UI.Utilities; | ||
|
||
public class NotificationPermissionManagerDefault : INotificationPermissionManager | ||
{ | ||
public bool HasPermission => true; | ||
|
||
public bool HasPermissionBeenDenied => false; | ||
|
||
public bool PermissionIsRequired => false; | ||
|
||
public bool ShouldExplainWhyPermissionsIsNeeded => false; | ||
|
||
public void RequestPermission() { } | ||
} |
Oops, something went wrong.