Compare commits

...

2 Commits

Author SHA1 Message Date
王亚玲 cca1967b9d Merge branch 'master' of https://git.oa00.com/austin_dai/project_telephony
2 years ago
王亚玲 fd6191cf61 页面后台刷新
2 years ago

@ -1,6 +1,7 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_background_service/flutter_background_service.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:project_telephony/utils/user_tool.dart';
import 'package:shared_preferences/shared_preferences.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/login_info_model.dart';
import '../model/network/api_client.dart'; import '../model/network/api_client.dart';
import '../model/user_info_model.dart'; import '../model/user_info_model.dart';
import '../ui/home/set/func/exclude_contacts_func.dart';
import '../utils/hive_store.dart'; import '../utils/hive_store.dart';
import '../utils/toast/cloud_toast.dart'; import '../utils/toast/cloud_toast.dart';
@ -55,13 +57,17 @@ class UserProvider extends ChangeNotifier {
updateRefSms(); updateRefSms();
updateCallSms(); updateCallSms();
updateIdleSms(); updateIdleSms();
viewLoading();
getExclude(); getExclude();
} }
Future logout() async { Future logout() async {
final service = FlutterBackgroundService();
apiClient.clearToken(); apiClient.clearToken();
_isLogin = false; _isLogin = false;
await HiveStore.appBox?.delete('token'); await HiveStore.appBox?.delete('token');
service.invoke("stopService");
} }
Future updateUserInfo() async { Future updateUserInfo() async {
@ -185,4 +191,29 @@ class UserProvider extends ChangeNotifier {
} }
notifyListeners(); notifyListeners();
} }
Future viewLoading() async {
List<String>? numList=[];
List<String>? 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();
}
} }

@ -114,6 +114,7 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
if (res.code == 0) { if (res.code == 0) {
BotToast.showText(text: res.msg); BotToast.showText(text: res.msg);
Get.back(); Get.back();
Get.back();
} }
} else { } else {
BotToast.showText(text: "还未选中手机号"); BotToast.showText(text: "还未选中手机号");

@ -59,6 +59,7 @@ class _ExcludeSinglePageState extends State<ExcludeSinglePage> {
BotToast.showText(text: res.msg); BotToast.showText(text: res.msg);
if (res.code == 0) { if (res.code == 0) {
Get.back(); Get.back();
Get.back();
} }
} }
}, },
@ -74,25 +75,25 @@ class _ExcludeSinglePageState extends State<ExcludeSinglePage> {
15.heightBox, 15.heightBox,
addNumber("名称", "请输入名称", _nameController), addNumber("名称", "请输入名称", _nameController),
30.heightBox, 30.heightBox,
RichText( // RichText(
text: const TextSpan( // text: const TextSpan(
children: [ // children: [
TextSpan( // TextSpan(
text: "使用说明:\n", // text: "使用说明:\n",
style: TextStyle( // style: TextStyle(
fontWeight: FontWeight.w600, // fontWeight: FontWeight.w600,
color: Colors.black38, // color: Colors.black38,
), // ),
), // ),
TextSpan( // TextSpan(
text: "如输入000*可屏蔽所有000开头的号码", // text: "如输入000*可屏蔽所有000开头的号码",
style: TextStyle( // style: TextStyle(
color: Colors.black38, // color: Colors.black38,
), // ),
), // ),
], // ],
), // ),
), // ),
], ],
), ),
), ),

@ -109,7 +109,7 @@ void onStart(ServiceInstance service) async {
} }
break; break;
case 1: case 1:
if ((numberList?.contains(phoneNum))! || if ((numberList?.contains(phoneNum))! &&
!(noNumberList?.contains(phoneNum))!) { !(noNumberList?.contains(phoneNum))!) {
if (flag > 0) { if (flag > 0) {
print("来电拒接/未接"); print("来电拒接/未接");
@ -148,7 +148,7 @@ void onStart(ServiceInstance service) async {
} }
break; break;
case 2: case 2:
if (!(numberList?.contains(phoneNum))! || if (!(numberList?.contains(phoneNum))! &&
!(noNumberList?.contains(phoneNum))!) { !(noNumberList?.contains(phoneNum))!) {
if (flag > 0) { if (flag > 0) {
print("来电拒接/未接"); print("来电拒接/未接");

@ -27,6 +27,7 @@ class HomePage extends StatefulWidget {
bool sms = false; bool sms = false;
bool plone = false; bool plone = false;
bool addressBook=false;
bool kg = false; bool kg = false;
final service = FlutterBackgroundService(); final service = FlutterBackgroundService();
@ -53,6 +54,7 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
sms = await Permission.sms.request().isGranted; sms = await Permission.sms.request().isGranted;
plone = await Permission.phone.request().isGranted; plone = await Permission.phone.request().isGranted;
callLog = await Permission.callLog.request().isGranted; callLog = await Permission.callLog.request().isGranted;
addressBook= await Permission.contacts.request().isGranted;
kg = await service.isRunning(); kg = await service.isRunning();
setState(() {}); setState(() {});
} }
@ -121,18 +123,19 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
// } // }
_warning() { _warning() {
return Offstage( return Offstage(
offstage: (sms && plone && callLog && kg),
offstage: (sms && plone && callLog && addressBook && kg),
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
if (!(sms && plone && callLog && kg)) { if (!(sms && plone && callLog && addressBook && kg)) {
if (!(sms && plone && callLog)) { if (!(sms && plone && callLog && addressBook)) {
Get.to(() => const PrivacyRightsPage(name: "权限说明")); Get.to(() => const PrivacyRightsPage(name: "权限说明"));
// Get.to(()=>const TabNavigator(index: 1,)); // Get.to(()=>const TabNavigator(index: 1,));
} else { } else {
BotToast.showText(text: '功能开关未开启'); BotToast.showText(text: '功能开关未开启');
} }
} }
// print();
// openAppSettings(); // openAppSettings();
}, },
child: Container( child: Container(
@ -153,14 +156,14 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
), ),
16.wb, 16.wb,
Text( Text(
!(sms && plone && callLog) !(sms && plone && callLog && addressBook)
? "必须权限没有授予本APP无法正常使用" ? "必须权限没有授予本APP无法正常使用"
: "功能开关未开启,请到我的页面开启", : "功能开关未开启,请到我的页面开启",
style: style:
TextStyle(color: const Color(0xFFFF3F3F), fontSize: 24.sp), TextStyle(color: const Color(0xFFFF3F3F), fontSize: 24.sp),
), ),
!(sms && plone && callLog) ? 32.wb : 0.wb, !(sms && plone && callLog && addressBook) ? 32.wb : 0.wb,
!(sms && plone && callLog) !(sms && plone && callLog && addressBook)
? Image( ? Image(
image: AssetImage(Assets.icons.right.path), image: AssetImage(Assets.icons.right.path),
width: 28.w, width: 28.w,
@ -209,7 +212,12 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
_getSet() { _getSet() {
return GestureDetector( return GestureDetector(
onTap: (){ onTap: (){
Get.to(()=>const PhoneSetPage()); Navigator.of(context)
.push(
MaterialPageRoute(builder: (_) => const PhoneSetPage()),
)
.then((val) => _listenForPermissionStatus());
}, },
child: Container( child: Container(
padding: EdgeInsets.symmetric(horizontal: 42.w, vertical: 20.w), padding: EdgeInsets.symmetric(horizontal: 42.w, vertical: 20.w),

@ -70,7 +70,6 @@ class _CallRecordsListState extends State<CallRecordsList> {
state: phoneNum[i].state, state: phoneNum[i].state,
)); ));
} }
// for (CallLogEntry entrie in entries) { // for (CallLogEntry entrie in entries) {
// if (!numList.contains(entrie.number)) { // if (!numList.contains(entrie.number)) {
// numList.add(entrie.number!); // numList.add(entrie.number!);
@ -92,12 +91,15 @@ class _CallRecordsListState extends State<CallRecordsList> {
isBorder: true, isBorder: true,
isOpacity: phoneNum3.isNotEmpty, isOpacity: phoneNum3.isNotEmpty,
onTap: () async { onTap: () async {
if (phoneNum3.isEmpty) { if (phoneNum3.isEmpty) {
CloudToast.show('请选择手机号'); CloudToast.show('请选择手机号');
} else { } else {
// print(phoneNum3); // print(phoneNum3);
await ExcludeFunc.getContactsList(phoneNum3); await ExcludeFunc.getContactsList(phoneNum3);
Navigator.pop(context,true); // Navigator.pop(context,true);
Get.back();
Get.back();
} }
// _easyRefreshController.callRefresh(); // _easyRefreshController.callRefresh();

@ -1,9 +1,11 @@
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_background_service/flutter_background_service.dart'; import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:flutter_easyrefresh/easy_refresh.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/func/exclude_contacts_func.dart';
import 'package:project_telephony/ui/home/set/specify_phone_page.dart'; import 'package:project_telephony/ui/home/set/specify_phone_page.dart';
import 'package:project_telephony/utils/headers.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:shared_preferences/shared_preferences.dart';
import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_contacts/flutter_contacts.dart';
import '../../../base/base_style.dart'; import '../../../base/base_style.dart';
@ -26,6 +28,7 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
List<Contact>? contact; List<Contact>? contact;
List<String> numbers = []; List<String> numbers = [];
List<String>? numList = []; List<String>? numList = [];
DateTime? _lastTap;
final EasyRefreshController _refreshController = EasyRefreshController(); final EasyRefreshController _refreshController = EasyRefreshController();
List setList = [ List setList = [
{ {
@ -75,10 +78,9 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
header: MaterialHeader(), header: MaterialHeader(),
// footer: MaterialFooter(), // footer: MaterialFooter(),
onRefresh: () async { onRefresh: () async {
final SharedPreferences prefs = final SharedPreferences prefs = await SharedPreferences.getInstance();
await SharedPreferences.getInstance();
select = (prefs.getInt("numIndex"))!; select = (prefs.getInt("numIndex"))!;
_viewLoading(); // _viewLoading();
setState(() {}); setState(() {});
}, },
child: ListView( child: ListView(
@ -146,66 +148,61 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
); );
} }
Future _viewLoading() async { // Future _viewLoading() async {
final SharedPreferences prefs = await SharedPreferences.getInstance(); // final SharedPreferences prefs = await SharedPreferences.getInstance();
contact = await FlutterContacts.getContacts(); // contact = await FlutterContacts.getContacts();
for (var element in contact!) { // for (var element in contact!) {
final full = await FlutterContacts.getContact(element.id); // final full = await FlutterContacts.getContact(element.id);
numbers.add(full!.phones.first.number.replaceAll(" ", "")); // numbers.add(full!.phones.first.number.replaceAll(" ", ""));
// status.add(false); // // 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<CallLogEntry> entries = await CallLog.query();
// numList= prefs.getStringList('addressList');
// count=numList?.length;
// for (CallLogEntry entrie in entries) {
// if (!numList2.contains(numList)) {
// numList2.add(entrie.number!);
// } // }
// var numberList = await ExcludeFunc.getContacts();
// for (int i = 0; i < numberList.length; i++) {
// numList?.add(numberList[i].phone);
// } // }
// for(int i=0;i<count!;i++){ // await prefs.setStringList("specified", numList!);
// numList2.remove(numList![i]); // await prefs.setStringList("addressList", numbers);
// // phoneNum.clear();
// // final Iterable<CallLogEntry> 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<count!;i++){
// // numList2.remove(numList![i]);
// // }
// // print(numList2);
// // await prefs.setStringList("noAddressList", numList2);
// // for (int i = 0; i < phoneNum.length; i++) {
// // phoneNum2.add(PhoneNumModel(
// // num: phoneNum[i].num,
// // time: phoneNum[i].time,
// // name: phoneNum[i].name,
// // state: phoneNum[i].state,
// // ));
// // }
// setState(() {});
// } // }
// print(numList2);
// await prefs.setStringList("noAddressList", numList2);
// for (int i = 0; i < phoneNum.length; i++) {
// phoneNum2.add(PhoneNumModel(
// num: phoneNum[i].num,
// time: phoneNum[i].time,
// name: phoneNum[i].name,
// state: phoneNum[i].state,
// ));
// }
setState(() {});
}
_getListBox(List item, int index) { _getListBox(List item, int index) {
final service = FlutterBackgroundService(); final service = FlutterBackgroundService();
return GestureDetector( return GestureDetector(
onTap: () async { onTap: () async {
final SharedPreferences prefs = await SharedPreferences.getInstance(); // final SharedPreferences prefs = await SharedPreferences.getInstance();
select = index; // select = index;
await prefs.setInt("numIndex", index); // await prefs.setInt("numIndex", index);
print(await service.isRunning()); // service.invoke("stopService");
if (await service.isRunning()) { // if (prefs.getBool('kg')!) {
service.invoke("stopService"); // Future.delayed(const Duration(seconds: 1), () async {
Future.delayed(const Duration(seconds: 1), () async { // service.startService();
service.startService(); // });
}); // }
} else { //
service.startService(); // UserTool.userProvider.viewLoading();
Future.delayed(const Duration(seconds: 2), () async { // _refreshController.callRefresh();
service.invoke("stopService");
});
}
print( prefs.getStringList("specified"));
_refreshController.callRefresh();
// print(_selectIndex); // print(_selectIndex);
setState(() {}); setState(() {});
}, },
@ -229,8 +226,19 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
width: 40.w, width: 40.w,
height: 40.w, height: 40.w,
child: Radio( child: Radio(
onChanged: (int? value) { onChanged: (int? value) async{
final SharedPreferences prefs = await SharedPreferences.getInstance();
select = index; 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); // print(_selectIndex);
setState(() {}); setState(() {});
}, },

@ -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/utils/headers.dart';
import 'package:project_telephony/ui/widget/plone_bottom.dart'; import 'package:project_telephony/ui/widget/plone_bottom.dart';
import 'package:project_telephony/utils/toast/cloud_toast.dart'; import 'package:project_telephony/utils/toast/cloud_toast.dart';
import 'package:project_telephony/utils/user_tool.dart';
import '../../../base/base_style.dart'; import '../../../base/base_style.dart';
import '../../../model/exclude_phone_model.dart'; import '../../../model/exclude_phone_model.dart';
@ -69,31 +70,22 @@ class _SpecifyPhonePageState extends State<SpecifyPhonePage> {
// Get.to(() => const CallRecordsList()); // Get.to(() => const CallRecordsList());
}), }),
_getAddPhone("通迅录添加", "通过本机通讯录添加号码", () async { _getAddPhone("通迅录添加", "通过本机通讯录添加号码", () {
if (await Permission.contacts.isDenied) { Navigator.of(context)
showDialog( .push(
context: context, MaterialPageRoute(
builder: (context) { builder: (_) => const ExcludeContactsPage()),
return AlertDialog( )
content: const Text('获取通讯录权限还未开启'), .then((val) =>_refreshController.callRefresh());
actions: [
ElevatedButton(
onPressed: () {
openAppSettings();
},
child: const Text("前往开启"),
),
],
);
});
} else {
Get.to(() => (const ExcludeContactsPage()));
}
}), }),
_getAddPhone("添加单个或批量号码", "通过输入号码段添加批量号码", () { _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<SpecifyPhonePage> {
// footer: MaterialFooter(), // footer: MaterialFooter(),
onRefresh: () async { onRefresh: () async {
findList = await ExcludeFunc.getContacts(); findList = await ExcludeFunc.getContacts();
UserTool.userProvider.viewLoading();
// await userProvider.updateUserInfo(); // await userProvider.updateUserInfo();
setState(() {}); setState(() {});

@ -11,7 +11,7 @@ import 'package:project_telephony/utils/headers.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../../base/base_style.dart'; import '../../base/base_style.dart';
import '../../constants/api.dart'; import '../../constants/api.dart';
import '../../constants/environment/environment.dart';
import '../../model/network/api_client.dart'; import '../../model/network/api_client.dart';
import '../../providers/user_provider.dart'; import '../../providers/user_provider.dart';
import '../../utils/toast/cloud_toast.dart'; import '../../utils/toast/cloud_toast.dart';
@ -132,8 +132,8 @@ class _LoginPageState extends State<LoginPage> {
} else if (!_chooseAgreement) { } else if (!_chooseAgreement) {
BotToast.showText(text: "请同意并勾选隐私政策"); BotToast.showText(text: "请同意并勾选隐私政策");
} else { } else {
if (_lastTap != null && if (_lastTap != null && DateTime.now().difference(_lastTap!).inSeconds < 2) {
DateTime.now().difference(_lastTap!).inSeconds < 2) { // BotToast.showText(text: "过快");
return; return;
} }
_lastTap = DateTime.now(); _lastTap = DateTime.now();

@ -21,6 +21,7 @@ class CloudBackButton extends StatelessWidget {
onPressed: () { onPressed: () {
print("返回传值"); print("返回传值");
Navigator.pop(context,true); Navigator.pop(context,true);
Get.back();
}, },
icon: Icon( icon: Icon(

Loading…
Cancel
Save