新增发送周期

master
戴余标 2 years ago
parent 306a273a8c
commit a7ec1b63c2

@ -0,0 +1,103 @@
import 'dart:io';
import 'package:flustars/flustars.dart';
import 'package:path_provider/path_provider.dart';
import 'package:project_telephony/model/send_number_model.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';
class DBManager {
///
final String _dbName = "dbName";
///
final int _version = 1;
static final DBManager _instance = DBManager._();
factory DBManager() {
return _instance;
}
DBManager._();
static Database? _db;
Future<Database> get db async {
return _db ??= await _initDB();
}
///
Future<Database> _initDB() async {
Directory directory = await getApplicationDocumentsDirectory();
String path = join(directory.path, _dbName);
return await openDatabase(
path,
version: _version,
onCreate: _onCreate,
onUpgrade: _onUpgrade,
);
}
///
Future _onCreate(Database db, int version) async {
const String sql = """
CREATE TABLE SendNumber(
id INTEGER primary key AUTOINCREMENT,
sendNumber TEXT,
createdAt datetime
)
""";
return await db.execute(sql);
}
///
Future _onUpgrade(Database db, int oldVersion, int newVersion) async {}
///
Future saveData(SendNumber sendNumber) async {
Database database = await db;
return await database.insert("SendNumber", sendNumber.toJson());
}
/// 使SQL
Future saveDataBySQL(SendNumber sendNumber) async {
const String sql = """
INSERT INTO SendNumber(sendNumber,createdAt) values(?,?)
""";
Database database = await db;
return await database.rawInsert(sql, [sendNumber.sendNumber, sendNumber.createdAt]);
}
///
Future<List<SendNumber>?> findAll() async {
Database? database = await db;
List<Map<String, Object?>> result = await database.query("SendNumber");
if (result.isNotEmpty) {
return result.map((e) => SendNumber.fromJson(e)).toList();
} else {
return [];
}
}
///
Future<List<SendNumber>?> find(String sendNumber) async {
Database database = await db;
List<Map<String, Object?>> result =
await database.query("SendNumber", where: "sendNumber=?", whereArgs: [sendNumber]);
if (result.isNotEmpty) {
return result.map((e) => SendNumber.fromJson(e)).toList();
} else {
return [];
}
}
///
Future<int> update(SendNumber sendNumber) async {
Database database = await db;
sendNumber.createdAt = DateUtil.formatDate(DateTime.now());
int count =
await database.update("SendNumber", sendNumber.toJson(), where: "sendNumber=?", whereArgs: [sendNumber.sendNumber]);
return count;
}
}

@ -31,6 +31,7 @@ class API {
static _Pay pay = _Pay();
static _Exclude exclude = _Exclude();
static _Content content = _Content();
static _Send send = _Send();
}
class _App {
@ -124,3 +125,11 @@ class _Exclude {
///
String get findAll => '/app/exclude/findAll';
}
class _Send {
///
String get add => '/app/send/add';
///
String get select => '/send/select';
}

@ -0,0 +1,27 @@
import 'dart:convert';
SendNumber sendNumberFromJson(String str) => SendNumber.fromJson(json.decode(str));
String sendNumberToJson(SendNumber data) => json.encode(data.toJson());
class SendNumber {
SendNumber({
this.sendNumber,
this.createdAt,
});
SendNumber.fromJson(dynamic json) {
sendNumber = json['sendNumber'];
createdAt = json['createdAt'];
}
String? sendNumber;
String? createdAt;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['sendNumber'] = sendNumber;
map['createdAt'] = createdAt;
return map;
}
}

@ -2,22 +2,27 @@ import 'dart:async';
import 'dart:ui';
import 'package:call_log/call_log.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:project_telephony/model/send_number_model.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:telephony/telephony.dart';
import '../../base/DBManager.dart';
import '../user/user_page.dart';
const nId = "my_foreground";
const notificationId = 888;
Future<void> initializeService() async {
final service = FlutterBackgroundService();
const AndroidNotificationChannel channel = AndroidNotificationChannel(
nId, // id
'我的前台服务', // title
description:
'此通道用于重要通知。', // description
description: '此通道用于重要通知。', // description
importance: Importance.low, // importance must be at low or higher level
);
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
@ -43,7 +48,8 @@ Future<void> initializeService() async {
autoStart: true,
isForegroundMode: true,
notificationChannelId: nId, // this must match with notification channel you created above.
notificationChannelId: nId,
// this must match with notification channel you created above.
initialNotificationTitle: 'AWESOME SERVICE',
initialNotificationContent: 'Initializing',
foregroundServiceNotificationId: notificationId,
@ -70,6 +76,7 @@ void onStart(ServiceInstance service) async {
int flag = 0;
String? phoneNum = "";
String callState;
bool fff=false;
Timer.periodic(const Duration(seconds: 1), (timer) async {
//
@ -96,16 +103,31 @@ void onStart(ServiceInstance service) async {
String content = prefs.getString("refSms") ?? "现在有事,等会回电";
//
int? numberSet = prefs.getInt("numIndex") ?? 1;
int? dayTimes =prefs.getInt("dayTimes")??0;
print("号码设置$numberSet 发送内容$content 指定不发送$noNumberList");
// print(flag);
if (callState == "IDLE") {
if (flag != 0) {
print(dayTimes);
final Iterable<CallLogEntry> entry = await CallLog.query();
phoneNum = entry.first.number;
// print(phoneNum);
var phone = SendNumber(
sendNumber: phoneNum,
createdAt: DateUtil.formatDate(DateTime.now()),
);
var s = await DBManager().find(phoneNum!);
if (s!.isEmpty) {
await DBManager().saveData(phone);
fff=true;
}else if(DateTime.parse(s.first.createdAt!)
.add(Duration(days: dayTimes))
.isBefore(DateTime.now())) {
await DBManager().update(phone);
fff=true;
}
if(fff){
switch (numberSet) {
case 0:
if (!noNumberList.contains(phoneNum)) {
print("所有都发+号码设置$numberSet+发送内容$content");
Telephony.backgroundInstance
@ -143,7 +165,6 @@ void onStart(ServiceInstance service) async {
flag = 0;
}
}
break;
case 2:
if (flag == -2) {
@ -169,6 +190,8 @@ void onStart(ServiceInstance service) async {
flag = 0;
break;
}
fff=false;
}
}
} else if (callState == "RINGING") {
flag = 1;

@ -76,13 +76,14 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
},
];
List cycleList = [
'每天发送',
'发送无限制',
"一天内发送一次",
"三天内发送一次",
"七天天内发送一次",
"十五天内发送一次",
"三十天内发送一次"
];
List dayTimes=[0,1,3,7,15,30];
String cycleText = "";
@override
@ -123,7 +124,7 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
await SharedPreferences.getInstance();
// print(prefs.getInt("numIndex"));
select = (prefs.getInt("numIndex")) ?? 0;
cycleText = prefs.getString("cycle") ?? "每天发送";
cycleText = prefs.getString("cycle") ?? "发送无限制";
UserTool.userProvider.viewLoading();
_getRequests();
@ -388,6 +389,7 @@ class _PhoneSetPageState extends State<PhoneSetPage> {
BotToast.showText(text: "成功");
prefs.setString(
"cycle", cycleList[index]);
prefs.setInt('dayTimes', dayTimes[index]);
BotToast.showText(
text: cycleList[index]);
Navigator.pop(context);

@ -93,7 +93,7 @@ final FocusNode verifyNode=FocusNode();
filled: true,
isDense: true,
fillColor: Colors.transparent ,
hintText: widget.content.isNotEmpty ? "" : "请输入所需短信",
hintText: UserTool.userProvider.userInfo.tag.isNotEmpty ? UserTool.userProvider.userInfo.tag : "请输入所需短信",
hintStyle: TextStyle(
color: widget.content != ""
? const Color(0xFF333333)
@ -122,7 +122,7 @@ final FocusNode verifyNode=FocusNode();
service.startService();
});
}
// UserTool.userProvider.updateUserInfo();
UserTool.userProvider.updateUserInfo();
// UserTool.userProvider.updateConSms();
Get.back();
} else {

@ -1035,6 +1035,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
sqflite:
dependency: "direct main"
description:
name: sqflite
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3+1"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
stack_trace:
dependency: transitive
description:
@ -1270,4 +1284,4 @@ packages:
version: "3.1.1"
sdks:
dart: ">=2.17.0 <3.0.0"
flutter: ">=2.10.0"
flutter: ">=3.0.0"

@ -91,9 +91,11 @@ dependencies:
flutter_update_dialog: ^2.0.0
# http
dio: ^4.0.6
# 版本
# 版本
flutter_xupdate: ^2.0.3
path_provider: ^2.0.11
# 本地数据库
sqflite: ^2.0.3+1
## 生成适配器
# hive_generator: ^1.1.3
# # jdk

Loading…
Cancel
Save