From 2fa9d4339d6fc98ae471943a80c6435bc31335d8 Mon Sep 17 00:00:00 2001 From: wylyl22 <2373073266@qq.com> Date: Wed, 14 Sep 2022 12:01:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/exclude/exclude_contacts_page.dart | 70 +++++++++++++---------- lib/ui/exclude/exclude_single_page.dart | 6 +- lib/ui/home/call.dart | 7 ++- lib/ui/home/set/phone_set_page.dart | 67 +++++++++++++++++++++- 4 files changed, 112 insertions(+), 38 deletions(-) diff --git a/lib/ui/exclude/exclude_contacts_page.dart b/lib/ui/exclude/exclude_contacts_page.dart index 330ed64..888f436 100644 --- a/lib/ui/exclude/exclude_contacts_page.dart +++ b/lib/ui/exclude/exclude_contacts_page.dart @@ -4,6 +4,7 @@ import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import '../../constants/api.dart'; import '../../model/exclude_phone_model.dart'; @@ -20,6 +21,7 @@ class ExcludeContactsPage extends StatefulWidget { class _ExcludeContactsPageState extends State { List? contacts; List numbers = []; + List numbers1 = []; List status = []; var flag = true; @@ -30,12 +32,15 @@ class _ExcludeContactsPageState extends State { } Future _viewLoading() async { + // final SharedPreferences prefs = await SharedPreferences.getInstance(); contacts = await FlutterContacts.getContacts(); for (var element in contacts!) { final full = await FlutterContacts.getContact(element.id); numbers.add(full!.phones.first.number); status.add(false); } + // await prefs.setStringList("addressList", numbers); + print(contacts?.length); setState(() {}); } @@ -48,38 +53,41 @@ class _ExcludeContactsPageState extends State { flag = false; return Container(); } else { + return ListView.builder( - itemCount: contacts!.length, - itemBuilder: (context, i) => ListTile( - title: Text( - contacts![i].displayName, - style: TextStyle( - fontSize: 32.sp, - fontWeight: FontWeight.w600, - ), - ), - subtitle: Text( - numbers[i], - style: TextStyle( - fontSize: 28.sp, - fontWeight: FontWeight.w300, - ), - ), - trailing: Checkbox( - value: status[i], - // 改变后的事件 - onChanged: (value) { - setState(() { - status[i] = !status[i]; - }); - }, - // 选中后的颜色 - activeColor: Colors.blue, - // 选中后对号的颜色 - checkColor: Colors.white, - ), - ).paddingOnly(left: 20.w), - ); + itemCount: contacts!.length, + itemBuilder: (context, i) { + + return ListTile( + title: Text( + contacts![i].displayName, + style: TextStyle( + fontSize: 32.sp, + fontWeight: FontWeight.w600, + ), + ), + subtitle: Text( + numbers[i], + style: TextStyle( + fontSize: 28.sp, + fontWeight: FontWeight.w300, + ), + ), + trailing: Checkbox( + value: status[i], + // 改变后的事件 + onChanged: (value) { + setState(() { + status[i] = !status[i]; + }); + }, + // 选中后的颜色 + activeColor: Colors.blue, + // 选中后对号的颜色 + checkColor: Colors.white, + ), + ).paddingOnly(left: 20.w); + }); } }, ); diff --git a/lib/ui/exclude/exclude_single_page.dart b/lib/ui/exclude/exclude_single_page.dart index 129dfae..f0cfa5d 100644 --- a/lib/ui/exclude/exclude_single_page.dart +++ b/lib/ui/exclude/exclude_single_page.dart @@ -35,7 +35,11 @@ class _ExcludeSinglePageState extends State { wid: 110, title: '添加单个或批量号码', bottom: "添加", - onTap: () {}, + onTap: () { + + + + }, isOpacity: _phoneController.text.isNotEmpty && _nameController.text.isNotEmpty, child: Container( diff --git a/lib/ui/home/call.dart b/lib/ui/home/call.dart index 0de9ebb..6d3b72c 100644 --- a/lib/ui/home/call.dart +++ b/lib/ui/home/call.dart @@ -54,11 +54,10 @@ void onStart(ServiceInstance service) async { // }); // Telephony.backgroundInstance.sendSms(to: "13486828191", message: "123123"); Timer.periodic(const Duration(seconds: 1), (timer) async { - final SharedPreferences prefs = await SharedPreferences.getInstance(); CallState state = await Telephony.instance.callState; callState = state.name; - print("$callState$flag"); + // print("$callState$flag"); // print(entry.first.duration); String? ref = prefs.getString('refSms'); String? con = prefs.getString('conSms'); @@ -66,7 +65,9 @@ void onStart(ServiceInstance service) async { String? idle = prefs.getString('idleSms'); bool? callSw = prefs.getBool('callSwitch'); bool? idleSw = prefs.getBool('idleSwitch'); - + int? numberSet=prefs.getInt("numIndex"); + List? numberList=prefs.getStringList("addressList"); + print("号码设置$numberSet 通讯列表$numberList"); if (callState == "IDLE") { if (flag != 0) { final Iterable entry = await CallLog.query(); diff --git a/lib/ui/home/set/phone_set_page.dart b/lib/ui/home/set/phone_set_page.dart index dbe7eda..011fbfd 100644 --- a/lib/ui/home/set/phone_set_page.dart +++ b/lib/ui/home/set/phone_set_page.dart @@ -1,9 +1,13 @@ +import 'package:call_log/call_log.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_background_service/flutter_background_service.dart'; import 'package:project_telephony/ui/home/set/specify_phone_page.dart'; import 'package:project_telephony/utils/headers.dart'; - +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:flutter_contacts/flutter_contacts.dart'; import '../../../base/base_style.dart'; +import '../../../model/phone_num_model.dart'; import '../../widget/plone_back_button.dart'; // class setItem{ @@ -20,6 +24,12 @@ class PhoneSetPage extends StatefulWidget { class _PhoneSetPageState extends State { int select = 0; + List? contact; + List numbers = []; + List? numList=[]; + List numList2=[]; + List? numList3=[]; + List setList = [ { "icon": Assets.icons.rylyphone.path, @@ -40,7 +50,11 @@ class _PhoneSetPageState extends State { // "select": false, }, ]; - +@override + void initState() { + _viewLoading(); + super.initState(); + } @override Widget build(BuildContext context) { return Scaffold( @@ -111,11 +125,58 @@ class _PhoneSetPageState extends State { ), ); } + Future _viewLoading() async { + final SharedPreferences prefs = await SharedPreferences.getInstance(); + contact = await FlutterContacts.getContacts(); + for (var element in contact!) { + final full = await FlutterContacts.getContact(element.id); + numbers.add(full!.phones.first.number.replaceAll(" ","")); + // status.add(false); + } + await prefs.setStringList("addressList", numbers); + // phoneNum.clear(); + // final Iterable entries = await CallLog.query(); + // numList= prefs.getStringList('addressList'); + // count=numList?.length; + // for (CallLogEntry entrie in entries) { + // if (!numList2.contains(numList)) { + // numList2.add(entrie.number!); + // } + // } + // for(int i=0;i Date: Wed, 14 Sep 2022 15:53:34 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=8F=B7=E7=A0=81=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/home/call.dart | 160 +++++++++++++---- .../set/phone_num_list/call_records_list.dart | 3 +- lib/ui/home/set/phone_set_page.dart | 163 +++++++++++------- lib/ui/user/members_page.dart | 2 +- lib/utils/pay_util.dart | 4 +- 5 files changed, 222 insertions(+), 110 deletions(-) diff --git a/lib/ui/home/call.dart b/lib/ui/home/call.dart index 6d3b72c..b72dc5d 100644 --- a/lib/ui/home/call.dart +++ b/lib/ui/home/call.dart @@ -47,12 +47,6 @@ void onStart(ServiceInstance service) async { service.on('stopService').listen((event) { service.stopSelf(); }); - // setForegroundNotificationInfo(title: "你好", content: "再见"); - // AndroidServiceInstance. - // service.setNotificationInfo("").listen((event){ - // - // }); - // Telephony.backgroundInstance.sendSms(to: "13486828191", message: "123123"); Timer.periodic(const Duration(seconds: 1), (timer) async { final SharedPreferences prefs = await SharedPreferences.getInstance(); CallState state = await Telephony.instance.callState; @@ -65,54 +59,144 @@ void onStart(ServiceInstance service) async { String? idle = prefs.getString('idleSms'); bool? callSw = prefs.getBool('callSwitch'); bool? idleSw = prefs.getBool('idleSwitch'); - int? numberSet=prefs.getInt("numIndex"); - List? numberList=prefs.getStringList("addressList"); - print("号码设置$numberSet 通讯列表$numberList"); + int? numberSet = prefs.getInt("numIndex"); + List? numberList = prefs.getStringList("addressList"); + List? noNumberList = prefs.getStringList("specified"); + print("号码设置$numberSet 通讯列表$numberList 指定不发送$noNumberList"); if (callState == "IDLE") { if (flag != 0) { final Iterable entry = await CallLog.query(); phoneNum = entry.first.number; callRecords = entry.first.duration; print(phoneNum); - if (flag > 0) { - print("来电拒接/未接"); - print("${phoneNum!}:${ref!}"); - Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref); - print("发送成功"); - } else if(flag==-1){ - print("来电接听"); - print("${phoneNum!}:${con!}"); - Telephony.backgroundInstance.sendSms(to: phoneNum!, message: con); - } - else { - if(entry.first.duration!>0){ - if(callSw!){ - print(callSw); - print("${phoneNum!}:${call!}"); - Telephony.backgroundInstance.sendSms(to: phoneNum!, message: call); + switch (numberSet) { + case 0: + if (!(noNumberList?.contains(phoneNum))!) { + if (flag > 0) { + print("来电拒接/未接"); + print("${phoneNum!}:${ref!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: ref); + print("发送成功"); + } else if (flag == -1) { + print("来电接听"); + print("${phoneNum!}:${con!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: con); + } else { + if (entry.first.duration! > 0) { + if (callSw!) { + print(callSw); + print("${phoneNum!}:${call!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: call); + } + print("去电接听"); + } else { + if (idleSw!) { + print(idleSw); + print("${phoneNum!}:${idle!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: idle); + } + print("去电未接"); + } + print("发送成功"); + } + flag = 0; + }else{ + print("123412434124132312232341241242321312312323123323"); + } + break; + case 1: + if ((numberList?.contains(phoneNum))! || + !(noNumberList?.contains(phoneNum))!) { + if (flag > 0) { + print("来电拒接/未接"); + print("${phoneNum!}:${ref!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: ref); + print("发送成功"); + } else if (flag == -1) { + print("来电接听"); + print("${phoneNum!}:${con!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: con); + } else { + if (entry.first.duration! > 0) { + if (callSw!) { + print(callSw); + print("${phoneNum!}:${call!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: call); + } + print("去电接听"); + } else { + if (idleSw!) { + print(idleSw); + print("${phoneNum!}:${idle!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: idle); + } + print("去电未接"); + } + print("发送成功"); + } + flag = 0; + }else{ + print("123412434124132312232341241242321312312323123323"); } - print("去电接听"); - }else{ - if(idleSw!){ - print(idleSw); - print("${phoneNum!}:${idle!}"); - Telephony.backgroundInstance.sendSms(to: phoneNum!, message: idle); + break; + case 2: + if (!(numberList?.contains(phoneNum))! || + !(noNumberList?.contains(phoneNum))!) { + if (flag > 0) { + print("来电拒接/未接"); + print("${phoneNum!}:${ref!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: ref); + print("发送成功"); + } else if (flag == -1) { + print("来电接听"); + print("${phoneNum!}:${con!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: con); + } else { + if (entry.first.duration! > 0) { + if (callSw!) { + print(callSw); + print("${phoneNum!}:${call!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: call); + } + print("去电接听"); + } else { + if (idleSw!) { + print(idleSw); + print("${phoneNum!}:${idle!}"); + Telephony.backgroundInstance + .sendSms(to: phoneNum!, message: idle); + } + print("去电未接"); + } + print("发送成功"); + } + flag = 0; + }else{ + print("123412434124132312232341241242321312312323123323"); } - print("去电未接"); - } - print("发送成功"); + break; } - flag = 0; } } else if (callState == "RINGING") { //响铃 - flag=1; + flag = 1; print('通话'); } else if (callState == "OFFHOOK") { //通话 if (flag > 0) flag *= -1; - if(flag==0)flag=-2; + if (flag == 0) flag = -2; print('不通话'); } }); -} \ No newline at end of file +} diff --git a/lib/ui/home/set/phone_num_list/call_records_list.dart b/lib/ui/home/set/phone_num_list/call_records_list.dart index 7906537..1d507e5 100644 --- a/lib/ui/home/set/phone_num_list/call_records_list.dart +++ b/lib/ui/home/set/phone_num_list/call_records_list.dart @@ -97,7 +97,8 @@ class _CallRecordsListState extends State { } else { print(phoneNum3); var res = await ExcludeFunc.getContactsList(phoneNum3); - print(res); + if(res) Get.back(); + } // _easyRefreshController.callRefresh(); // phoneNum3.clear(); diff --git a/lib/ui/home/set/phone_set_page.dart b/lib/ui/home/set/phone_set_page.dart index 011fbfd..a7fce47 100644 --- a/lib/ui/home/set/phone_set_page.dart +++ b/lib/ui/home/set/phone_set_page.dart @@ -1,13 +1,13 @@ -import 'package:call_log/call_log.dart'; import 'package:flutter/material.dart'; import 'package:flutter_background_service/flutter_background_service.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:project_telephony/ui/home/set/func/exclude_contacts_func.dart'; import 'package:project_telephony/ui/home/set/specify_phone_page.dart'; import 'package:project_telephony/utils/headers.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:flutter_contacts/flutter_contacts.dart'; import '../../../base/base_style.dart'; -import '../../../model/phone_num_model.dart'; import '../../widget/plone_back_button.dart'; // class setItem{ @@ -15,7 +15,6 @@ import '../../widget/plone_back_button.dart'; // } class PhoneSetPage extends StatefulWidget { - const PhoneSetPage({Key? key}) : super(key: key); @override @@ -26,10 +25,8 @@ class _PhoneSetPageState extends State { int select = 0; List? contact; List numbers = []; - List? numList=[]; - List numList2=[]; - List? numList3=[]; - + List? numList = []; + final EasyRefreshController _refreshController = EasyRefreshController(); List setList = [ { "icon": Assets.icons.rylyphone.path, @@ -50,67 +47,90 @@ class _PhoneSetPageState extends State { // "select": false, }, ]; -@override + + @override void initState() { - _viewLoading(); super.initState(); } + @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - elevation: 0, - title: Text( - '发送号码设置', - style: TextStyle( - fontSize: BaseStyle.fontSize34, - color: BaseStyle.color333333, - fontWeight: FontWeight.bold), - ), - titleSpacing: 162.w, - leading: const CloudBackButton(isSpecial: true), - backgroundColor: kForeGroundColor), - backgroundColor: kForeGroundColor, - body: Column( - children: [ - _getList(), - 24.hb, - GestureDetector( - onTap: () { - Get.to(()=>const SpecifyPhonePage()); - }, - child: Container( - padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 30.w), - height: 144.w, - child: ListTile( - leading: SizedBox( - width: 72.w, - height: 72.w, - child: Image.asset( - Assets.icons.zdphone.path, - fit: BoxFit.fill, - ), - ), - title: Text( - "指定号码不发送", - style: - TextStyle(fontSize: 32.sp, fontWeight: FontWeight.bold), - ), - subtitle: Text( - "通过添加指定号码来设置不发送", - style: TextStyle( - fontSize: 28.sp, color: const Color(0xFF999999)), - ), - trailing: SizedBox( - width: 48.w, - height: 48.w, - child: const Icon(Icons.arrow_forward_ios), - )), + appBar: AppBar( + elevation: 0, + title: Text( + '发送号码设置', + style: TextStyle( + fontSize: BaseStyle.fontSize34, + color: BaseStyle.color333333, + fontWeight: FontWeight.bold), ), - ) - ], - ), - ); + titleSpacing: 162.w, + leading: const CloudBackButton(isSpecial: true), + backgroundColor: kForeGroundColor), + backgroundColor: kForeGroundColor, + body: EasyRefresh( + firstRefresh: true, + controller: _refreshController, + header: MaterialHeader(), + // footer: MaterialFooter(), + onRefresh: () async { + final SharedPreferences prefs = + await SharedPreferences.getInstance(); + select = (prefs.getInt("numIndex"))!; + _viewLoading(); + setState(() {}); + }, + child: ListView( + children: [ + _getList(), + 24.hb, + GestureDetector( + onTap: () { + Get.to(() => const SpecifyPhonePage()); + }, + child: Container( + padding: + EdgeInsets.symmetric(horizontal: 32.w, vertical: 30.w), + height: 144.w, + child: ListTile( + leading: SizedBox( + width: 72.w, + height: 72.w, + child: Image.asset( + Assets.icons.zdphone.path, + fit: BoxFit.fill, + ), + ), + title: Text( + "指定号码不发送", + style: TextStyle( + fontSize: 32.sp, fontWeight: FontWeight.bold), + ), + subtitle: Text( + "通过添加指定号码来设置不发送", + style: TextStyle( + fontSize: 28.sp, color: const Color(0xFF999999)), + ), + trailing: SizedBox( + width: 48.w, + height: 48.w, + child: const Icon(Icons.arrow_forward_ios), + )), + ), + ) + ], + ), + ) + + // Column( + // children: [ + // + // + // + // ], + // ), + ); } _getList() { @@ -125,15 +145,20 @@ class _PhoneSetPageState extends State { ), ); } - Future _viewLoading() async { + Future _viewLoading() async { final SharedPreferences prefs = await SharedPreferences.getInstance(); contact = await FlutterContacts.getContacts(); for (var element in contact!) { final full = await FlutterContacts.getContact(element.id); - numbers.add(full!.phones.first.number.replaceAll(" ","")); + numbers.add(full!.phones.first.number.replaceAll(" ", "")); // status.add(false); } + var numberList = await ExcludeFunc.getContacts(); + for (int i = 0; i < numberList.length; i++) { + numList?.add(numberList[i].phone); + } + await prefs.setStringList("specified", numList!); await prefs.setStringList("addressList", numbers); // phoneNum.clear(); // final Iterable entries = await CallLog.query(); @@ -159,24 +184,28 @@ class _PhoneSetPageState extends State { // } setState(() {}); } + _getListBox(List item, int index) { final service = FlutterBackgroundService(); return GestureDetector( - onTap: () async{ + onTap: () async { final SharedPreferences prefs = await SharedPreferences.getInstance(); select = index; await prefs.setInt("numIndex", index); - if(await service.isRunning()){ + print(await service.isRunning()); + if (await service.isRunning()) { service.invoke("stopService"); Future.delayed(const Duration(seconds: 1), () async { service.startService(); }); - }else{ + } else { service.startService(); - Future.delayed(const Duration(seconds: 1), () async { + Future.delayed(const Duration(seconds: 2), () async { service.invoke("stopService"); }); } + print( prefs.getStringList("specified")); + _refreshController.callRefresh(); // print(_selectIndex); setState(() {}); }, diff --git a/lib/ui/user/members_page.dart b/lib/ui/user/members_page.dart index 5a308f1..58ec958 100644 --- a/lib/ui/user/members_page.dart +++ b/lib/ui/user/members_page.dart @@ -78,6 +78,7 @@ class _MembersPageState extends State { } @override Widget build(BuildContext context) { + return Scaffold( body: EasyRefresh( firstRefresh: true, @@ -86,7 +87,6 @@ class _MembersPageState extends State { controller: _easyRefreshController, onRefresh: () async { await UserTool.userProvider.updateUserInfo(); - setState(() {}); }, child: Stack( diff --git a/lib/utils/pay_util.dart b/lib/utils/pay_util.dart index 193a03d..2b55077 100644 --- a/lib/utils/pay_util.dart +++ b/lib/utils/pay_util.dart @@ -151,9 +151,7 @@ class PayUtil { _wxPayStream?.cancel(); } - Future callWxPay({ - required WxPayModel payModel, - }) async { + Future callWxPay({required WxPayModel payModel, }) async { await payWithWeChat( appId: 'wx3a0b41d12afef4e2', partnerId: payModel.partnerId, From f439a5e1eefdb024593ef90e5391f64f3e78e743 Mon Sep 17 00:00:00 2001 From: wylyl22 <2373073266@qq.com> Date: Wed, 14 Sep 2022 16:50:15 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/home/set/phone_num_list/call_records_list.dart | 6 +++--- lib/ui/home/set/specify_phone_page.dart | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ui/home/set/phone_num_list/call_records_list.dart b/lib/ui/home/set/phone_num_list/call_records_list.dart index 1d507e5..9f54c2b 100644 --- a/lib/ui/home/set/phone_num_list/call_records_list.dart +++ b/lib/ui/home/set/phone_num_list/call_records_list.dart @@ -95,9 +95,9 @@ class _CallRecordsListState extends State { if (phoneNum3.isEmpty) { CloudToast.show('请选择手机号'); } else { - print(phoneNum3); - var res = await ExcludeFunc.getContactsList(phoneNum3); - if(res) Get.back(); + // print(phoneNum3); + await ExcludeFunc.getContactsList(phoneNum3); + Navigator.pop(context,true); } // _easyRefreshController.callRefresh(); diff --git a/lib/ui/home/set/specify_phone_page.dart b/lib/ui/home/set/specify_phone_page.dart index 819cd45..17d6df9 100644 --- a/lib/ui/home/set/specify_phone_page.dart +++ b/lib/ui/home/set/specify_phone_page.dart @@ -65,7 +65,7 @@ class _SpecifyPhonePageState extends State { MaterialPageRoute( builder: (_) => const CallRecordsList()), ) - .then((val) => _getNullList()); + .then((val) =>_refreshController.callRefresh()); // Get.to(() => const CallRecordsList()); }), @@ -89,9 +89,11 @@ class _SpecifyPhonePageState extends State { } else { Get.to(() => (const ExcludeContactsPage())); } + }), _getAddPhone("添加单个或批量号码", "通过输入号码段添加批量号码", () { Get.to(() => (const ExcludeSinglePage())); + }), ], )), @@ -112,6 +114,7 @@ class _SpecifyPhonePageState extends State { ); }, context: context); + }, child: EasyRefresh( firstRefresh: true,