summaryrefslogtreecommitdiff
path: root/lib/level_selection.dart
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2025-01-07 06:38:34 +0100
committerOrangerot <purple@orangerot.dev>2025-01-07 06:38:34 +0100
commit9c229b94d0aa52679e12e50d62aa8e6cbf9fb9c5 (patch)
treec148c6ee4bbf664be3f1a64f9c9501f00b38edf2 /lib/level_selection.dart
parent685323adeab3d27bff4df16a201f9f14688475d5 (diff)
style: refactored searching files into Simfile class
Diffstat (limited to 'lib/level_selection.dart')
-rw-r--r--lib/level_selection.dart44
1 files changed, 20 insertions, 24 deletions
diff --git a/lib/level_selection.dart b/lib/level_selection.dart
index 5359d66..0c1a0fe 100644
--- a/lib/level_selection.dart
+++ b/lib/level_selection.dart
@@ -5,6 +5,7 @@ import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sense_the_rhythm/esense_connect_dialog.dart';
+import 'package:sense_the_rhythm/simfile.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'level.dart';
@@ -18,7 +19,7 @@ class LevelSelection extends StatefulWidget {
class _LevelSelectionState extends State<LevelSelection> {
String? stepmaniaCoursesPath;
- List<FileSystemEntity> stepmaniaCoursesFolders = [];
+ List<Simfile> stepmaniaCoursesFolders = [];
String eSenseDeviceName = '';
ESenseManager? eSenseManager;
@@ -109,8 +110,9 @@ class _LevelSelectionState extends State<LevelSelection> {
prefs.getString('stepmania_courses');
if (stepmaniaCoursesPathSetting == null) return;
- List<FileSystemEntity> stepmaniaCoursesFoldersFuture = await listFilesAndFolders(stepmaniaCoursesPathSetting);
-
+ List<Simfile> stepmaniaCoursesFoldersFuture =
+ await listFilesAndFolders(stepmaniaCoursesPathSetting);
+
setState(() {
stepmaniaCoursesPath = stepmaniaCoursesPathSetting;
stepmaniaCoursesFolders = stepmaniaCoursesFoldersFuture;
@@ -129,15 +131,18 @@ class _LevelSelectionState extends State<LevelSelection> {
}
}
- Future<List<FileSystemEntity>> listFilesAndFolders(
- String directoryPath) async {
+ Future<List<Simfile>> listFilesAndFolders(String directoryPath) async {
final directory = Directory(directoryPath);
try {
// List all files and folders in the directory
return directory
.listSync()
.where((entity) => FileSystemEntity.isDirectorySync(entity.path))
- .toList();
+ .map((entity) {
+ Simfile simfile = Simfile(entity.path);
+ simfile.load();
+ return simfile;
+ }).toList();
} catch (e) {
print("Error reading directory: $e");
return [];
@@ -155,10 +160,10 @@ class _LevelSelectionState extends State<LevelSelection> {
context: context,
builder: (BuildContext context) {
return ESenseConnectDialog(
- deviceStatus: _deviceStatus,
- connect: (String name) {
- _connectToESense(name);
- });
+ deviceStatus: _deviceStatus,
+ connect: (String name) {
+ _connectToESense(name);
+ });
},
),
icon: const Icon(Icons.bluetooth))
@@ -176,26 +181,17 @@ class _LevelSelectionState extends State<LevelSelection> {
separatorBuilder: (BuildContext context, int index) =>
const Divider(),
itemBuilder: (context, index) {
- String thumbnailPath = Directory(
- stepmaniaCoursesFolders[index].path)
- .listSync()
- .firstWhere(
- (file) => file.path.toLowerCase().endsWith('banner.png'),
- orElse: () => File(''))
- .path;
return ListTile(
- leading: Image.file(File(thumbnailPath)),
+ leading: Image.file(
+ File(stepmaniaCoursesFolders[index].bannerPath!)),
trailing: Icon(Icons.play_arrow),
- title:
- Text(stepmaniaCoursesFolders[index].path.split('/').last),
+ title: Text(stepmaniaCoursesFolders[index].tags["TITLE"]!),
subtitle: Text('3:45'),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
- builder: (BuildContext context) => Level(
- stepmaniaFolderPath:
- stepmaniaCoursesFolders[index].path,
- ))),
+ builder: (BuildContext context) =>
+ Level(stepmaniaCoursesFolders[index]))),
);
},
);