Browse Source

feat(translation): 为音频文件列表添加按修改时间降序排序功能

为翻译模块的音频文件列表添加按修改时间降序排序功能,最新的文件显示在最上方
同时为会议模块添加音频类型区分,支持识别翻译模块的音频文件
newdev_shunjiawei
lxm 12 months ago
parent
commit
09c71e31e3
  1. 1
      lib/modules/meeting/controllers/meeting_controller.dart
  2. 13
      lib/modules/meeting/controllers/meeting_home_controller.dart
  3. 13
      lib/modules/translation/controllers/translation_list_controller.dart

1
lib/modules/meeting/controllers/meeting_controller.dart

@ -5,6 +5,7 @@ import '../../../data/services/db/sqflite_api.dart';
import '../views/meeting_home_view.dart';
import '../views/meeting_mine_view.dart';
// 会议模块控制器
class MeetingController extends GetxController {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();

13
lib/modules/meeting/controllers/meeting_home_controller.dart

@ -188,8 +188,10 @@ class MeetingHomeController extends GetxController {
Directory("${appDir.path}/DestAudio/"),
];
// 目标目录:LocalAudio
final destDir = Directory("${appDir.path}/LocalAudio/");
if (!await destDir.exists()) {
// 检查目标目录是否存在
await destDir.create(recursive: true);
}
@ -335,9 +337,14 @@ class MeetingHomeController extends GetxController {
EasyLoading.show(status: 'importing'.tr); // 对应中文:正在导入...
String fileName = "";
bool isParamProvided = filePath != null; // 更清晰的变量名
String audioType = 'IMPORT'; // 默认类型为IMPORT
if (filePath != null) {
// 正确截取文件名(跨平台安全方式)
fileName = path.basename(filePath);
// 检查是否来自翻译模块
if (filePath.contains('/TranslatAudio/')) {
audioType = 'TRANSLAT'; // 设置为翻译音频类型
}
} else {
FilePickerResult? result = await FilePicker.platform.pickFiles(
withData: false,
@ -368,7 +375,8 @@ class MeetingHomeController extends GetxController {
}
}
final meetingId = await insertMeetingAudio(fileName, filePath);
final meetingId =
await insertMeetingAudio(fileName, filePath, type: audioType);
if (isParamProvided) {
Get.toNamed(Routes.meetingDetails, arguments: {
@ -382,13 +390,14 @@ class MeetingHomeController extends GetxController {
String fileName,
String filePath, {
bool isUpload = true,
String type = 'IMPORT', //添加type参数,默认为'IMPORT'
}) async {
await _audioPlayer.setAudioSource(AudioSource.file(filePath));
int seconds = _audioPlayer.duration?.inSeconds ?? 0;
int creationTime = DateTime.now().millisecondsSinceEpoch;
Map<String, Object?> data = {
'title': fileName,
'type': 'IMPORT',
'type': type, // 使用传入的type参数
'seconds': seconds,
'filepath': filePath,
'audiourl': '',

13
lib/modules/translation/controllers/translation_list_controller.dart

@ -164,8 +164,8 @@ class TranslationListController extends GetxController {
return;
}
// Directory exis
files.value = dir
// 获取音频文件列表并按修改时间降序排序(最新的在最上面)
final audioFiles = dir
.listSync()
.where((f) =>
f is File &&
@ -176,6 +176,15 @@ class TranslationListController extends GetxController {
f.path.endsWith('.mp4') ||
f.path.endsWith('.mov')))
.toList();
// 按文件修改时间降序排序,最新的录音文件在最上面
audioFiles.sort((a, b) {
final aStat = a.statSync();
final bStat = b.statSync();
return bStat.modified.compareTo(aStat.modified); // 降序排序
});
files.value = audioFiles;
} catch (e) {
print("Error loading files: $e");
files.value = []; // Return empty list on error

Loading…
Cancel
Save