Browse Source

add caption as hint text in caption textField

ashilkn 2 years ago
parent
commit
a5c7f82019

+ 8 - 0
lib/models/file.dart

@@ -233,6 +233,14 @@ class File extends EnteFile {
     return title ?? '';
   }
 
+  String get caption {
+    if (pubMagicMetadata != null && pubMagicMetadata!.caption != null) {
+      return pubMagicMetadata!.caption!;
+    } else {
+      return '';
+    }
+  }
+
   // returns true if the file isn't available in the user's gallery
   bool get isRemoteFile {
     return localID == null && uploadedFileID != null;

+ 3 - 1
lib/models/magic_metadata.dart

@@ -33,8 +33,9 @@ class MagicMetadata {
 class PubMagicMetadata {
   int? editedTime;
   String? editedName;
+  String? caption;
 
-  PubMagicMetadata({this.editedTime, this.editedName});
+  PubMagicMetadata({this.editedTime, this.editedName, this.caption});
 
   factory PubMagicMetadata.fromEncodedJson(String encodedJson) =>
       PubMagicMetadata.fromJson(jsonDecode(encodedJson));
@@ -47,6 +48,7 @@ class PubMagicMetadata {
     return PubMagicMetadata(
       editedTime: map[pubMagicKeyEditedTime],
       editedName: map[pubMagicKeyEditedName],
+      caption: map[pubMagicKeyCaption],
     );
   }
 }

+ 7 - 7
lib/ui/viewer/file/file_caption_widget.dart

@@ -4,9 +4,8 @@ import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/utils/magic_util.dart';
 
 class FileCaptionWidget extends StatefulWidget {
-  final String hintText;
   final File file;
-  const FileCaptionWidget({required this.file, this.hintText = '', super.key});
+  const FileCaptionWidget({required this.file, super.key});
 
   @override
   State<FileCaptionWidget> createState() => _FileCaptionWidgetState();
@@ -17,7 +16,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
   int currentLength = 0;
   final _textController = TextEditingController();
   final _focusNode = FocusNode();
-  String caption = "";
+  String editedCaption = "";
 
   @override
   void dispose() {
@@ -30,6 +29,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
   Widget build(BuildContext context) {
     final colorScheme = getEnteColorScheme(context);
     final textTheme = getEnteTextTheme(context);
+    final caption = widget.file.caption;
     return TextField(
       onEditingComplete: () {
         editCaption();
@@ -47,7 +47,7 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
         focusedBorder: InputBorder.none,
         filled: true,
         fillColor: colorScheme.fillFaint,
-        hintText: widget.hintText,
+        hintText: caption.isEmpty ? "Add a caption" : caption,
         hintStyle: getEnteTextTheme(context)
             .small
             .copyWith(color: colorScheme.textMuted),
@@ -61,15 +61,15 @@ class _FileCaptionWidgetState extends State<FileCaptionWidget> {
       onChanged: (value) {
         setState(() {
           currentLength = value.length;
-          caption = value;
+          editedCaption = value;
         });
       },
     );
   }
 
   void editCaption({bool fromDispose = false}) {
-    if (caption.isNotEmpty) {
-      editFileCaption(fromDispose ? null : context, widget.file, caption);
+    if (editedCaption.isNotEmpty) {
+      editFileCaption(fromDispose ? null : context, widget.file, editedCaption);
     }
   }
 }