From fd6191cf617e3d51b60da6318cf5e0a61aeda6f3 Mon Sep 17 00:00:00 2001 From: wylyl22 <2373073266@qq.com> Date: Thu, 15 Sep 2022 11:45:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=90=8E=E5=8F=B0=E5=88=B7?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/providers/user_provider.dart | 31 +++++ lib/ui/exclude/exclude_contacts_page.dart | 1 + lib/ui/exclude/exclude_single_page.dart | 39 +++--- lib/ui/home/call.dart | 4 +- lib/ui/home/home_page.dart | 24 ++-- .../set/phone_num_list/call_records_list.dart | 6 +- lib/ui/home/set/phone_set_page.dart | 126 ++++++++++-------- lib/ui/home/set/specify_phone_page.dart | 37 +++-- lib/ui/login/login_page.dart | 5 +- lib/ui/widget/plone_back_button.dart | 1 + 10 files changed, 159 insertions(+), 115 deletions(-) diff --git a/lib/providers/user_provider.dart b/lib/providers/user_provider.dart index ecc8482..c49111c 100644 --- a/lib/providers/user_provider.dart +++ b/lib/providers/user_provider.dart @@ -1,6 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_background_service/flutter_background_service.dart'; +import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:project_telephony/utils/user_tool.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -9,6 +10,7 @@ import '../model/exclude_phone_model.dart'; import '../model/login_info_model.dart'; import '../model/network/api_client.dart'; import '../model/user_info_model.dart'; +import '../ui/home/set/func/exclude_contacts_func.dart'; import '../utils/hive_store.dart'; import '../utils/toast/cloud_toast.dart'; @@ -55,13 +57,17 @@ class UserProvider extends ChangeNotifier { updateRefSms(); updateCallSms(); updateIdleSms(); + viewLoading(); getExclude(); } Future logout() async { + final service = FlutterBackgroundService(); apiClient.clearToken(); _isLogin = false; await HiveStore.appBox?.delete('token'); + service.invoke("stopService"); + } Future updateUserInfo() async { @@ -185,4 +191,29 @@ class UserProvider extends ChangeNotifier { } notifyListeners(); } + Future viewLoading() async { + List? numList=[]; + List? numbers=[]; + final service = FlutterBackgroundService(); + final SharedPreferences prefs = await SharedPreferences.getInstance(); + var 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); + } + 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); + service.invoke("stopService"); + if (prefs.getBool('kg')!) { + Future.delayed(const Duration(seconds: 1), () async { + service.startService(); + }); + } + notifyListeners(); + } } diff --git a/lib/ui/exclude/exclude_contacts_page.dart b/lib/ui/exclude/exclude_contacts_page.dart index aae3f23..6c62aa1 100644 --- a/lib/ui/exclude/exclude_contacts_page.dart +++ b/lib/ui/exclude/exclude_contacts_page.dart @@ -114,6 +114,7 @@ class _ExcludeContactsPageState extends State { if (res.code == 0) { BotToast.showText(text: res.msg); Get.back(); + Get.back(); } } else { BotToast.showText(text: "还未选中手机号"); diff --git a/lib/ui/exclude/exclude_single_page.dart b/lib/ui/exclude/exclude_single_page.dart index 20bbcd2..c0b1070 100644 --- a/lib/ui/exclude/exclude_single_page.dart +++ b/lib/ui/exclude/exclude_single_page.dart @@ -59,6 +59,7 @@ class _ExcludeSinglePageState extends State { BotToast.showText(text: res.msg); if (res.code == 0) { Get.back(); + Get.back(); } } }, @@ -74,25 +75,25 @@ class _ExcludeSinglePageState extends State { 15.heightBox, addNumber("名称", "请输入名称", _nameController), 30.heightBox, - RichText( - text: const TextSpan( - children: [ - TextSpan( - text: "使用说明:\n", - style: TextStyle( - fontWeight: FontWeight.w600, - color: Colors.black38, - ), - ), - TextSpan( - text: "如输入000*,可屏蔽所有000开头的号码", - style: TextStyle( - color: Colors.black38, - ), - ), - ], - ), - ), + // RichText( + // text: const TextSpan( + // children: [ + // TextSpan( + // text: "使用说明:\n", + // style: TextStyle( + // fontWeight: FontWeight.w600, + // color: Colors.black38, + // ), + // ), + // TextSpan( + // text: "如输入000*,可屏蔽所有000开头的号码", + // style: TextStyle( + // color: Colors.black38, + // ), + // ), + // ], + // ), + // ), ], ), ), diff --git a/lib/ui/home/call.dart b/lib/ui/home/call.dart index b72dc5d..58c2577 100644 --- a/lib/ui/home/call.dart +++ b/lib/ui/home/call.dart @@ -109,7 +109,7 @@ void onStart(ServiceInstance service) async { } break; case 1: - if ((numberList?.contains(phoneNum))! || + if ((numberList?.contains(phoneNum))! && !(noNumberList?.contains(phoneNum))!) { if (flag > 0) { print("来电拒接/未接"); @@ -148,7 +148,7 @@ void onStart(ServiceInstance service) async { } break; case 2: - if (!(numberList?.contains(phoneNum))! || + if (!(numberList?.contains(phoneNum))! && !(noNumberList?.contains(phoneNum))!) { if (flag > 0) { print("来电拒接/未接"); diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart index 681195e..d10844b 100644 --- a/lib/ui/home/home_page.dart +++ b/lib/ui/home/home_page.dart @@ -27,6 +27,7 @@ class HomePage extends StatefulWidget { bool sms = false; bool plone = false; +bool addressBook=false; bool kg = false; final service = FlutterBackgroundService(); @@ -53,6 +54,7 @@ class _HomePageState extends State with WidgetsBindingObserver { sms = await Permission.sms.request().isGranted; plone = await Permission.phone.request().isGranted; callLog = await Permission.callLog.request().isGranted; + addressBook= await Permission.contacts.request().isGranted; kg = await service.isRunning(); setState(() {}); } @@ -121,18 +123,19 @@ class _HomePageState extends State with WidgetsBindingObserver { // } _warning() { return Offstage( - offstage: (sms && plone && callLog && kg), + + offstage: (sms && plone && callLog && addressBook && kg), child: GestureDetector( onTap: () { - if (!(sms && plone && callLog && kg)) { - if (!(sms && plone && callLog)) { + if (!(sms && plone && callLog && addressBook && kg)) { + if (!(sms && plone && callLog && addressBook)) { Get.to(() => const PrivacyRightsPage(name: "权限说明")); // Get.to(()=>const TabNavigator(index: 1,)); } else { BotToast.showText(text: '功能开关未开启'); } } - // print(); + // openAppSettings(); }, child: Container( @@ -153,14 +156,14 @@ class _HomePageState extends State with WidgetsBindingObserver { ), 16.wb, Text( - !(sms && plone && callLog) + !(sms && plone && callLog && addressBook) ? "必须权限没有授予,本APP无法正常使用" : "功能开关未开启,请到我的页面开启", style: TextStyle(color: const Color(0xFFFF3F3F), fontSize: 24.sp), ), - !(sms && plone && callLog) ? 32.wb : 0.wb, - !(sms && plone && callLog) + !(sms && plone && callLog && addressBook) ? 32.wb : 0.wb, + !(sms && plone && callLog && addressBook) ? Image( image: AssetImage(Assets.icons.right.path), width: 28.w, @@ -209,7 +212,12 @@ class _HomePageState extends State with WidgetsBindingObserver { _getSet() { return GestureDetector( onTap: (){ - Get.to(()=>const PhoneSetPage()); + Navigator.of(context) + .push( + MaterialPageRoute(builder: (_) => const PhoneSetPage()), + ) + .then((val) => _listenForPermissionStatus()); + }, child: Container( padding: EdgeInsets.symmetric(horizontal: 42.w, vertical: 20.w), 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 9f54c2b..089c4b5 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 @@ -70,7 +70,6 @@ class _CallRecordsListState extends State { state: phoneNum[i].state, )); } - // for (CallLogEntry entrie in entries) { // if (!numList.contains(entrie.number)) { // numList.add(entrie.number!); @@ -92,12 +91,15 @@ class _CallRecordsListState extends State { isBorder: true, isOpacity: phoneNum3.isNotEmpty, onTap: () async { + if (phoneNum3.isEmpty) { CloudToast.show('请选择手机号'); } else { // print(phoneNum3); await ExcludeFunc.getContactsList(phoneNum3); - Navigator.pop(context,true); + // Navigator.pop(context,true); + Get.back(); + Get.back(); } // _easyRefreshController.callRefresh(); diff --git a/lib/ui/home/set/phone_set_page.dart b/lib/ui/home/set/phone_set_page.dart index a7fce47..8ecf3c0 100644 --- a/lib/ui/home/set/phone_set_page.dart +++ b/lib/ui/home/set/phone_set_page.dart @@ -1,9 +1,11 @@ +import 'package:bot_toast/bot_toast.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:project_telephony/utils/user_tool.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:flutter_contacts/flutter_contacts.dart'; import '../../../base/base_style.dart'; @@ -26,6 +28,7 @@ class _PhoneSetPageState extends State { List? contact; List numbers = []; List? numList = []; + DateTime? _lastTap; final EasyRefreshController _refreshController = EasyRefreshController(); List setList = [ { @@ -75,10 +78,9 @@ class _PhoneSetPageState extends State { header: MaterialHeader(), // footer: MaterialFooter(), onRefresh: () async { - final SharedPreferences prefs = - await SharedPreferences.getInstance(); + final SharedPreferences prefs = await SharedPreferences.getInstance(); select = (prefs.getInt("numIndex"))!; - _viewLoading(); + // _viewLoading(); setState(() {}); }, child: ListView( @@ -146,66 +148,61 @@ 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); - } - 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(); - // 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 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 { width: 40.w, height: 40.w, child: Radio( - onChanged: (int? value) { + onChanged: (int? value) async{ + final SharedPreferences prefs = await SharedPreferences.getInstance(); select = index; + await prefs.setInt("numIndex", index); + service.invoke("stopService"); + if (prefs.getBool('kg')!) { + Future.delayed(const Duration(seconds: 1), () async { + service.startService(); + }); + } + UserTool.userProvider.viewLoading(); + _refreshController.callRefresh(); + // select = index; // print(_selectIndex); setState(() {}); }, diff --git a/lib/ui/home/set/specify_phone_page.dart b/lib/ui/home/set/specify_phone_page.dart index 17d6df9..4d4ea83 100644 --- a/lib/ui/home/set/specify_phone_page.dart +++ b/lib/ui/home/set/specify_phone_page.dart @@ -10,6 +10,7 @@ import 'package:project_telephony/ui/home/set/phone_num_list/call_records_list.d import 'package:project_telephony/utils/headers.dart'; import 'package:project_telephony/ui/widget/plone_bottom.dart'; import 'package:project_telephony/utils/toast/cloud_toast.dart'; +import 'package:project_telephony/utils/user_tool.dart'; import '../../../base/base_style.dart'; import '../../../model/exclude_phone_model.dart'; @@ -69,31 +70,22 @@ class _SpecifyPhonePageState extends State { // Get.to(() => const CallRecordsList()); }), - _getAddPhone("通迅录添加", "通过本机通讯录添加号码", () async { - if (await Permission.contacts.isDenied) { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - content: const Text('获取通讯录权限还未开启'), - actions: [ - ElevatedButton( - onPressed: () { - openAppSettings(); - }, - child: const Text("前往开启"), - ), - ], - ); - }); - } else { - Get.to(() => (const ExcludeContactsPage())); - } + _getAddPhone("通迅录添加", "通过本机通讯录添加号码", () { + Navigator.of(context) + .push( + MaterialPageRoute( + builder: (_) => const ExcludeContactsPage()), + ) + .then((val) =>_refreshController.callRefresh()); }), _getAddPhone("添加单个或批量号码", "通过输入号码段添加批量号码", () { - Get.to(() => (const ExcludeSinglePage())); - + Navigator.of(context) + .push( + MaterialPageRoute( + builder: (_) => const ExcludeSinglePage()), + ) + .then((val) =>_refreshController.callRefresh()); }), ], )), @@ -123,6 +115,7 @@ class _SpecifyPhonePageState extends State { // footer: MaterialFooter(), onRefresh: () async { findList = await ExcludeFunc.getContacts(); + UserTool.userProvider.viewLoading(); // await userProvider.updateUserInfo(); setState(() {}); diff --git a/lib/ui/login/login_page.dart b/lib/ui/login/login_page.dart index 6341349..d3530e5 100644 --- a/lib/ui/login/login_page.dart +++ b/lib/ui/login/login_page.dart @@ -11,7 +11,7 @@ import 'package:project_telephony/utils/headers.dart'; import 'package:provider/provider.dart'; import '../../base/base_style.dart'; import '../../constants/api.dart'; -import '../../constants/environment/environment.dart'; + import '../../model/network/api_client.dart'; import '../../providers/user_provider.dart'; import '../../utils/toast/cloud_toast.dart'; @@ -132,8 +132,7 @@ class _LoginPageState extends State { } else if (!_chooseAgreement) { BotToast.showText(text: "请同意并勾选隐私政策"); } else { - if (_lastTap != null && - DateTime.now().difference(_lastTap!).inSeconds < 2) { + if (_lastTap != null && DateTime.now().difference(_lastTap!).inSeconds < 2) { // BotToast.showText(text: "过快"); return; } diff --git a/lib/ui/widget/plone_back_button.dart b/lib/ui/widget/plone_back_button.dart index 9cbb82f..fe0e40f 100644 --- a/lib/ui/widget/plone_back_button.dart +++ b/lib/ui/widget/plone_back_button.dart @@ -21,6 +21,7 @@ class CloudBackButton extends StatelessWidget { onPressed: () { print("返回传值"); Navigator.pop(context,true); + Get.back(); }, icon: Icon(