first commit

This commit is contained in:
ytc1012
2025-11-13 15:45:28 +08:00
commit 6b321890c0
54 changed files with 8412 additions and 0 deletions

70
lib/models/app_usage.dart Normal file
View File

@@ -0,0 +1,70 @@
class AppUsage {
final int? id;
final String packageName;
final String appName;
final DateTime startTime;
final DateTime endTime;
final int duration; // 秒
final String category;
final int? projectId;
final int deviceUnlockCount;
final DateTime createdAt;
final DateTime updatedAt;
AppUsage({
this.id,
required this.packageName,
required this.appName,
required this.startTime,
required this.endTime,
required this.duration,
required this.category,
this.projectId,
this.deviceUnlockCount = 0,
required this.createdAt,
required this.updatedAt,
});
Map<String, dynamic> toMap() {
return {
'id': id,
'package_name': packageName,
'app_name': appName,
'start_time': startTime.millisecondsSinceEpoch ~/ 1000,
'end_time': endTime.millisecondsSinceEpoch ~/ 1000,
'duration': duration,
'category': category,
'project_id': projectId,
'device_unlock_count': deviceUnlockCount,
'created_at': createdAt.millisecondsSinceEpoch ~/ 1000,
'updated_at': updatedAt.millisecondsSinceEpoch ~/ 1000,
};
}
factory AppUsage.fromMap(Map<String, dynamic> map) {
return AppUsage(
id: map['id'],
packageName: map['package_name'],
appName: map['app_name'],
startTime: DateTime.fromMillisecondsSinceEpoch(map['start_time'] * 1000),
endTime: DateTime.fromMillisecondsSinceEpoch(map['end_time'] * 1000),
duration: map['duration'],
category: map['category'],
projectId: map['project_id'],
deviceUnlockCount: map['device_unlock_count'] ?? 0,
createdAt: DateTime.fromMillisecondsSinceEpoch(map['created_at'] * 1000),
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updated_at'] * 1000),
);
}
// 格式化时长
String get formattedDuration {
final hours = duration ~/ 3600;
final minutes = (duration % 3600) ~/ 60;
if (hours > 0) {
return '${hours}h ${minutes}m';
}
return '${minutes}m';
}
}