Add domestic vendor push infrastructure
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:miaoji_zhang/shared/services/current_ledger_store.dart';
|
||||
import 'package:miaoji_zhang/shared/services/guest_merge_service.dart';
|
||||
import 'package:miaoji_zhang/shared/services/local_database.dart';
|
||||
import 'package:miaoji_zhang/shared/services/session_store.dart';
|
||||
import 'package:miaoji_zhang/shared/services/push_service.dart';
|
||||
import 'package:miaoji_zhang/shared/theme/app_theme.dart';
|
||||
import 'package:miaoji_zhang/shared/version.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/app_controls.dart';
|
||||
@@ -63,6 +64,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
_pass.text,
|
||||
);
|
||||
final profile = await AuthApi.me();
|
||||
await PushService.instance.refresh();
|
||||
await CurrentLedgerStore.instance.ensureLoaded(force: true);
|
||||
if (!mounted) return;
|
||||
if (guestSnapshot?['hasData'] == true) {
|
||||
|
||||
@@ -304,6 +304,14 @@ class _MePageState extends State<MePage> {
|
||||
'外观设置',
|
||||
onTap: () => context.push('/appearance'),
|
||||
),
|
||||
if (session.isAccount)
|
||||
_row(
|
||||
AppIcons.bell,
|
||||
context.jz.primaryBackground,
|
||||
AppTheme.primary,
|
||||
'通知设置',
|
||||
onTap: () => context.push('/notification-settings'),
|
||||
),
|
||||
if (session.isAccount &&
|
||||
SyncService.instance.conflictCount > 0)
|
||||
_row(
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:miaoji_zhang/shared/services/push_service.dart';
|
||||
import 'package:miaoji_zhang/shared/theme/app_theme.dart';
|
||||
import 'package:miaoji_zhang/shared/widgets/app_controls.dart';
|
||||
|
||||
class PushSettingsPage extends StatefulWidget {
|
||||
const PushSettingsPage({super.key});
|
||||
|
||||
@override
|
||||
State<PushSettingsPage> createState() => _PushSettingsPageState();
|
||||
}
|
||||
|
||||
class _PushSettingsPageState extends State<PushSettingsPage> {
|
||||
final service = PushService.instance;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
service.addListener(_changed);
|
||||
service.refresh();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
service.removeListener(_changed);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _changed() {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
Future<void> _toggle(String category, bool value) async {
|
||||
final ok = await service.setCategory(category, value);
|
||||
if (!ok && mounted && service.lastError != null) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(service.lastError!)));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final status = service.nativeStatus;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('通知设置')),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 24),
|
||||
children: [
|
||||
Card(
|
||||
child: Column(
|
||||
children: [
|
||||
_switchRow(
|
||||
'系统通知',
|
||||
'版本更新和重要服务状态',
|
||||
service.preferences.system,
|
||||
(value) => _toggle('system', value),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
_switchRow(
|
||||
'预算提醒',
|
||||
'预算达到 80% 或 100% 时提醒',
|
||||
service.preferences.budget,
|
||||
(value) => _toggle('budget', value),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
_switchRow(
|
||||
'运营通知',
|
||||
'活动和产品公告',
|
||||
service.preferences.operations,
|
||||
(value) => _toggle('operations', value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'推送通道',
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w800),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_providerLabel(status.provider),
|
||||
style: TextStyle(color: context.jz.text2, fontSize: 12),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
_statusLabel(status),
|
||||
style: TextStyle(
|
||||
color: status.notificationsAllowed
|
||||
? context.jz.text2
|
||||
: AppTheme.orange,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
if (!status.notificationsAllowed) ...[
|
||||
const SizedBox(height: 12),
|
||||
JzActionButton(
|
||||
label: '打开系统通知设置',
|
||||
onPressed: service.openNotificationSettings,
|
||||
secondary: true,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (service.loading) ...[
|
||||
const SizedBox(height: 16),
|
||||
const Center(child: CircularProgressIndicator(strokeWidth: 2)),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _switchRow(
|
||||
String title,
|
||||
String subtitle,
|
||||
bool value,
|
||||
ValueChanged<bool> onChanged,
|
||||
) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: const TextStyle(fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(color: context.jz.text2, fontSize: 11.5),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Switch(value: value, onChanged: service.loading ? null : onChanged),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
String _providerLabel(String? provider) => switch (provider) {
|
||||
'huawei' => '华为 Push Kit',
|
||||
'honor' => '荣耀 Push Kit',
|
||||
'xiaomi' => '小米推送',
|
||||
'oppo' => 'OPPO 推送',
|
||||
'vivo' => 'vivo 推送',
|
||||
'meizu' => '魅族推送',
|
||||
_ => '当前设备没有可用的国产厂商通道',
|
||||
};
|
||||
|
||||
String _statusLabel(PushNativeStatus status) {
|
||||
if (!status.supported) return '不支持';
|
||||
if (!status.sdkAvailable) return '当前安装包未配置对应厂商 SDK';
|
||||
if (!status.notificationsAllowed) return '系统通知权限已关闭';
|
||||
if (status.token?.isNotEmpty == true) return '已连接';
|
||||
if (status.enabled) return '正在获取厂商令牌';
|
||||
return '未启用';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user