Pārlūkot izejas kodu

Show fileCaption for incoming files

Neeraj Gupta 2 gadi atpakaļ
vecāks
revīzija
aa1cf5b167

+ 41 - 0
lib/ui/viewer/file/file_caption_widget.dart

@@ -6,8 +6,48 @@ import 'package:photos/ui/components/keyboard/keybiard_oveylay.dart';
 import 'package:photos/ui/components/keyboard/keyboard_top_button.dart';
 import 'package:photos/utils/magic_util.dart';
 
+class FileCaptionReadyOnly extends StatelessWidget {
+  final String caption;
+
+  const FileCaptionReadyOnly({super.key, required this.caption});
+
+  @override
+  Widget build(BuildContext context) {
+    final colorScheme = getEnteColorScheme(context);
+    final textTheme = getEnteTextTheme(context);
+    return Padding(
+      padding: const EdgeInsets.all(4.0),
+      child: ConstrainedBox(
+        constraints: const BoxConstraints(
+          minHeight: 32.0,
+          minWidth: double.infinity,
+          maxHeight: 200.0,
+          maxWidth: double.infinity,
+        ),
+        child: DecoratedBox(
+          decoration: BoxDecoration(
+            color: colorScheme.fillFaint,
+            borderRadius: BorderRadius.circular(4),
+          ),
+          child: SingleChildScrollView(
+            scrollDirection: Axis.vertical,
+            child: Padding(
+              padding: const EdgeInsets.all(12.0),
+              child: Text(
+                caption,
+                style: textTheme.small,
+              ),
+            ),
+          ),
+        ),
+      ),
+    );
+  }
+}
+
 class FileCaptionWidget extends StatefulWidget {
   final File file;
+
   const FileCaptionWidget({required this.file, super.key});
 
   @override
@@ -16,6 +56,7 @@ class FileCaptionWidget extends StatefulWidget {
 
 class _FileCaptionWidgetState extends State<FileCaptionWidget> {
   static const int maxLength = 5000;
+
   // counterThreshold represents the nun of char after which
   // currentLength/maxLength will show up
   static const int counterThreshold = 1000;

+ 7 - 2
lib/ui/viewer/file/file_info_widget.dart

@@ -74,6 +74,8 @@ class _FileInfoWidgetState extends State<FileInfoWidget> {
   Widget build(BuildContext context) {
     final file = widget.file;
     final fileIsBackedup = file.uploadedFileID == null ? false : true;
+    final bool isFileOwner =
+        file.ownerID == null || file.ownerID == _currentUserID;
     Future<Set<int>> allCollectionIDsOfFile;
     Future<Set<String>>
         allDeviceFoldersOfFile; //Typing this as Future<Set<T>> as it would be easier to implement showing multiple device folders for a file in the future
@@ -99,11 +101,14 @@ class _FileInfoWidgetState extends State<FileInfoWidget> {
     final bool showDimension =
         _exifData["resolution"] != null && _exifData["megaPixels"] != null;
     final listTiles = <Widget>[
-      widget.file.uploadedFileID == null || _currentUserID != file.ownerID
+      !widget.file.isUploaded ||
+              (!isFileOwner && (widget.file.caption?.isEmpty ?? true))
           ? const SizedBox.shrink()
           : Padding(
               padding: const EdgeInsets.only(top: 8, bottom: 4),
-              child: FileCaptionWidget(file: widget.file),
+              child: isFileOwner
+                  ? FileCaptionWidget(file: widget.file)
+                  : FileCaptionReadyOnly(caption: widget.file.caption),
             ),
       ListTile(
         horizontalTitleGap: 2,