From bf31a2b06219a79789fc873e5e966688bf375772 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 29 Sep 2021 13:19:56 -0700 Subject: [PATCH] Filesharing UI Updates --- lib/cwtch/cwtchNotifier.dart | 4 +- lib/model.dart | 9 +- lib/models/messages/filemessage.dart | 9 +- lib/widgets/filebubble.dart | 185 ++++++++++++++------------- pubspec.lock | 6 +- 5 files changed, 117 insertions(+), 96 deletions(-) diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index 0a3644ae..90071154 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -182,8 +182,10 @@ class CwtchNotifier { if (contactHandle == null || contactHandle == "") contactHandle = data["GroupID"]; profileCN.getProfile(data["Identity"])?.contactList.getContact(contactHandle)!.totalMessages = int.parse(data["Data"]); break; + case "SendMessageToPeerError": + // Ignore + break; case "IndexedFailure": - EnvironmentConfig.debugLog("IndexedFailure"); var idx = data["Index"]; var key = profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(data["RemotePeer"])?.getMessageKey(idx); try { diff --git a/lib/model.dart b/lib/model.dart index f036be0f..ff781d90 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -382,10 +382,11 @@ class ProfileInfoState extends ChangeNotifier { void downloadMarkFinished(String fileKey, String finalPath) { if (!downloadActive(fileKey)) { - // happens as a result of a CheckDownloadStatus call, - // invoked from a historical (timeline) download message - // so setting numChunks correctly shouldn't matter - this.downloadInit(fileKey, 1); + print("error: received download completion notice for unknown download " + fileKey); + } else { + this._downloads[fileKey]!.timeEnd = DateTime.now(); + this._downloads[fileKey]!.complete = true; + notifyListeners(); } this._downloads[fileKey]!.timeEnd = DateTime.now(); this._downloads[fileKey]!.downloadedTo = finalPath; diff --git a/lib/models/messages/filemessage.dart b/lib/models/messages/filemessage.dart index 49b23667..fa178dd4 100644 --- a/lib/models/messages/filemessage.dart +++ b/lib/models/messages/filemessage.dart @@ -2,7 +2,6 @@ import 'dart:convert'; import 'package:cwtch/models/message.dart'; import 'package:cwtch/widgets/filebubble.dart'; -import 'package:cwtch/widgets/invitationbubble.dart'; import 'package:cwtch/widgets/malformedbubble.dart'; import 'package:cwtch/widgets/messagerow.dart'; import 'package:flutter/widgets.dart'; @@ -48,7 +47,13 @@ class FileMessage extends Message { String rootHash = shareObj['h'] as String; String nonce = shareObj['n'] as String; int fileSize = shareObj['s'] as int; - return FileBubble(nameSuggestion, rootHash, nonce, fileSize); + return FileBubble( + nameSuggestion, + rootHash, + nonce, + fileSize, + interactive: false, + ); }); } diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index 166ec164..1366c9c6 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -6,6 +6,7 @@ import 'package:cwtch/models/message.dart'; import 'package:cwtch/widgets/malformedbubble.dart'; import 'package:file_picker/file_picker.dart' as androidPicker; import 'package:file_picker_desktop/file_picker_desktop.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; @@ -24,8 +25,9 @@ class FileBubble extends StatefulWidget { final String rootHash; final String nonce; final int fileSize; + final bool interactive; - FileBubble(this.nameSuggestion, this.rootHash, this.nonce, this.fileSize); + FileBubble(this.nameSuggestion, this.rootHash, this.nonce, this.fileSize, {this.interactive = true}); @override FileBubbleState createState() => FileBubbleState(); @@ -122,15 +124,16 @@ class FileBubbleState extends State { widthFactor: 1.0, child: Padding( padding: EdgeInsets.all(9.0), - child: Wrap(runAlignment: WrapAlignment.spaceEvenly, alignment: WrapAlignment.spaceEvenly, runSpacing: 1.0, crossAxisAlignment: WrapCrossAlignment.center, children: [ - Center(widthFactor: 1, child: Padding(padding: EdgeInsets.all(10.0), child: Icon(Icons.attach_file, size: 32))), + child: Wrap(alignment: WrapAlignment.start, children: [ Center( widthFactor: 1.0, child: Column( crossAxisAlignment: fromMe ? CrossAxisAlignment.end : CrossAxisAlignment.start, mainAxisAlignment: fromMe ? MainAxisAlignment.end : MainAxisAlignment.start, mainAxisSize: MainAxisSize.min, - children: fromMe ? [wdgMessage, wdgDecorations] : [wdgSender, wdgMessage, wdgDecorations]), + children: fromMe + ? [wdgMessage, Visibility(visible: widget.interactive, child: wdgDecorations)] + : [wdgSender, wdgMessage, Visibility(visible: widget.interactive, child: wdgDecorations)]), ) ]))))); }); @@ -171,99 +174,109 @@ class FileBubbleState extends State { // Construct an invite chrome for the sender Widget senderFileChrome(String chrome, String fileName, String rootHash, int fileSize) { - return Wrap(direction: Axis.vertical, children: [ - SelectableText( - chrome + '\u202F', - style: TextStyle( - color: Provider.of(context).theme.messageFromMeTextColor(), + return ListTile( + visualDensity: VisualDensity.compact, + title: Wrap(direction: Axis.horizontal, alignment: WrapAlignment.start, children: [ + SelectableText( + chrome + '\u202F', + style: TextStyle( + color: Provider.of(context).theme.messageFromMeTextColor(), + ), + textAlign: TextAlign.left, + maxLines: 2, + textWidthBasis: TextWidthBasis.longestLine, + ), + SelectableText( + fileName + '\u202F', + style: TextStyle( + color: Provider.of(context).theme.messageFromMeTextColor(), + fontWeight: FontWeight.bold, + overflow: TextOverflow.ellipsis, + ), + textAlign: TextAlign.left, + textWidthBasis: TextWidthBasis.parent, + maxLines: 2, + ), + SelectableText( + prettyBytes(fileSize) + '\u202F' + '\n', + style: TextStyle( + color: Provider.of(context).theme.messageFromMeTextColor(), + ), + textAlign: TextAlign.left, + maxLines: 2, + ) + ]), + subtitle: SelectableText( + 'sha512: ' + rootHash + '\u202F', + style: TextStyle( + color: Provider.of(context).theme.messageFromMeTextColor(), + fontSize: 10, + fontFamily: "monospace", + ), + textAlign: TextAlign.left, + maxLines: 4, + textWidthBasis: TextWidthBasis.parent, ), - textAlign: TextAlign.left, - maxLines: 2, - textWidthBasis: TextWidthBasis.longestLine, - ), - SelectableText( - fileName + '\u202F', - style: TextStyle( - color: Provider.of(context).theme.messageFromMeTextColor(), - ), - textAlign: TextAlign.left, - maxLines: 2, - textWidthBasis: TextWidthBasis.longestLine, - ), - SelectableText( - prettyBytes(fileSize) + '\u202F', - style: TextStyle( - color: Provider.of(context).theme.messageFromMeTextColor(), - ), - textAlign: TextAlign.left, - maxLines: 2, - textWidthBasis: TextWidthBasis.longestLine, - ), - SelectableText( - 'sha512: ' + rootHash + '\u202F', - style: TextStyle( - color: Provider.of(context).theme.messageFromMeTextColor(), - ), - textAlign: TextAlign.left, - maxLines: 2, - textWidthBasis: TextWidthBasis.longestLine, - ), - ]); + leading: Icon(Icons.attach_file, size: 32, color: Provider.of(context).theme.messageFromMeTextColor())); } // Construct an invite chrome Widget fileChrome(String chrome, String fileName, String rootHash, int fileSize, String speed) { - var prettyHash = rootHash; - if (rootHash.length == 128) { - prettyHash = rootHash.substring(0, 32) + '\n' + rootHash.substring(32, 64) + '\n' + rootHash.substring(64, 96) + '\n' + rootHash.substring(96); - } - - return Wrap(direction: Axis.vertical, children: [ - SelectableText( - chrome + '\u202F', - style: TextStyle( - color: Provider.of(context).theme.messageFromOtherTextColor(), + return ListTile( + visualDensity: VisualDensity.compact, + title: Wrap(direction: Axis.horizontal, alignment: WrapAlignment.start, children: [ + SelectableText( + chrome + '\u202F', + style: TextStyle( + color: Provider.of(context).theme.messageFromOtherTextColor(), + ), + textAlign: TextAlign.left, + maxLines: 2, + textWidthBasis: TextWidthBasis.longestLine, ), - textAlign: TextAlign.left, - textWidthBasis: TextWidthBasis.longestLine, - maxLines: 2, - ), - SelectableText( - AppLocalizations.of(context)!.labelFilename + ': ' + fileName + '\u202F', - style: TextStyle( - color: Provider.of(context).theme.messageFromMeTextColor(), - ), - textAlign: TextAlign.left, - maxLines: 2, - textWidthBasis: TextWidthBasis.longestLine, - ), - SelectableText( - AppLocalizations.of(context)!.labelFilesize + ': ' + prettyBytes(fileSize) + '\u202F', - style: TextStyle( - color: Provider.of(context).theme.messageFromMeTextColor(), - ), - textAlign: TextAlign.left, - maxLines: 2, - textWidthBasis: TextWidthBasis.longestLine, - ), - SelectableText( - 'sha512: ' + prettyHash + '\u202F', + SelectableText( + fileName + '\u202F', + style: TextStyle( + color: Provider.of(context).theme.messageFromOtherTextColor(), + fontWeight: FontWeight.bold, + overflow: TextOverflow.ellipsis, + ), + textAlign: TextAlign.left, + textWidthBasis: TextWidthBasis.parent, + maxLines: 2, + ), + SelectableText( + AppLocalizations.of(context)!.labelFilesize + ': ' + prettyBytes(fileSize) + '\u202F' + '\n', + style: TextStyle( + color: Provider.of(context).theme.messageFromOtherTextColor(), + ), + textAlign: TextAlign.left, + maxLines: 2, + ) + ]), + subtitle: SelectableText( + 'sha512: ' + rootHash + '\u202F', style: TextStyle( color: Provider.of(context).theme.messageFromMeTextColor(), + fontSize: 10, + fontFamily: "monospace", ), textAlign: TextAlign.left, maxLines: 4, - textWidthBasis: TextWidthBasis.longestLine, + textWidthBasis: TextWidthBasis.parent, ), - SelectableText( - speed + '\u202F', - style: TextStyle( - color: Provider.of(context).theme.messageFromMeTextColor(), - ), - textAlign: TextAlign.left, - maxLines: 1, - textWidthBasis: TextWidthBasis.longestLine, - ), - ]); + leading: Icon(Icons.attach_file, size: 32, color: Provider.of(context).theme.messageFromOtherTextColor()), + trailing: Visibility( + visible: speed != "0 B/s", + child: SelectableText( + speed + '\u202F', + style: TextStyle( + color: Provider.of(context).theme.messageFromMeTextColor(), + ), + textAlign: TextAlign.left, + maxLines: 1, + textWidthBasis: TextWidthBasis.longestLine, + )), + ); } } diff --git a/pubspec.lock b/pubspec.lock index 41cdef38..ca0185ec 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -21,7 +21,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.8.1" boolean_selector: dependency: transitive description: @@ -195,7 +195,7 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.10" meta: dependency: transitive description: @@ -403,7 +403,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.3" + version: "0.4.2" typed_data: dependency: transitive description: