From 8570199196ac611605591a5c6b08749af4e45923 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 20 Jun 2022 10:54:06 -0700 Subject: [PATCH] Fix: #308 - Scroll to Contact Also fixes a bunch of debug-build issues (overflows / resizes). --- .gitignore | 7 ++++ lib/models/profile.dart | 3 +- lib/views/contactsview.dart | 70 +++++++++++++++++++++------------- lib/views/messageview.dart | 2 +- lib/widgets/quotedmessage.dart | 10 +++-- 5 files changed, 59 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index c2dfc6e5..1933e8db 100644 --- a/.gitignore +++ b/.gitignore @@ -40,10 +40,17 @@ app.*.symbols # Obfuscation related app.*.map.json +# Tor +data-dir* + + +# Compiled Libs linux/tor linux/libCwtch.so android/cwtch/cwtch.aar android/app/src/main/jniLibs/*/libtor.so +libCwtch.dylib + coverage test/failures .gradle diff --git a/lib/models/profile.dart b/lib/models/profile.dart index 4a7a59fc..9f53286a 100644 --- a/lib/models/profile.dart +++ b/lib/models/profile.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:cwtch/models/remoteserver.dart'; import 'package:flutter/widgets.dart'; +import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; import 'contact.dart'; import 'contactlist.dart'; @@ -20,7 +21,7 @@ class ProfileInfoState extends ChangeNotifier { bool _online = false; Map _downloads = Map(); Map _downloadTriggers = Map(); - + ItemScrollController contactListScrollController = new ItemScrollController(); // assume profiles are encrypted...this will be set to false // in the constructor if the profile is encrypted with the defacto password. bool _encrypted = true; diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index 379a7949..6cb975f6 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -12,6 +12,7 @@ import 'package:cwtch/widgets/profileimage.dart'; import 'package:cwtch/widgets/textfield.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; +import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; import '../main.dart'; import '../settings.dart'; import 'addcontactview.dart'; @@ -35,6 +36,8 @@ void selectConversation(BuildContext context, int handle) { Provider.of(context, listen: false).contactList.getContact(previouslySelected)!.unselected(); } Provider.of(context, listen: false).contactList.getContact(handle)!.selected(); + var contactIndex = Provider.of(context, listen: false).contactList.filteredList().indexWhere((element) => element.identifier == handle); + Provider.of(context, listen: false).contactListScrollController.scrollTo(index: contactIndex, duration: Duration(milliseconds: 500)); // triggers update in Double/TripleColumnView Provider.of(context, listen: false).initialScrollIndex = unread; Provider.of(context, listen: false).selectedConversation = handle; @@ -86,29 +89,35 @@ class _ContactsViewState extends State { endDrawerEnableOpenDragGesture: false, drawerEnableOpenDragGesture: false, appBar: AppBar( - leading: Row(children: [ - IconButton( - icon: Icon(Icons.arrow_back), - tooltip: MaterialLocalizations.of(context).backButtonTooltip, - onPressed: () { - Provider.of(context, listen: false).recountUnread(); - Provider.of(context, listen: false).selectedProfile = ""; - Navigator.of(context).pop(); - }, - ), - StreamBuilder( - stream: Provider.of(context).getUnreadProfileNotifyStream(), - builder: (BuildContext context, AsyncSnapshot unreadCountSnapshot) { - int unreadCount = Provider.of(context).generateUnreadCount(Provider.of(context).selectedProfile ?? ""); + leading: Stack(children: [ + Align( + alignment: Alignment.center, + child: IconButton( + icon: Icon(Icons.arrow_back), + tooltip: MaterialLocalizations.of(context).backButtonTooltip, + onPressed: () { + Provider.of(context, listen: false).recountUnread(); + Provider.of(context, listen: false).selectedProfile = ""; + Navigator.of(context).pop(); + }, + )), + Positioned( + bottom: 5.0, + right: 5.0, + child: StreamBuilder( + stream: Provider.of(context).getUnreadProfileNotifyStream(), + builder: (BuildContext context, AsyncSnapshot unreadCountSnapshot) { + int unreadCount = Provider.of(context).generateUnreadCount(Provider.of(context).selectedProfile ?? ""); - return Visibility( - visible: unreadCount > 0, - child: CircleAvatar( - radius: 10.0, - backgroundColor: Provider.of(context).theme.portraitProfileBadgeColor, - child: Text(unreadCount > 99 ? "99+" : unreadCount.toString(), style: TextStyle(color: Provider.of(context).theme.portraitProfileBadgeTextColor, fontSize: 8.0)), - )); - }), + return Visibility( + visible: unreadCount > 0, + child: CircleAvatar( + radius: 10.0, + backgroundColor: Provider.of(context).theme.portraitProfileBadgeColor, + child: Text(unreadCount > 99 ? "99+" : unreadCount.toString(), style: TextStyle(color: Provider.of(context).theme.portraitProfileBadgeTextColor, fontSize: 8.0)), + )); + }), + ) ]), title: RepaintBoundary( child: Row(children: [ @@ -207,11 +216,18 @@ class _ContactsViewState extends State { ); }); - final divided = ListTile.divideTiles( - context: context, - tiles: tiles, - ).toList(); - return RepaintBoundary(child: ListView(children: divided)); + var contactList = ScrollablePositionedList.separated( + itemScrollController: Provider.of(context).contactListScrollController, + itemCount: tiles.length, + itemBuilder: (context, index) { + return tiles.elementAt(index); + }, + separatorBuilder: (BuildContext context, int index) { + return Divider(height: 1); + }, + ); + + return RepaintBoundary(child: contactList); } void _pushAddContact(bool newGroup) { diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index f96296fc..21d0b501 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -233,7 +233,7 @@ class _MessageViewState extends State { ctrlrCompose.value = TextEditingValue(text: messageWithoutNewLine, selection: TextSelection.fromPosition(TextPosition(offset: messageWithoutNewLine.length))); // Do this after we trim to preserve enter-behaviour... - bool isOffline = Provider.of(context).isOnline() == false; + bool isOffline = Provider.of(context, listen: false).isOnline() == false; if (isOffline) { return; } diff --git a/lib/widgets/quotedmessage.dart b/lib/widgets/quotedmessage.dart index 220a915d..14f9be72 100644 --- a/lib/widgets/quotedmessage.dart +++ b/lib/widgets/quotedmessage.dart @@ -96,17 +96,19 @@ class QuotedMessageBubbleState extends State { margin: EdgeInsets.all(5), padding: EdgeInsets.all(5), clipBehavior: Clip.antiAlias, - decoration: BoxDecoration(), + decoration: BoxDecoration( + color: fromMe ? Provider.of(context).theme.messageFromOtherBackgroundColor : Provider.of(context).theme.messageFromMeBackgroundColor, + ), height: 75, - color: fromMe ? Provider.of(context).theme.messageFromOtherBackgroundColor : Provider.of(context).theme.messageFromMeBackgroundColor, child: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, children: [ Padding(padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0), child: Icon(Icons.reply, size: 32, color: qTextColor)), - DefaultTextStyle( + Flexible( + child: DefaultTextStyle( textWidthBasis: TextWidthBasis.parent, child: qMessage.getPreviewWidget(context), style: TextStyle(color: qTextColor), overflow: TextOverflow.fade, - ) + )) ])))); } catch (e) { print(e);