diff --git a/lib/providers/user_provider.dart b/lib/providers/user_provider.dart index 863364c..d03134d 100644 --- a/lib/providers/user_provider.dart +++ b/lib/providers/user_provider.dart @@ -55,6 +55,8 @@ class UserProvider extends ChangeNotifier { await updateUserInfo(); updateConSms(); updateRefSms(); + updateCallSms(); + updateIdleSms(); getExclude(); } @@ -121,14 +123,14 @@ class UserProvider extends ChangeNotifier { notifyListeners(); } - Future updateSms() async { + Future updateCallSms() async { final prefs = await SharedPreferences.getInstance(); final service = FlutterBackgroundService(); - var base = await apiClient.request(API.content.find, data: {'status': 2}); + var base = await apiClient.request(API.content.find, data: {'status': 3}); if (base.code == 0) { - await prefs.remove('refSms'); + await prefs.remove('callSms'); await prefs.setString( - 'refSms', + 'callSms', (UserTool.userProvider.userInfo.tag) == "" ? "${base.data['content']}" : "【${UserTool.userProvider.userInfo.tag}】${base.data['content']}"); @@ -147,11 +149,11 @@ class UserProvider extends ChangeNotifier { Future updateIdleSms() async { final prefs = await SharedPreferences.getInstance(); final service = FlutterBackgroundService(); - var base = await apiClient.request(API.content.find, data: {'status': 2}); + var base = await apiClient.request(API.content.find, data: {'status': 4}); if (base.code == 0) { - await prefs.remove('refSms'); + await prefs.remove('idleSms'); await prefs.setString( - 'refSms', + 'idleSms', (UserTool.userProvider.userInfo.tag) == "" ? "${base.data['content']}" : "【${UserTool.userProvider.userInfo.tag}】${base.data['content']}"); diff --git a/lib/ui/home/call.dart b/lib/ui/home/call.dart index 89baae4..05f6063 100644 --- a/lib/ui/home/call.dart +++ b/lib/ui/home/call.dart @@ -61,6 +61,8 @@ void onStart(ServiceInstance service) async { print(callState+"$flag"); String? ref = prefs.getString('refSms'); String? con = prefs.getString('conSms'); + String? call = prefs.getString('callSms'); + String? idle = prefs.getString('idleSms'); if (callState == "IDLE") { if (flag != 0) { final Iterable entry = await CallLog.query(); @@ -75,11 +77,11 @@ void onStart(ServiceInstance service) async { print("来电接听"); Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!); }else { - print(entry.first.callType); - print(entry.first.duration); if(entry.first.duration!>0){ + Telephony.backgroundInstance.sendSms(to: phoneNum!, message: call!); print("去电接听"); }else{ + Telephony.backgroundInstance.sendSms(to: phoneNum!, message: idle!); print("去电未接"); } // Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con!); diff --git a/lib/ui/home/calling_idle_list.dart b/lib/ui/home/calling_idle_list.dart index 1c9e635..8a4ccfa 100644 --- a/lib/ui/home/calling_idle_list.dart +++ b/lib/ui/home/calling_idle_list.dart @@ -98,7 +98,6 @@ class _CallingIdleListState extends State // footer: MaterialFooter(), onRefresh: () async { await userProvider.updateUserInfo(); - userProvider.updateRefSms(); await updateList(); setState(() {}); }, @@ -168,11 +167,24 @@ class _CallingIdleListState extends State onTap: () async { if (content != "自定义短信内容") { BaseModel res = await apiClient.request(API.content.checked, - data: {'id': smsIdList[index], 'status': 2}); + data: {'id': smsIdList[index], 'status': widget.status}); if (res.code == 0) { setState(() {}); - userProvider.updateUserInfo(); - userProvider.updateRefSms(); + await userProvider.updateUserInfo(); + switch (widget.status) { + case 1: + await userProvider.updateConSms(); + break; + case 2: + await userProvider.updateRefSms(); + break; + case 3: + await userProvider.updateCallSms(); + break; + case 4: + await userProvider.updateIdleSms(); + break; + } widget.refreshController.callRefresh(); } else { CloudToast.show(res.msg);