Layout and Push Fix

This commit is contained in:
2026-03-28 23:44:56 +01:00
parent 74722b5e81
commit cf3d7557aa
13 changed files with 429 additions and 282 deletions
@@ -1,5 +1,6 @@
using Android.App;
using Android.Content;
using Android.Provider;
using AndroidX.Core.App;
using cfs_tracker.Data;
using cfs_tracker.Helpers;
@@ -54,12 +55,29 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
public async Task<bool> EnsurePermissionAsync()
{
var status = await Permissions.CheckStatusAsync<NotificationPermission>();
if (status == PermissionStatus.Granted)
var notificationStatus = await Permissions.CheckStatusAsync<NotificationPermission>();
if (notificationStatus != PermissionStatus.Granted)
{
notificationStatus = await Permissions.RequestAsync<NotificationPermission>();
if (notificationStatus != PermissionStatus.Granted)
return false;
}
if (!OperatingSystem.IsAndroidVersionAtLeast(31))
return true;
status = await Permissions.RequestAsync<NotificationPermission>();
return status == PermissionStatus.Granted;
var context = Platform.AppContext;
var alarmManager = (AlarmManager?)context.GetSystemService(Context.AlarmService);
if (alarmManager is null || alarmManager.CanScheduleExactAlarms())
return true;
var intent = new Intent(Settings.ActionRequestScheduleExactAlarm);
intent.SetData(global::Android.Net.Uri.Parse($"package:{context.PackageName}"));
intent.AddFlags(ActivityFlags.NewTask);
context.StartActivity(intent);
return false;
}
public Task<bool> GetVibrationEnabledAsync() =>
@@ -78,8 +96,8 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
CancelAllScheduled(context);
var granted = await EnsurePermissionAsync();
if (!granted)
var notificationStatus = await Permissions.CheckStatusAsync<NotificationPermission>();
if (notificationStatus != PermissionStatus.Granted)
return;
SaveActionLabelsToPreferences();
@@ -143,10 +161,19 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
var when = triggerAt.ToUnixTimeMilliseconds();
if (CanUseExactAlarms(context, alarmManager))
{
alarmManager.SetExactAndAllowWhileIdle(AlarmType.RtcWakeup, when, pendingIntent);
return;
}
if (OperatingSystem.IsAndroidVersionAtLeast(23))
{
alarmManager.SetAndAllowWhileIdle(AlarmType.RtcWakeup, when, pendingIntent);
else
alarmManager.Set(AlarmType.RtcWakeup, when, pendingIntent);
return;
}
alarmManager.Set(AlarmType.RtcWakeup, when, pendingIntent);
}
internal static void ShowNotification(
@@ -293,6 +320,14 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
Preferences.Default.Remove(PrefScheduledIds);
}
private static bool CanUseExactAlarms(Context context, AlarmManager alarmManager)
{
if (!OperatingSystem.IsAndroidVersionAtLeast(31))
return true;
return alarmManager.CanScheduleExactAlarms();
}
private static PendingIntentFlags BuildPendingIntentFlags()
{
var flags = PendingIntentFlags.UpdateCurrent;
@@ -352,4 +387,4 @@ public sealed class AndroidNotificationScheduler : INotificationScheduler
if (flags.HasFlag(NotificationWeekdays.Saturday)) yield return DayOfWeek.Saturday;
if (flags.HasFlag(NotificationWeekdays.Sunday)) yield return DayOfWeek.Sunday;
}
}
}