XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

STHApplication

【MAUI】寄当家——安卓端交易管理系统

公开
关注 0 Fork 0 Star 0
UTF-8
using JiDangJia.Services;

namespace JiDangJia.Views;

public sealed class NotificationSettingsPage : ContentPage
{
    private readonly Label state=Ui.Text("",14,Ui.Bronze);
    public NotificationSettingsPage()
    {
        Title="通知与提醒";var body=Ui.Stack();body.Padding=18;
        body.Add(Ui.Card(Ui.Stack(Ui.Section("系统通知"),state,Ui.Text("声音跟随系统通知音。锁屏仅显示通用提示,不展示任何内容。",13,Ui.Muted),Ui.Button("开启通知",Enable),Ui.Button("系统通知设置",Settings,false))));
#if COMMUNITY_APP
        body.Add(Ui.Card(Ui.Stack(Ui.Section("私信提醒"),Ui.Text("打开应用时自动检查新私信,后台由系统定期检查。省电限制和网络状况可能影响后台到达时间。",13,Ui.Muted))));
#else
        body.Add(Ui.Card(Ui.Stack(Ui.Section("到期提醒"),Ui.Text("未结清的业务在到期前 7 天和到期当天各提醒一次;归还、结清、删除或更改到期日期后,提醒随之更新。",13,Ui.Muted))));
#endif
        Content=new ScrollView{Content=body};
    }
    protected override void OnAppearing(){base.OnAppearing();Refresh();}
    private void Refresh()
    {
#if ANDROID
        state.Text=NotificationPlatform.Allowed?"通知已开启":"通知未开启,请允许系统通知";
#else
        state.Text="此设备暂不支持系统提醒";
#endif
    }
    private async Task Enable()
    {
#if ANDROID
        await NotificationPlatform.RequestPermission();NotificationPlatform.Reschedule();NotificationPlatform.ScheduleInbox();Refresh();await AppNotifications.CheckInbox();if(!NotificationPlatform.Allowed)NotificationPlatform.OpenSettings();
#else
        await DisplayAlertAsync("通知","此设备暂不支持系统提醒。","知道了");
#endif
    }
    private Task Settings()
    {
#if ANDROID
        NotificationPlatform.OpenSettings();
#endif
        return Task.CompletedTask;
    }
}