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
+5 -17
View File
@@ -19,6 +19,7 @@ import '../../../../widget/details_bottom_sheet.dart';
import '../../../../widget/downloads/download_trigger.dart';
import '../../../../widget/prompt_dialog.dart';
import '../../talk/widgets/highlighted_linkify.dart';
import '../data/webdav_path.dart';
import '../sharing/share_sheet.dart';
import 'file_details_sheet.dart';
import 'file_leading.dart';
@@ -26,7 +27,7 @@ import 'file_leading.dart';
class FileElement extends StatefulWidget {
final CacheableFile file;
final List<String> path;
final void Function() refetch;
final VoidCallback refetch;
/// When non-null, occurrences of this string in the file name are visually
/// highlighted in the tile title. Used by the Files search delegate.
@@ -101,7 +102,7 @@ class _FileElementState extends State<FileElement>
if (widget.file.isDirectory) {
AppRoutes.openFolder(
context,
widget.path.toList()..add(widget.file.name),
[...widget.path, widget.file.name],
);
return;
}
@@ -116,18 +117,6 @@ class _FileElementState extends State<FileElement>
);
}
// All paths here are relative to the WebDAV root (matching CacheableFile.path).
// Root parent is the empty string ''. Folders end with '/'.
String _parentPathOf(String path) {
final stripped = path.replaceAll(RegExp(r'^/+|/+$'), '');
if (!stripped.contains('/')) return '';
final parts = stripped.split('/')..removeLast();
return parts.isEmpty ? '' : '${parts.join('/')}/';
}
String _joinPath(String folder, String name, {required bool isDirectory}) =>
isDirectory ? '$folder$name/' : '$folder$name';
void _rename() {
if (guardDemoAction(context)) return;
showPromptDialog(
@@ -138,9 +127,8 @@ class _FileElementState extends State<FileElement>
initialValue: widget.file.name,
onConfirm: (newName) async {
if (newName.isEmpty || newName == widget.file.name) return;
final parent = _parentPathOf(widget.file.path);
final destination = _joinPath(
parent,
final destination = webdavJoin(
webdavFolderPath(webdavParentSegmentsOf(widget.file.path)),
newName,
isDirectory: widget.file.isDirectory,
);