Line data Source code
1 : import 'dart:io';
2 :
3 : import 'package:cwtch/cwtch/cwtch.dart';
4 : import 'package:cwtch/cwtch_icons_icons.dart';
5 : import 'package:cwtch/models/appstate.dart';
6 : import 'package:cwtch/models/contact.dart';
7 : import 'package:cwtch/models/contactlist.dart';
8 : import 'package:cwtch/models/profile.dart';
9 : import 'package:cwtch/models/profilelist.dart';
10 : import 'package:cwtch/models/search.dart';
11 : import 'package:cwtch/views/globalsettingsview.dart';
12 : import 'package:cwtch/views/profileserversview.dart';
13 : import 'package:flutter/material.dart';
14 : import 'package:cwtch/widgets/contactrow.dart';
15 : import 'package:cwtch/widgets/profileimage.dart';
16 : import 'package:cwtch/widgets/textfield.dart';
17 : import 'package:flutter/services.dart';
18 : import 'package:provider/provider.dart';
19 : import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
20 : import '../config.dart';
21 : import '../main.dart';
22 : import '../models/redaction.dart';
23 : import '../settings.dart';
24 : import '../themes/opaque.dart';
25 : import 'addcontactview.dart';
26 : import 'package:cwtch/l10n/app_localizations.dart';
27 : import 'package:qr_flutter/qr_flutter.dart';
28 :
29 : import 'addeditprofileview.dart';
30 : import 'messageview.dart';
31 :
32 : enum ShareMenu { copyCode, qrcode }
33 :
34 : enum ProfileStatusMenu { available, away, busy, appearOnline, appearOffline, allowUnknownContacts, blockUnknownContacts, enableProfile, disableProfile, editProfile }
35 :
36 : class ContactsView extends StatefulWidget {
37 0 : const ContactsView({Key? key}) : super(key: key);
38 :
39 0 : @override
40 0 : _ContactsViewState createState() => _ContactsViewState();
41 : }
42 :
43 : // selectConversation can be called from anywhere to set the active conversation
44 0 : void selectConversation(BuildContext context, int handle, int? messageIndex) {
45 : int? index;
46 :
47 : if (messageIndex != null) {
48 : // this message is loaded
49 0 : Provider.of<SearchState>(context, listen: false).selectedSearchMessage = messageIndex;
50 0 : Provider.of<AppState>(context, listen: false).initialScrollIndex = messageIndex;
51 0 : EnvironmentConfig.debugLog("Looked up index $messageIndex");
52 : }
53 :
54 0 : if (handle == Provider.of<AppState>(context, listen: false).selectedConversation) {
55 : if (messageIndex != null) {
56 0 : Provider.of<ContactInfoState>(context, listen: false).messageScrollController.scrollTo(index: messageIndex, duration: Duration(milliseconds: 100));
57 : }
58 : return;
59 : }
60 :
61 : // requery instead of using contactinfostate directly because sometimes listview gets confused about data that resorts
62 0 : var unread = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(handle)!.unreadMessages;
63 0 : var previouslySelected = Provider.of<AppState>(context, listen: false).selectedConversation;
64 : if (previouslySelected != null) {
65 0 : Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(previouslySelected)!.unselected();
66 : }
67 0 : Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(handle)!.selected();
68 :
69 : // triggers update in Double/TripleColumnView
70 0 : Provider.of<ContactInfoState>(context, listen: false).hoveredIndex = -1;
71 0 : Provider.of<AppState>(context, listen: false).selectedConversation = handle;
72 :
73 : // if in singlepane mode, push to the stack
74 0 : var isLandscape = Provider.of<AppState>(context, listen: false).isLandscape(context);
75 0 : if (Provider.of<Settings>(context, listen: false).uiColumns(isLandscape).length == 1) _pushMessageView(context, handle);
76 :
77 : // Set last message seen time in backend
78 0 : Provider.of<FlwtchState>(
79 : context,
80 : listen: false,
81 0 : ).cwtch.SetConversationAttribute(Provider.of<ProfileInfoState>(context, listen: false).onion, handle, LastMessageSeenTimeKey, DateTime.now().toUtc().toIso8601String());
82 : }
83 :
84 0 : void _pushMessageView(BuildContext context, int handle) {
85 0 : var profileOnion = Provider.of<ProfileInfoState>(context, listen: false).onion;
86 :
87 0 : Navigator.of(context).push(
88 0 : PageRouteBuilder(
89 0 : settings: RouteSettings(name: "messages"),
90 0 : pageBuilder: (builderContext, a1, a2) {
91 0 : var profile = Provider.of<FlwtchState>(builderContext).profs.getProfile(profileOnion)!;
92 0 : return MultiProvider(
93 0 : providers: [
94 0 : ChangeNotifierProvider.value(value: profile),
95 0 : ChangeNotifierProvider.value(value: profile.contactList.getContact(handle)!),
96 0 : ChangeNotifierProvider.value(value: profile.searchState),
97 : ],
98 0 : builder: (context, child) => MessageView(),
99 : );
100 : },
101 0 : transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
102 0 : transitionDuration: Duration(milliseconds: 200),
103 : ),
104 : );
105 : }
106 :
107 : class _ContactsViewState extends State<ContactsView> {
108 : late TextEditingController ctrlrFilter;
109 : final scaffoldKey = GlobalKey<ScaffoldMessengerState>();
110 :
111 0 : @override
112 : void initState() {
113 0 : super.initState();
114 0 : ctrlrFilter = new TextEditingController(text: Provider.of<SearchState>(context, listen: false).filter);
115 : }
116 :
117 0 : @override
118 : Widget build(BuildContext context) {
119 0 : var enabled = Provider.of<ProfileInfoState>(context, listen: false).enabled;
120 0 : var appearOffline = Provider.of<ProfileInfoState>(context, listen: false).appearOffline;
121 0 : var settings = Provider.of<Settings>(context, listen: false);
122 0 : if (!Provider.of<SearchState>(context).searchActive) {
123 0 : ctrlrFilter.text = "";
124 : }
125 0 : return ScaffoldMessenger(
126 0 : key: scaffoldKey,
127 0 : child: Scaffold(
128 0 : backgroundColor: Provider.of<Settings>(context).theme.backgroundMainColor,
129 : endDrawerEnableOpenDragGesture: false,
130 : drawerEnableOpenDragGesture: false,
131 0 : appBar: AppBar(
132 0 : leading: Stack(
133 0 : children: [
134 0 : Align(
135 : alignment: Alignment.center,
136 0 : child: IconButton(
137 0 : icon: Icon(Icons.arrow_back),
138 0 : tooltip: MaterialLocalizations.of(context).backButtonTooltip,
139 0 : onPressed: () {
140 0 : if (Provider.of<SearchState>(context, listen: false).searchActive) {
141 0 : Provider.of<SearchState>(context, listen: false).clearSearch();
142 : } else {
143 0 : Provider.of<ProfileInfoState>(context, listen: false).recountUnread();
144 0 : Provider.of<AppState>(context, listen: false).selectedProfile = "";
145 0 : Navigator.of(context).pop();
146 : }
147 : },
148 : ),
149 : ),
150 0 : Positioned(
151 : bottom: 5.0,
152 : right: 5.0,
153 0 : child: StreamBuilder<bool>(
154 0 : stream: Provider.of<AppState>(context).getUnreadProfileNotifyStream(),
155 0 : builder: (BuildContext context, AsyncSnapshot<bool> unreadCountSnapshot) {
156 0 : int unreadCount = Provider.of<ProfileListState>(context).generateUnreadCount(Provider.of<AppState>(context).selectedProfile ?? "");
157 :
158 0 : return Visibility(
159 0 : visible: unreadCount > 0,
160 0 : child: CircleAvatar(
161 : radius: 10.0,
162 0 : backgroundColor: Provider.of<Settings>(context).theme.portraitProfileBadgeColor,
163 0 : child: Text(unreadCount > 99 ? "99+" : unreadCount.toString(), style: TextStyle(color: Provider.of<Settings>(context).theme.portraitProfileBadgeTextColor, fontSize: 8.0)),
164 : ),
165 : );
166 : },
167 : ),
168 : ),
169 : ],
170 : ),
171 0 : title: Row(
172 0 : children: [
173 0 : PopupMenuButton<ProfileStatusMenu>(
174 0 : icon: ProfileImage(
175 0 : imagePath: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment)
176 0 : ? Provider.of<ProfileInfoState>(context).imagePath
177 0 : : Provider.of<ProfileInfoState>(context).defaultImagePath,
178 : diameter: 42,
179 0 : border: Provider.of<ProfileInfoState>(context).getBorderColor(Provider.of<Settings>(context).theme),
180 : badgeTextColor: Colors.red,
181 : badgeColor: Colors.red,
182 : ),
183 : iconSize: 42,
184 0 : tooltip: AppLocalizations.of(context)!.availabilityStatusTooltip,
185 0 : splashRadius: Material.defaultSplashRadius / 2,
186 0 : onSelected: (ProfileStatusMenu item) {
187 0 : String onion = Provider.of<ProfileInfoState>(context, listen: false).onion;
188 : switch (item) {
189 0 : case ProfileStatusMenu.available:
190 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.SetProfileAttribute(onion, "profile.profile-status", "available");
191 : break;
192 0 : case ProfileStatusMenu.away:
193 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.SetProfileAttribute(onion, "profile.profile-status", "away");
194 : break;
195 0 : case ProfileStatusMenu.busy:
196 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.SetProfileAttribute(onion, "profile.profile-status", "busy");
197 : break;
198 0 : case ProfileStatusMenu.appearOffline:
199 0 : Provider.of<ProfileInfoState>(context, listen: false).appearOffline = true;
200 0 : Provider.of<ProfileInfoState>(context, listen: false).deactivatePeerEngine(context);
201 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, false, false, false);
202 : break;
203 0 : case ProfileStatusMenu.editProfile:
204 0 : Navigator.of(context).push(
205 0 : PageRouteBuilder(
206 0 : pageBuilder: (bcontext, a1, a2) {
207 0 : return MultiProvider(
208 0 : providers: [ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context, listen: false))],
209 0 : builder: (context, widget) => AddEditProfileView(key: Key('addprofile')),
210 : );
211 : },
212 0 : transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
213 0 : transitionDuration: Duration(milliseconds: 200),
214 : ),
215 : );
216 : break;
217 0 : case ProfileStatusMenu.appearOnline:
218 0 : Provider.of<ProfileInfoState>(context, listen: false).appearOffline = false;
219 : // we only need to toggle all connections on here..
220 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, true, true, true);
221 : break;
222 0 : case ProfileStatusMenu.allowUnknownContacts:
223 0 : settings.blockUnknownConnections = false;
224 0 : saveSettings(context);
225 : break;
226 0 : case ProfileStatusMenu.blockUnknownContacts:
227 0 : settings.blockUnknownConnections = true;
228 0 : saveSettings(context);
229 : break;
230 0 : case ProfileStatusMenu.enableProfile:
231 0 : Provider.of<ProfileInfoState>(context, listen: false).enabled = true;
232 0 : if (Provider.of<ProfileInfoState>(context, listen: false).appearOffline) {
233 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, false, false, false);
234 : } else {
235 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, true, true, true);
236 : }
237 : break;
238 0 : case ProfileStatusMenu.disableProfile:
239 0 : Provider.of<ProfileInfoState>(context, listen: false).enabled = false;
240 0 : Provider.of<ProfileInfoState>(context, listen: false).deactivatePeerEngine(context);
241 : break;
242 : }
243 : },
244 0 : itemBuilder: (BuildContext context) => <PopupMenuEntry<ProfileStatusMenu>>[
245 0 : PopupMenuItem<ProfileStatusMenu>(
246 : value: ProfileStatusMenu.available,
247 : enabled: enabled,
248 0 : child: Row(
249 0 : children: [
250 0 : Icon(CwtchIcons.account_circle_24px, color: Colors.white),
251 0 : Expanded(
252 0 : child: Text(
253 0 : AppLocalizations.of(context)!.availabilityStatusAvailable,
254 : textAlign: TextAlign.right,
255 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
256 : ),
257 : ),
258 : ],
259 : ),
260 : ),
261 0 : PopupMenuItem<ProfileStatusMenu>(
262 : value: ProfileStatusMenu.away,
263 : enabled: enabled,
264 0 : child: Row(
265 0 : children: [
266 0 : Icon(CwtchIcons.account_circle_24px, color: Colors.yellowAccent),
267 0 : Expanded(
268 0 : child: Text(
269 0 : AppLocalizations.of(context)!.availabilityStatusAway,
270 : textAlign: TextAlign.right,
271 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
272 : ),
273 : ),
274 : ],
275 : ),
276 : ),
277 0 : PopupMenuItem<ProfileStatusMenu>(
278 : value: ProfileStatusMenu.busy,
279 : enabled: enabled,
280 0 : child: Row(
281 0 : children: [
282 0 : Icon(CwtchIcons.account_circle_24px, color: Colors.redAccent),
283 0 : Expanded(
284 0 : child: Text(
285 0 : AppLocalizations.of(context)!.availabilityStatusBusy,
286 : textAlign: TextAlign.right,
287 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
288 : ),
289 : ),
290 : ],
291 : ),
292 : ),
293 0 : PopupMenuDivider(),
294 0 : PopupMenuItem<ProfileStatusMenu>(
295 : value: ProfileStatusMenu.appearOffline,
296 : enabled: enabled && !appearOffline,
297 0 : child: Row(
298 0 : children: [
299 0 : Icon(CwtchIcons.disconnect_from_contact),
300 0 : Expanded(
301 0 : child: Text(
302 0 : AppLocalizations.of(context)!.profileAppearOffline,
303 : textAlign: TextAlign.right,
304 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
305 : ),
306 : ),
307 : ],
308 : ),
309 : ),
310 0 : PopupMenuItem<ProfileStatusMenu>(
311 : value: ProfileStatusMenu.appearOnline,
312 : enabled: enabled && appearOffline,
313 0 : child: Row(
314 0 : children: [
315 0 : Icon(CwtchIcons.disconnect_from_contact),
316 0 : Expanded(
317 0 : child: Text(
318 0 : AppLocalizations.of(context)!.profileAppearOnline,
319 : textAlign: TextAlign.right,
320 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
321 : ),
322 : ),
323 : ],
324 : ),
325 : ),
326 0 : PopupMenuDivider(),
327 0 : PopupMenuItem<ProfileStatusMenu>(
328 0 : value: !settings.blockUnknownConnections ? ProfileStatusMenu.blockUnknownContacts : ProfileStatusMenu.allowUnknownContacts,
329 0 : child: Row(
330 0 : children: [
331 0 : Icon(CwtchIcons.block_unknown, color: settings.theme.mainTextColor),
332 0 : Expanded(
333 0 : child: Text(
334 0 : (settings.blockUnknownConnections ? AppLocalizations.of(context)!.profileAllowUnknownContacts : AppLocalizations.of(context)!.profileBlockUnknownContacts),
335 : textAlign: TextAlign.right,
336 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
337 : ),
338 : ),
339 : ],
340 : ),
341 : ),
342 0 : PopupMenuDivider(),
343 0 : PopupMenuItem<ProfileStatusMenu>(
344 : value: enabled ? ProfileStatusMenu.disableProfile : ProfileStatusMenu.enableProfile,
345 0 : child: Row(
346 0 : children: [
347 0 : Icon(CwtchIcons.favorite_24dp, color: settings.theme.mainTextColor),
348 0 : Expanded(
349 0 : child: Text(
350 0 : (enabled ? AppLocalizations.of(context)!.profileDisableProfile : AppLocalizations.of(context)!.profileEnableProfile),
351 : textAlign: TextAlign.right,
352 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
353 : ),
354 : ),
355 : ],
356 : ),
357 : ),
358 0 : PopupMenuItem<ProfileStatusMenu>(
359 : value: ProfileStatusMenu.editProfile,
360 : enabled: true,
361 0 : child: Row(
362 0 : children: [
363 0 : Icon(CwtchIcons.edit_24px, color: settings.theme.mainTextColor),
364 0 : Expanded(
365 0 : child: Text(AppLocalizations.of(context)!.editProfile, textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
366 : ),
367 : ],
368 : ),
369 : ),
370 : ],
371 : ),
372 0 : SizedBox(width: 10),
373 0 : Expanded(
374 0 : child: Text(
375 : "%1 ยป %2"
376 0 : .replaceAll("%1", redactedNick(context, Provider.of<ProfileInfoState>(context).onion, Provider.of<ProfileInfoState>(context).nickname))
377 0 : .replaceAll("%2", AppLocalizations.of(context)!.titleManageContacts),
378 : overflow: TextOverflow.ellipsis,
379 0 : style: TextStyle(
380 0 : color: Provider.of<Settings>(context).current().mainTextColor,
381 : fontFamily: "Inter",
382 : fontWeight: FontWeight.bold,
383 0 : fontSize: 14.0 * Provider.of<Settings>(context).fontScaling,
384 : ),
385 : ),
386 : ),
387 : ],
388 : ),
389 0 : actions: getActions(context),
390 : ),
391 0 : floatingActionButton: FloatingActionButton(
392 0 : onPressed: _modalAddImportChoice,
393 0 : tooltip: AppLocalizations.of(context)!.tooltipAddContact,
394 0 : child: Icon(CwtchIcons.person_add_alt_1_24px, color: Provider.of<Settings>(context).theme.defaultButtonTextColor),
395 : ),
396 0 : body: Provider.of<SearchState>(context).searchOrFiltered ? _buildFilterable() : _buildContactList(),
397 : ),
398 : );
399 : }
400 :
401 0 : List<Widget> getActions(context) {
402 0 : var actions = List<Widget>.empty(growable: true);
403 0 : if (Provider.of<Settings>(context).blockUnknownConnections) {
404 0 : actions.add(Tooltip(message: AppLocalizations.of(context)!.blockUnknownConnectionsEnabledDescription, child: Icon(CwtchIcons.block_unknown)));
405 : }
406 :
407 0 : if (Provider.of<Settings>(context, listen: false).isExperimentEnabled(QRCodeExperiment)) {
408 0 : actions.add(
409 0 : PopupMenuButton<ShareMenu>(
410 0 : icon: Icon(CwtchIcons.address_copy),
411 0 : tooltip: AppLocalizations.of(context)!.shareProfileMenuTooltop,
412 0 : splashRadius: Material.defaultSplashRadius / 2,
413 0 : onSelected: (ShareMenu item) {
414 : switch (item) {
415 0 : case ShareMenu.copyCode:
416 : {
417 0 : Clipboard.setData(new ClipboardData(text: Provider.of<ProfileInfoState>(context, listen: false).onion));
418 0 : final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.copiedToClipboardNotification));
419 0 : scaffoldKey.currentState?.showSnackBar(snackBar);
420 : }
421 : break;
422 0 : case ShareMenu.qrcode:
423 : {
424 0 : _showQRCode("cwtch:" + Provider.of<ProfileInfoState>(context, listen: false).onion);
425 : }
426 : break;
427 : }
428 : },
429 0 : itemBuilder: (BuildContext context) => <PopupMenuEntry<ShareMenu>>[
430 0 : PopupMenuItem<ShareMenu>(
431 : value: ShareMenu.copyCode,
432 0 : child: Text(AppLocalizations.of(context)!.copyAddress, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
433 : ),
434 0 : PopupMenuItem<ShareMenu>(
435 : value: ShareMenu.qrcode,
436 0 : child: Text(AppLocalizations.of(context)!.shareMenuQRCode, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
437 : ),
438 : ],
439 : ),
440 : );
441 : } else {
442 0 : actions.add(
443 0 : IconButton(
444 0 : icon: Icon(CwtchIcons.address_copy),
445 0 : tooltip: AppLocalizations.of(context)!.copyAddress,
446 0 : splashRadius: Material.defaultSplashRadius / 2,
447 0 : onPressed: () {
448 0 : Clipboard.setData(new ClipboardData(text: Provider.of<ProfileInfoState>(context, listen: false).onion));
449 0 : final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.copiedToClipboardNotification));
450 0 : scaffoldKey.currentState?.showSnackBar(snackBar);
451 : },
452 : ),
453 : );
454 : }
455 :
456 : // Manage known Servers
457 0 : if (Provider.of<Settings>(context, listen: false).isExperimentEnabled(TapirGroupsExperiment) || Provider.of<Settings>(context, listen: false).isExperimentEnabled(ServerManagementExperiment)) {
458 0 : actions.add(
459 0 : IconButton(
460 0 : icon: Icon(CwtchIcons.dns_24px),
461 0 : tooltip: AppLocalizations.of(context)!.manageKnownServersButton,
462 0 : splashRadius: Material.defaultSplashRadius / 2,
463 0 : onPressed: () {
464 0 : _pushServers();
465 : },
466 : ),
467 : );
468 : }
469 :
470 : // Search contacts
471 0 : actions.add(
472 0 : IconButton(
473 : // need both conditions for displaying initial empty textfield and also allowing filters to be cleared if this widget gets lost/reset
474 0 : icon: Icon(Provider.of<SearchState>(context).searchOrFiltered ? Icons.search_off : Icons.search),
475 0 : splashRadius: Material.defaultSplashRadius / 2,
476 0 : onPressed: () {
477 0 : Provider.of<SearchState>(context, listen: false).toggleSearch();
478 : },
479 : ),
480 : );
481 : return actions;
482 : }
483 :
484 0 : Widget _buildFilterable() {
485 0 : Widget txtfield = CwtchTextField(
486 0 : controller: ctrlrFilter,
487 0 : hintText: AppLocalizations.of(context)!.search,
488 : autofocus: true,
489 0 : onChanged: (newVal) {
490 0 : String profileHandle = Provider.of<ProfileInfoState>(context, listen: false).onion;
491 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.SearchConversations(profileHandle, newVal).then((value) {
492 0 : Provider.of<SearchState>(context, listen: false).newSearch(value);
493 : });
494 0 : Provider.of<SearchState>(context, listen: false).filter = newVal;
495 : },
496 : );
497 0 : return Column(
498 0 : children: [
499 0 : Padding(padding: EdgeInsets.all(8), child: txtfield),
500 0 : Expanded(child: _buildContactList()),
501 : ],
502 : );
503 : }
504 :
505 0 : Widget _buildContactList() {
506 0 : var tilesFilteredContacts = Provider.of<ProfileInfoState>(context).filteredList().map((ContactInfoState contact) {
507 0 : return MultiProvider(
508 0 : providers: [
509 0 : ChangeNotifierProvider.value(value: contact),
510 0 : ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context).serverList),
511 : ],
512 0 : builder: (context, child) => ContactRow(),
513 : );
514 : });
515 :
516 0 : var initialScroll = Provider.of<ProfileInfoState>(context, listen: false).filteredList().indexWhere((element) => element.identifier == Provider.of<AppState>(context).selectedConversation);
517 0 : if (initialScroll < 0) {
518 : initialScroll = 0;
519 : }
520 :
521 0 : if (Provider.of<SearchState>(context).searchActive) {
522 0 : List<SearchResult> searchResults = Provider.of<SearchState>(context).activeSearchResults;
523 0 : var tilesSearchResult = searchResults.map((SearchResult searchResult) {
524 0 : return MultiProvider(
525 0 : providers: [
526 0 : ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context).contactList.getContact(searchResult.conversationIdentifier)),
527 0 : ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context).serverList),
528 : ],
529 0 : builder: (context, child) => ContactRow(messageIndex: searchResult.messageIndex),
530 : );
531 : });
532 0 : tilesFilteredContacts = tilesFilteredContacts.followedBy(tilesSearchResult);
533 : } else {}
534 :
535 0 : var contactList = ScrollablePositionedList.separated(
536 0 : itemScrollController: Provider.of<ProfileInfoState>(context).contactListScrollController,
537 0 : itemCount: tilesFilteredContacts.length,
538 : initialScrollIndex: initialScroll,
539 : shrinkWrap: true,
540 0 : physics: BouncingScrollPhysics(),
541 0 : semanticChildCount: tilesFilteredContacts.length,
542 0 : itemBuilder: (context, index) {
543 0 : if (tilesFilteredContacts.length > index) {
544 0 : return tilesFilteredContacts.elementAt(index);
545 : }
546 0 : return Container();
547 : },
548 0 : separatorBuilder: (BuildContext context, int index) {
549 0 : return Divider(height: 1);
550 : },
551 : );
552 :
553 : return contactList;
554 : }
555 :
556 0 : void _pushAddContact(bool newGroup) {
557 : // close modal
558 0 : Navigator.popUntil(context, (route) => route.settings.name == "conversations");
559 :
560 0 : Navigator.of(context).push(
561 0 : PageRouteBuilder(
562 0 : settings: RouteSettings(name: "addcontact"),
563 0 : pageBuilder: (builderContext, a1, a2) {
564 0 : return MultiProvider(
565 0 : providers: [ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context))],
566 0 : child: AddContactView(newGroup: newGroup),
567 : );
568 : },
569 0 : transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
570 0 : transitionDuration: Duration(milliseconds: 200),
571 : ),
572 : );
573 : }
574 :
575 0 : void _pushServers() {
576 0 : var profileInfoState = Provider.of<ProfileInfoState>(context, listen: false);
577 :
578 0 : Navigator.of(context).push(
579 0 : PageRouteBuilder(
580 0 : settings: RouteSettings(name: "profileremoteservers"),
581 0 : pageBuilder: (bcontext, a1, a2) {
582 0 : return MultiProvider(
583 0 : providers: [
584 0 : ChangeNotifierProvider.value(value: profileInfoState),
585 0 : Provider.value(value: Provider.of<FlwtchState>(context)),
586 : ],
587 0 : child: ProfileServersView(),
588 : );
589 : },
590 0 : transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
591 0 : transitionDuration: Duration(milliseconds: 200),
592 : ),
593 : );
594 : }
595 :
596 0 : void _modalAddImportChoice() {
597 0 : bool groupsEnabled = Provider.of<Settings>(context, listen: false).isExperimentEnabled(TapirGroupsExperiment);
598 :
599 0 : showModalBottomSheet<void>(
600 0 : context: context,
601 : isScrollControlled: true,
602 0 : builder: (BuildContext context) {
603 0 : return Padding(
604 0 : padding: MediaQuery.of(context).viewInsets,
605 0 : child: RepaintBoundary(
606 0 : child: Container(
607 0 : height: Platform.isAndroid ? 250 : 200, // bespoke value courtesy of the [TextField] docs
608 0 : child: Center(
609 0 : child: Padding(
610 0 : padding: EdgeInsets.all(2.0),
611 0 : child: Column(
612 : mainAxisAlignment: MainAxisAlignment.center,
613 : crossAxisAlignment: CrossAxisAlignment.center,
614 : mainAxisSize: MainAxisSize.max,
615 0 : children: <Widget>[
616 0 : SizedBox(height: 20),
617 0 : Expanded(
618 0 : child: Tooltip(
619 0 : message: AppLocalizations.of(context)!.tooltipAddContact,
620 0 : child: ElevatedButton(
621 0 : style: ElevatedButton.styleFrom(
622 0 : minimumSize: Size.fromWidth(399),
623 0 : maximumSize: Size.fromWidth(400),
624 0 : shape: RoundedRectangleBorder(
625 0 : borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180)),
626 : ),
627 : ),
628 0 : child: Text(
629 0 : AppLocalizations.of(context)!.addContact,
630 0 : semanticsLabel: AppLocalizations.of(context)!.addContact,
631 : textAlign: TextAlign.center,
632 0 : style: TextStyle(fontFamily: "Inter", fontSize: 10.0 * Provider.of<Settings>(context).fontScaling, fontWeight: FontWeight.bold),
633 : ),
634 0 : onPressed: () {
635 0 : _pushAddContact(false);
636 : },
637 : ),
638 : ),
639 : ),
640 0 : SizedBox(height: 20),
641 0 : Expanded(
642 0 : child: Tooltip(
643 0 : message: groupsEnabled ? AppLocalizations.of(context)!.addServerTooltip : AppLocalizations.of(context)!.thisFeatureRequiresGroupExpermientsToBeEnabled,
644 0 : child: ElevatedButton(
645 0 : style: ElevatedButton.styleFrom(
646 0 : minimumSize: Size.fromWidth(399),
647 0 : maximumSize: Size.fromWidth(400),
648 0 : shape: RoundedRectangleBorder(
649 0 : borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180)),
650 : ),
651 : ),
652 0 : child: Text(
653 0 : AppLocalizations.of(context)!.addServerTitle,
654 0 : semanticsLabel: AppLocalizations.of(context)!.addServerTitle,
655 : textAlign: TextAlign.center,
656 0 : style: TextStyle(fontFamily: "Inter", fontSize: 10.0 * Provider.of<Settings>(context).fontScaling, fontWeight: FontWeight.bold),
657 : ),
658 : onPressed: groupsEnabled
659 0 : ? () {
660 0 : _pushAddContact(false);
661 : }
662 : : null,
663 : ),
664 : ),
665 : ),
666 0 : SizedBox(height: 20),
667 0 : Expanded(
668 0 : child: Tooltip(
669 0 : message: groupsEnabled ? AppLocalizations.of(context)!.createGroupTitle : AppLocalizations.of(context)!.thisFeatureRequiresGroupExpermientsToBeEnabled,
670 0 : child: ElevatedButton(
671 0 : style: ElevatedButton.styleFrom(
672 0 : minimumSize: Size.fromWidth(399),
673 0 : maximumSize: Size.fromWidth(400),
674 0 : shape: RoundedRectangleBorder(
675 0 : borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180)),
676 : ),
677 : ),
678 0 : child: Text(
679 0 : AppLocalizations.of(context)!.createGroupTitle,
680 0 : semanticsLabel: AppLocalizations.of(context)!.createGroupTitle,
681 : textAlign: TextAlign.center,
682 0 : style: TextStyle(fontFamily: "Inter", fontSize: 10.0 * Provider.of<Settings>(context).fontScaling, fontWeight: FontWeight.bold),
683 : ),
684 : onPressed: groupsEnabled
685 0 : ? () {
686 0 : _pushAddContact(true);
687 : }
688 : : null,
689 : ),
690 : ),
691 : ),
692 0 : SizedBox(height: 20),
693 : ],
694 : ),
695 : ),
696 : ),
697 : ),
698 : ),
699 : );
700 : },
701 : );
702 : }
703 :
704 0 : void _showQRCode(String profileCode) {
705 0 : showModalBottomSheet<dynamic>(
706 0 : context: context,
707 0 : builder: (BuildContext context) {
708 0 : return Wrap(
709 0 : children: <Widget>[
710 0 : Center(
711 0 : child: QrImageView(
712 : data: profileCode,
713 : version: QrVersions.auto,
714 : size: 400.0,
715 0 : backgroundColor: Provider.of<Settings>(context).theme.backgroundPaneColor,
716 0 : foregroundColor: Provider.of<Settings>(context).theme.mainTextColor,
717 : gapless: false,
718 : ),
719 : ),
720 : ],
721 : );
722 : },
723 : );
724 : }
725 : }
|