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/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<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) {
BotToast.showText(text: res.msg);
Get.back();
Get.back();
}
} else {
BotToast.showText(text: "还未选中手机号");

@ -59,6 +59,7 @@ class _ExcludeSinglePageState extends State<ExcludeSinglePage> {
BotToast.showText(text: res.msg);
if (res.code == 0) {
Get.back();
Get.back();
}
}
},
@ -74,25 +75,25 @@ class _ExcludeSinglePageState extends State<ExcludeSinglePage> {
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,
// ),
// ),
// ],
// ),
// ),
],
),
),

@ -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("来电拒接/未接");

@ -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<HomePage> 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<HomePage> 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<HomePage> 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<HomePage> 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),

@ -70,7 +70,6 @@ class _CallRecordsListState extends State<CallRecordsList> {
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<CallRecordsList> {
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();

@ -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<PhoneSetPage> {
List<Contact>? contact;
List<String> numbers = [];
List<String>? numList = [];
DateTime? _lastTap;
final EasyRefreshController _refreshController = EasyRefreshController();
List setList = [
{
@ -75,10 +78,9 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
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<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(() {});
}
// 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) {
final service = FlutterBackgroundService();
return GestureDetector(
onTap: () async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
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();
// 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();
// print(_selectIndex);
setState(() {});
},
@ -229,8 +226,19 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
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(() {});
},

@ -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<SpecifyPhonePage> {
// 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<SpecifyPhonePage> {
// footer: MaterialFooter(),
onRefresh: () async {
findList = await ExcludeFunc.getContacts();
UserTool.userProvider.viewLoading();
// await userProvider.updateUserInfo();
setState(() {});

@ -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,8 @@ class _LoginPageState extends State<LoginPage> {
} 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;
}
_lastTap = DateTime.now();

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

Loading…
Cancel
Save