|
@@ -1,10 +1,13 @@
|
|
|
|
+import 'package:flutter/material.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:logging/logging.dart';
|
|
import 'package:logging/logging.dart';
|
|
|
|
+import 'package:path/path.dart';
|
|
import 'package:photos/core/event_bus.dart';
|
|
import 'package:photos/core/event_bus.dart';
|
|
import 'package:photos/events/force_reload_home_gallery_event.dart';
|
|
import 'package:photos/events/force_reload_home_gallery_event.dart';
|
|
import 'package:photos/models/file.dart';
|
|
import 'package:photos/models/file.dart';
|
|
import 'package:photos/models/magic_metadata.dart';
|
|
import 'package:photos/models/magic_metadata.dart';
|
|
import 'package:photos/services/file_magic_service.dart';
|
|
import 'package:photos/services/file_magic_service.dart';
|
|
|
|
+import 'package:photos/ui/rename_dialog.dart';
|
|
import 'package:photos/utils/dialog_util.dart';
|
|
import 'package:photos/utils/dialog_util.dart';
|
|
import 'package:photos/utils/toast_util.dart';
|
|
import 'package:photos/utils/toast_util.dart';
|
|
|
|
|
|
@@ -41,6 +44,35 @@ Future<bool> editTime(
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+Future<bool> editFilename(
|
|
|
|
+ BuildContext context,
|
|
|
|
+ File file,
|
|
|
|
+) async {
|
|
|
|
+ try {
|
|
|
|
+ final fileName = file.getDisplayName();
|
|
|
|
+ final nameWithoutExt = basenameWithoutExtension(fileName);
|
|
|
|
+ final extName = extension(fileName);
|
|
|
|
+ var result = await showDialog<String>(
|
|
|
|
+ context: context,
|
|
|
|
+ builder: (BuildContext context) {
|
|
|
|
+ return RenameDialog(nameWithoutExt, 'file', maxLength: 50);
|
|
|
|
+ },
|
|
|
|
+ barrierColor: Colors.black.withOpacity(0.85),
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (result == null || result.trim() == nameWithoutExt.trim()) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ result = result + extName;
|
|
|
|
+ await _updatePublicMetadata(
|
|
|
|
+ context, List.of([file]), kPubMagicKeyEditedName, result);
|
|
|
|
+ return true;
|
|
|
|
+ } catch (e, s) {
|
|
|
|
+ showToast('something went wrong');
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
Future<void> _updatePublicMetadata(
|
|
Future<void> _updatePublicMetadata(
|
|
BuildContext context, List<File> files, String key, dynamic value) async {
|
|
BuildContext context, List<File> files, String key, dynamic value) async {
|
|
if (files.isEmpty) {
|
|
if (files.isEmpty) {
|