戴余标 2 years ago
commit 35d5816734

@ -4,6 +4,7 @@ import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart'; import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
import '../../constants/api.dart'; import '../../constants/api.dart';
@ -21,15 +22,18 @@ class ExcludeContactsPage extends StatefulWidget {
class _ExcludeContactsPageState extends State<ExcludeContactsPage> { class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
List<Contact>? contacts; List<Contact>? contacts;
List<String> numbers = []; List<String> numbers = [];
List<String> numbers1 = [];
List<bool> status = []; List<bool> status = [];
var flag = true; var flag = true;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_viewLoading();
} }
Future _viewLoading() async { Future _viewLoading() async {
// final SharedPreferences prefs = await SharedPreferences.getInstance();
contacts = await FlutterContacts.getContacts(); contacts = await FlutterContacts.getContacts();
for (var element in contacts!) { for (var element in contacts!) {
final full = await FlutterContacts.getContact(element.id); final full = await FlutterContacts.getContact(element.id);
@ -40,6 +44,8 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
} }
status.add(false); status.add(false);
} }
// await prefs.setStringList("addressList", numbers);
print(contacts?.length);
setState(() {}); setState(() {});
} }
@ -52,9 +58,12 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
flag = false; flag = false;
return Container(); return Container();
} else { } else {
return ListView.builder( return ListView.builder(
itemCount: contacts!.length, itemCount: contacts!.length,
itemBuilder: (context, i) => ListTile( itemBuilder: (context, i) {
return ListTile(
title: Text( title: Text(
contacts![i].displayName, contacts![i].displayName,
style: TextStyle( style: TextStyle(
@ -82,8 +91,8 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
// //
checkColor: Colors.white, checkColor: Colors.white,
), ),
).paddingOnly(left: 20.w), ).paddingOnly(left: 20.w);
); });
} }
}, },
); );

@ -47,18 +47,11 @@ void onStart(ServiceInstance service) async {
service.on('stopService').listen((event) { service.on('stopService').listen((event) {
service.stopSelf(); 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 { Timer.periodic(const Duration(seconds: 1), (timer) async {
final SharedPreferences prefs = await SharedPreferences.getInstance(); final SharedPreferences prefs = await SharedPreferences.getInstance();
CallState state = await Telephony.instance.callState; CallState state = await Telephony.instance.callState;
callState = state.name; callState = state.name;
print("$callState$flag"); // print("$callState$flag");
// print(entry.first.duration); // print(entry.first.duration);
String? ref = prefs.getString('refSms'); String? ref = prefs.getString('refSms');
String? con = prefs.getString('conSms'); String? con = prefs.getString('conSms');
@ -66,51 +59,143 @@ void onStart(ServiceInstance service) async {
String? idle = prefs.getString('idleSms'); String? idle = prefs.getString('idleSms');
bool? callSw = prefs.getBool('callSwitch'); bool? callSw = prefs.getBool('callSwitch');
bool? idleSw = prefs.getBool('idleSwitch'); bool? idleSw = prefs.getBool('idleSwitch');
int? numberSet = prefs.getInt("numIndex");
List<String>? numberList = prefs.getStringList("addressList");
List<String>? noNumberList = prefs.getStringList("specified");
print("号码设置$numberSet 通讯列表$numberList 指定不发送$noNumberList");
if (callState == "IDLE") { if (callState == "IDLE") {
if (flag != 0) { if (flag != 0) {
final Iterable<CallLogEntry> entry = await CallLog.query(); final Iterable<CallLogEntry> entry = await CallLog.query();
phoneNum = entry.first.number; phoneNum = entry.first.number;
callRecords = entry.first.duration; callRecords = entry.first.duration;
print(phoneNum); print(phoneNum);
switch (numberSet) {
case 0:
if (!(noNumberList?.contains(phoneNum))!) {
if (flag > 0) { if (flag > 0) {
print("来电拒接/未接"); print("来电拒接/未接");
print("${phoneNum!}:${ref!}"); print("${phoneNum!}:${ref!}");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: ref); Telephony.backgroundInstance
.sendSms(to: phoneNum!, message: ref);
print("发送成功"); print("发送成功");
} else if(flag==-1){ } else if (flag == -1) {
print("来电接听"); print("来电接听");
print("${phoneNum!}:${con!}"); print("${phoneNum!}:${con!}");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: 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");
} }
else { break;
if(entry.first.duration!>0){ case 1:
if(callSw!){ 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(callSw);
print("${phoneNum!}:${call!}"); print("${phoneNum!}:${call!}");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: call); Telephony.backgroundInstance
.sendSms(to: phoneNum!, message: call);
} }
print("去电接听"); print("去电接听");
} else {
if (idleSw!) {
print(idleSw);
print("${phoneNum!}:${idle!}");
Telephony.backgroundInstance
.sendSms(to: phoneNum!, message: idle);
}
print("去电未接");
}
print("发送成功");
}
flag = 0;
}else{ }else{
if(idleSw!){ print("123412434124132312232341241242321312312323123323");
}
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(idleSw);
print("${phoneNum!}:${idle!}"); print("${phoneNum!}:${idle!}");
Telephony.backgroundInstance.sendSms(to: phoneNum!, message: idle); Telephony.backgroundInstance
.sendSms(to: phoneNum!, message: idle);
} }
print("去电未接"); print("去电未接");
} }
print("发送成功"); print("发送成功");
} }
flag = 0; flag = 0;
}else{
print("123412434124132312232341241242321312312323123323");
}
break;
}
} }
} else if (callState == "RINGING") { } else if (callState == "RINGING") {
// //
flag=1; flag = 1;
print('通话'); print('通话');
} else if (callState == "OFFHOOK") { } else if (callState == "OFFHOOK") {
// //
if (flag > 0) flag *= -1; if (flag > 0) flag *= -1;
if(flag==0)flag=-2; if (flag == 0) flag = -2;
print('不通话'); print('不通话');
} }
}); });

@ -95,9 +95,10 @@ class _CallRecordsListState extends State<CallRecordsList> {
if (phoneNum3.isEmpty) { if (phoneNum3.isEmpty) {
CloudToast.show('请选择手机号'); CloudToast.show('请选择手机号');
} else { } else {
print(phoneNum3); // print(phoneNum3);
var res = await ExcludeFunc.getContactsList(phoneNum3); await ExcludeFunc.getContactsList(phoneNum3);
print(res); Navigator.pop(context,true);
} }
// _easyRefreshController.callRefresh(); // _easyRefreshController.callRefresh();
// phoneNum3.clear(); // phoneNum3.clear();

@ -1,7 +1,11 @@
import 'package:flutter/material.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/ui/home/set/specify_phone_page.dart';
import 'package:project_telephony/utils/headers.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 '../../../base/base_style.dart';
import '../../widget/plone_back_button.dart'; import '../../widget/plone_back_button.dart';
@ -11,7 +15,6 @@ import '../../widget/plone_back_button.dart';
// } // }
class PhoneSetPage extends StatefulWidget { class PhoneSetPage extends StatefulWidget {
const PhoneSetPage({Key? key}) : super(key: key); const PhoneSetPage({Key? key}) : super(key: key);
@override @override
@ -20,6 +23,10 @@ class PhoneSetPage extends StatefulWidget {
class _PhoneSetPageState extends State<PhoneSetPage> { class _PhoneSetPageState extends State<PhoneSetPage> {
int select = 0; int select = 0;
List<Contact>? contact;
List<String> numbers = [];
List<String>? numList = [];
final EasyRefreshController _refreshController = EasyRefreshController();
List setList = [ List setList = [
{ {
"icon": Assets.icons.rylyphone.path, "icon": Assets.icons.rylyphone.path,
@ -41,6 +48,11 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
}, },
]; ];
@override
void initState() {
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -57,16 +69,29 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
leading: const CloudBackButton(isSpecial: true), leading: const CloudBackButton(isSpecial: true),
backgroundColor: kForeGroundColor), backgroundColor: kForeGroundColor),
backgroundColor: kForeGroundColor, backgroundColor: kForeGroundColor,
body: Column( 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: [ children: [
_getList(), _getList(),
24.hb, 24.hb,
GestureDetector( GestureDetector(
onTap: () { onTap: () {
Get.to(()=>const SpecifyPhonePage()); Get.to(() => const SpecifyPhonePage());
}, },
child: Container( child: Container(
padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 30.w), padding:
EdgeInsets.symmetric(horizontal: 32.w, vertical: 30.w),
height: 144.w, height: 144.w,
child: ListTile( child: ListTile(
leading: SizedBox( leading: SizedBox(
@ -79,8 +104,8 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
), ),
title: Text( title: Text(
"指定号码不发送", "指定号码不发送",
style: style: TextStyle(
TextStyle(fontSize: 32.sp, fontWeight: FontWeight.bold), fontSize: 32.sp, fontWeight: FontWeight.bold),
), ),
subtitle: Text( subtitle: Text(
"通过添加指定号码来设置不发送", "通过添加指定号码来设置不发送",
@ -96,6 +121,15 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
) )
], ],
), ),
)
// Column(
// children: [
//
//
//
// ],
// ),
); );
} }
@ -112,10 +146,66 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
); );
} }
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<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(() {});
}
_getListBox(List item, int index) { _getListBox(List item, int index) {
final service = FlutterBackgroundService();
return GestureDetector( return GestureDetector(
onTap: () { onTap: () async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
select = index; select = index;
await prefs.setInt("numIndex", index);
print(await service.isRunning());
if (await service.isRunning()) {
service.invoke("stopService");
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
} else {
service.startService();
Future.delayed(const Duration(seconds: 2), () async {
service.invoke("stopService");
});
}
print( prefs.getStringList("specified"));
_refreshController.callRefresh();
// print(_selectIndex); // print(_selectIndex);
setState(() {}); setState(() {});
}, },

@ -65,7 +65,7 @@ class _SpecifyPhonePageState extends State<SpecifyPhonePage> {
MaterialPageRoute( MaterialPageRoute(
builder: (_) => const CallRecordsList()), builder: (_) => const CallRecordsList()),
) )
.then((val) => _getNullList()); .then((val) =>_refreshController.callRefresh());
// Get.to(() => const CallRecordsList()); // Get.to(() => const CallRecordsList());
}), }),
@ -89,9 +89,11 @@ class _SpecifyPhonePageState extends State<SpecifyPhonePage> {
} else { } else {
Get.to(() => (const ExcludeContactsPage())); Get.to(() => (const ExcludeContactsPage()));
} }
}), }),
_getAddPhone("添加单个或批量号码", "通过输入号码段添加批量号码", () { _getAddPhone("添加单个或批量号码", "通过输入号码段添加批量号码", () {
Get.to(() => (const ExcludeSinglePage())); Get.to(() => (const ExcludeSinglePage()));
}), }),
], ],
)), )),
@ -112,6 +114,7 @@ class _SpecifyPhonePageState extends State<SpecifyPhonePage> {
); );
}, },
context: context); context: context);
}, },
child: EasyRefresh( child: EasyRefresh(
firstRefresh: true, firstRefresh: true,

@ -78,6 +78,7 @@ class _MembersPageState extends State<MembersPage> {
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: EasyRefresh( body: EasyRefresh(
firstRefresh: true, firstRefresh: true,
@ -86,7 +87,6 @@ class _MembersPageState extends State<MembersPage> {
controller: _easyRefreshController, controller: _easyRefreshController,
onRefresh: () async { onRefresh: () async {
await UserTool.userProvider.updateUserInfo(); await UserTool.userProvider.updateUserInfo();
setState(() {}); setState(() {});
}, },
child: Stack( child: Stack(

@ -151,9 +151,7 @@ class PayUtil {
_wxPayStream?.cancel(); _wxPayStream?.cancel();
} }
Future callWxPay({ Future callWxPay({required WxPayModel payModel, }) async {
required WxPayModel payModel,
}) async {
await payWithWeChat( await payWithWeChat(
appId: 'wx3a0b41d12afef4e2', appId: 'wx3a0b41d12afef4e2',
partnerId: payModel.partnerId, partnerId: payModel.partnerId,

Loading…
Cancel
Save