simplified code across the app and consolidated duplicated helpers

This commit is contained in:
2026-09-27 17:29:54 +02:00
parent 3e856d0b1c
commit ee1240f71a
155 changed files with 1772 additions and 2546 deletions
+25
View File
@@ -0,0 +1,25 @@
import '../../../../api/marianumcloud/webdav/queries/list_files/cacheable_file.dart';
import '../../../../api/marianumcloud/webdav/queries/list_files/list_files_response.dart';
import '../../../../state/app/modules/settings/bloc/settings_cubit.dart';
import 'sort_options.dart';
typedef FileSort = ({SortOption by, bool ascending, bool foldersToTop});
/// Selector for `context.select`, so folder views rebuild only when the
/// file sort settings change.
FileSort fileSortOf(SettingsCubit cubit) {
final settings = cubit.state.fileSettings;
return (
by: settings.sortBy,
ascending: settings.ascending,
foldersToTop: settings.sortFoldersToTop,
);
}
extension FileSortListing on ListFilesResponse {
List<CacheableFile> sortedBy(FileSort sort) => sortBy(
sortOption: sort.by,
foldersToTop: sort.foldersToTop,
reversed: sort.ascending,
);
}
@@ -11,12 +11,7 @@ IconData iconForFile(CacheableFile file) {
final byMime = _iconForMime(mime);
if (byMime != null) return byMime;
}
final ext = _extensionOf(file.name);
if (ext != null) {
final byExt = _extensionIcons[ext];
if (byExt != null) return byExt;
}
return Icons.insert_drive_file_outlined;
return iconForFileName(file.name);
}
/// Icon for a bare file name (no [CacheableFile] / MIME available), e.g. in the
@@ -0,0 +1,26 @@
// Paths relative to the WebDAV root, as used by `CacheableFile.path`: no
// leading slash, folders end with '/', the root folder is ''.
final RegExp _edgeSlashes = RegExp(r'^/+|/+$');
List<String> webdavSegmentsOf(String path) {
final stripped = path.replaceAll(_edgeSlashes, '');
return stripped.isEmpty ? [] : stripped.split('/');
}
List<String> webdavParentSegmentsOf(String path) {
final segments = webdavSegmentsOf(path);
if (segments.isNotEmpty) segments.removeLast();
return segments;
}
String webdavFolderPath(List<String> segments) =>
segments.isEmpty ? '' : '${segments.join('/')}/';
String webdavJoin(String folder, String name, {required bool isDirectory}) =>
isDirectory ? '$folder$name/' : '$folder$name';
/// Folder key used by `ListFilesCache` and `FilesBloc`: no leading or
/// trailing slash, root is '/'.
String listFilesCacheKey(List<String> segments) =>
segments.isEmpty ? '/' : segments.join('/');