Work on implementing sheetable client

This commit is contained in:
2024-12-18 00:36:33 +01:00
parent 0825f048cd
commit f530a52e9d
8 changed files with 620 additions and 209 deletions

View File

@@ -4,50 +4,53 @@ import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
class Sheet {
final String author;
final String uuid;
final String name;
final String path;
final String composerUuid;
final DateTime releaseDate;
final String file;
final String fileHash;
final bool wasUploaded;
final int uploaderId;
final DateTime createdAt;
final DateTime updatedAt;
final DateTime lastOpened;
final List<String> tags;
final String informationText;
Sheet(this.author, this.name, this.path);
}
Sheet({
required this.uuid,
required this.name,
required this.composerUuid,
required this.releaseDate,
required this.file,
required this.fileHash,
required this.wasUploaded,
required this.uploaderId,
required this.createdAt,
required this.updatedAt,
required this.lastOpened,
required this.tags,
required this.informationText,
});
Future<List<Sheet>> loadSheetsSorted(List<String> sheetsDirectoryFiles) async {
var sheets = await _loadSheets(sheetsDirectoryFiles);
sheets.sort((left, right) => left.name.compareTo(right.name));
return sheets;
}
Future<List<Sheet>> _loadSheets(List<String> sheetsDirectoryFiles) async {
final List<Sheet> sheets = List.empty(growable: true);
var authorDirectories = sheetsDirectoryFiles
.map((e) => Directory(e))
.where((element) => element.existsSync());
for (Directory authorDirectory in authorDirectories) {
var authorName = p.basename(authorDirectory.path);
// Ignore hidden directories
if (authorName.startsWith(".")) {
continue;
}
await for (final FileSystemEntity sheetFile in authorDirectory.list()) {
if (sheetFile is File) {
var sheetName = p.basenameWithoutExtension(sheetFile.path);
// Ignore hidden files
if (sheetName.startsWith(".")) {
continue;
}
sheetName = sheetName.capitalize();
sheets.add(Sheet(authorName, sheetName, sheetFile.path));
}
}
}
return sheets;
}
extension StringExtension on String {
String capitalize() {
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
// Factory constructor for creating a Sheet from JSON
factory Sheet.fromJson(Map<String, dynamic> json) {
return Sheet(
uuid: json['uuid'],
name: json['sheet_name'],
composerUuid: json['composer_uuid'],
releaseDate: DateTime.parse(json['release_date']),
file: json['file'],
fileHash: json['file_hash'],
wasUploaded: json['was_uploaded'],
uploaderId: json['uploader_id'],
createdAt: DateTime.parse(json['created_at']),
updatedAt: DateTime.parse(json['updated_at']),
lastOpened: DateTime.parse(json['last_opened']),
tags: List<String>.from(json['tags']),
informationText: json['information_text'],
);
}
}
@@ -65,7 +68,7 @@ class SheetsWidget extends StatelessWidget {
var sheet = sheets[index];
return ListTile(
title: Text(sheet.name),
subtitle: Text(sheet.author),
subtitle: Text(sheet.uuid),
onTap: () => callback(sheet),
);
});