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, reconnectProfile }
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.reconnectProfile:
199 0 : Provider.of<ProfileInfoState>(context, listen: false).deactivatePeerEngine(context);
200 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, true, true, true);
201 : break;
202 0 : case ProfileStatusMenu.appearOffline:
203 0 : Provider.of<ProfileInfoState>(context, listen: false).appearOffline = true;
204 0 : Provider.of<ProfileInfoState>(context, listen: false).deactivatePeerEngine(context);
205 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, false, false, false);
206 : break;
207 0 : case ProfileStatusMenu.editProfile:
208 0 : Navigator.of(context).push(
209 0 : PageRouteBuilder(
210 0 : pageBuilder: (bcontext, a1, a2) {
211 0 : return MultiProvider(
212 0 : providers: [ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context, listen: false))],
213 0 : builder: (context, widget) => AddEditProfileView(key: Key('addprofile')),
214 : );
215 : },
216 0 : transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
217 0 : transitionDuration: Duration(milliseconds: 200),
218 : ),
219 : );
220 : break;
221 0 : case ProfileStatusMenu.appearOnline:
222 0 : Provider.of<ProfileInfoState>(context, listen: false).appearOffline = false;
223 : // we only need to toggle all connections on here..
224 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, true, true, true);
225 : break;
226 0 : case ProfileStatusMenu.allowUnknownContacts:
227 0 : settings.blockUnknownConnections = false;
228 0 : saveSettings(context);
229 : break;
230 0 : case ProfileStatusMenu.blockUnknownContacts:
231 0 : settings.blockUnknownConnections = true;
232 0 : saveSettings(context);
233 : break;
234 0 : case ProfileStatusMenu.enableProfile:
235 0 : Provider.of<ProfileInfoState>(context, listen: false).enabled = true;
236 0 : if (Provider.of<ProfileInfoState>(context, listen: false).appearOffline) {
237 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, false, false, false);
238 : } else {
239 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.ConfigureConnections(onion, true, true, true);
240 : }
241 : break;
242 0 : case ProfileStatusMenu.disableProfile:
243 0 : Provider.of<ProfileInfoState>(context, listen: false).enabled = false;
244 0 : Provider.of<ProfileInfoState>(context, listen: false).deactivatePeerEngine(context);
245 : break;
246 : }
247 : },
248 0 : itemBuilder: (BuildContext context) => <PopupMenuEntry<ProfileStatusMenu>>[
249 0 : PopupMenuItem<ProfileStatusMenu>(
250 : value: ProfileStatusMenu.available,
251 : enabled: enabled,
252 0 : child: Row(
253 0 : children: [
254 0 : Icon(CwtchIcons.account_circle_24px, color: Colors.white),
255 0 : Expanded(
256 0 : child: Text(
257 0 : AppLocalizations.of(context)!.availabilityStatusAvailable,
258 : textAlign: TextAlign.right,
259 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
260 : ),
261 : ),
262 : ],
263 : ),
264 : ),
265 0 : PopupMenuItem<ProfileStatusMenu>(
266 : value: ProfileStatusMenu.away,
267 : enabled: enabled,
268 0 : child: Row(
269 0 : children: [
270 0 : Icon(CwtchIcons.account_circle_24px, color: Colors.yellowAccent),
271 0 : Expanded(
272 0 : child: Text(
273 0 : AppLocalizations.of(context)!.availabilityStatusAway,
274 : textAlign: TextAlign.right,
275 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
276 : ),
277 : ),
278 : ],
279 : ),
280 : ),
281 0 : PopupMenuItem<ProfileStatusMenu>(
282 : value: ProfileStatusMenu.busy,
283 : enabled: enabled,
284 0 : child: Row(
285 0 : children: [
286 0 : Icon(CwtchIcons.account_circle_24px, color: Colors.redAccent),
287 0 : Expanded(
288 0 : child: Text(
289 0 : AppLocalizations.of(context)!.availabilityStatusBusy,
290 : textAlign: TextAlign.right,
291 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
292 : ),
293 : ),
294 : ],
295 : ),
296 : ),
297 0 : PopupMenuDivider(),
298 0 : PopupMenuItem<ProfileStatusMenu>(
299 : value: ProfileStatusMenu.appearOffline,
300 : enabled: enabled && !appearOffline,
301 0 : child: Row(
302 0 : children: [
303 0 : Icon(CwtchIcons.disconnect_from_contact),
304 0 : Expanded(
305 0 : child: Text(
306 0 : AppLocalizations.of(context)!.profileAppearOffline,
307 : textAlign: TextAlign.right,
308 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
309 : ),
310 : ),
311 : ],
312 : ),
313 : ),
314 0 : PopupMenuItem<ProfileStatusMenu>(
315 : value: ProfileStatusMenu.appearOnline,
316 : enabled: enabled && appearOffline,
317 0 : child: Row(
318 0 : children: [
319 0 : Icon(CwtchIcons.disconnect_from_contact),
320 0 : Expanded(
321 0 : child: Text(
322 0 : AppLocalizations.of(context)!.profileAppearOnline,
323 : textAlign: TextAlign.right,
324 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
325 : ),
326 : ),
327 : ],
328 : ),
329 : ),
330 0 : PopupMenuDivider(),
331 0 : PopupMenuItem<ProfileStatusMenu>(
332 0 : value: !settings.blockUnknownConnections ? ProfileStatusMenu.blockUnknownContacts : ProfileStatusMenu.allowUnknownContacts,
333 0 : child: Row(
334 0 : children: [
335 0 : Icon(CwtchIcons.block_unknown, color: settings.theme.mainTextColor),
336 0 : Expanded(
337 0 : child: Text(
338 0 : (settings.blockUnknownConnections ? AppLocalizations.of(context)!.profileAllowUnknownContacts : AppLocalizations.of(context)!.profileBlockUnknownContacts),
339 : textAlign: TextAlign.right,
340 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
341 : ),
342 : ),
343 : ],
344 : ),
345 : ),
346 0 : PopupMenuDivider(),
347 0 : PopupMenuItem<ProfileStatusMenu>(
348 : value: enabled ? ProfileStatusMenu.disableProfile : ProfileStatusMenu.enableProfile,
349 0 : child: Row(
350 0 : children: [
351 0 : Icon(CwtchIcons.favorite_24px, color: settings.theme.mainTextColor),
352 0 : Expanded(
353 0 : child: Text(
354 0 : (enabled ? AppLocalizations.of(context)!.profileDisableProfile : AppLocalizations.of(context)!.profileEnableProfile),
355 : textAlign: TextAlign.right,
356 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
357 : ),
358 : ),
359 : ],
360 : ),
361 : ),
362 0 : PopupMenuItem<ProfileStatusMenu>(
363 : value: ProfileStatusMenu.reconnectProfile,
364 : enabled: enabled && !appearOffline,
365 0 : child: Row(
366 0 : children: [
367 0 : Icon(Icons.cached),
368 0 : Expanded(
369 0 : child: Text(
370 0 : AppLocalizations.of(context)!.restartProfile,
371 : textAlign: TextAlign.right,
372 0 : style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle),
373 : ),
374 : ),
375 : ],
376 : ),
377 : ),
378 0 : PopupMenuItem<ProfileStatusMenu>(
379 : value: ProfileStatusMenu.editProfile,
380 : enabled: true,
381 0 : child: Row(
382 0 : children: [
383 0 : Icon(CwtchIcons.edit_24px, color: settings.theme.mainTextColor),
384 0 : Expanded(
385 0 : child: Text(AppLocalizations.of(context)!.editProfile, textAlign: TextAlign.right, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
386 : ),
387 : ],
388 : ),
389 : ),
390 : ],
391 : ),
392 0 : SizedBox(width: 10),
393 0 : Expanded(
394 0 : child: Text(
395 : "%1 ยป %2"
396 0 : .replaceAll("%1", redactedNick(context, Provider.of<ProfileInfoState>(context).onion, Provider.of<ProfileInfoState>(context).nickname))
397 0 : .replaceAll("%2", AppLocalizations.of(context)!.titleManageContacts),
398 : overflow: TextOverflow.ellipsis,
399 0 : style: TextStyle(
400 0 : color: Provider.of<Settings>(context).current().mainTextColor,
401 : fontFamily: "Inter",
402 : fontWeight: FontWeight.bold,
403 0 : fontSize: 14.0 * Provider.of<Settings>(context).fontScaling,
404 : ),
405 : ),
406 : ),
407 : ],
408 : ),
409 0 : actions: getActions(context),
410 : ),
411 0 : floatingActionButton: FloatingActionButton(
412 0 : onPressed: _modalAddImportChoice,
413 0 : tooltip: AppLocalizations.of(context)!.tooltipAddContact,
414 0 : child: Icon(CwtchIcons.person_add_alt_1_24px, color: Provider.of<Settings>(context).theme.defaultButtonTextColor),
415 : ),
416 0 : body: Provider.of<SearchState>(context).searchOrFiltered ? _buildFilterable() : _buildContactList(),
417 : ),
418 : );
419 : }
420 :
421 0 : List<Widget> getActions(context) {
422 0 : var actions = List<Widget>.empty(growable: true);
423 0 : if (Provider.of<Settings>(context).blockUnknownConnections) {
424 0 : actions.add(Tooltip(message: AppLocalizations.of(context)!.blockUnknownConnectionsEnabledDescription, child: Icon(CwtchIcons.block_unknown)));
425 : }
426 :
427 0 : if (Provider.of<Settings>(context, listen: false).isExperimentEnabled(QRCodeExperiment)) {
428 0 : actions.add(
429 0 : PopupMenuButton<ShareMenu>(
430 0 : icon: Icon(CwtchIcons.copy_address),
431 0 : tooltip: AppLocalizations.of(context)!.shareProfileMenuTooltop,
432 0 : splashRadius: Material.defaultSplashRadius / 2,
433 0 : onSelected: (ShareMenu item) {
434 : switch (item) {
435 0 : case ShareMenu.copyCode:
436 : {
437 0 : Clipboard.setData(new ClipboardData(text: Provider.of<ProfileInfoState>(context, listen: false).onion));
438 0 : final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.copiedToClipboardNotification));
439 0 : scaffoldKey.currentState?.showSnackBar(snackBar);
440 : }
441 : break;
442 0 : case ShareMenu.qrcode:
443 : {
444 0 : _showQRCode("cwtch:" + Provider.of<ProfileInfoState>(context, listen: false).onion);
445 : }
446 : break;
447 : }
448 : },
449 0 : itemBuilder: (BuildContext context) => <PopupMenuEntry<ShareMenu>>[
450 0 : PopupMenuItem<ShareMenu>(
451 : value: ShareMenu.copyCode,
452 0 : child: Text(AppLocalizations.of(context)!.copyAddress, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
453 : ),
454 0 : PopupMenuItem<ShareMenu>(
455 : value: ShareMenu.qrcode,
456 0 : child: Text(AppLocalizations.of(context)!.shareMenuQRCode, style: Provider.of<Settings>(context, listen: false).scaleFonts(defaultTextButtonStyle)),
457 : ),
458 : ],
459 : ),
460 : );
461 : } else {
462 0 : actions.add(
463 0 : IconButton(
464 0 : icon: Icon(CwtchIcons.copy_address),
465 0 : tooltip: AppLocalizations.of(context)!.copyAddress,
466 0 : splashRadius: Material.defaultSplashRadius / 2,
467 0 : onPressed: () {
468 0 : Clipboard.setData(new ClipboardData(text: Provider.of<ProfileInfoState>(context, listen: false).onion));
469 0 : final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.copiedToClipboardNotification));
470 0 : scaffoldKey.currentState?.showSnackBar(snackBar);
471 : },
472 : ),
473 : );
474 : }
475 :
476 : // Manage known Servers
477 0 : if (Provider.of<Settings>(context, listen: false).isExperimentEnabled(TapirGroupsExperiment) || Provider.of<Settings>(context, listen: false).isExperimentEnabled(ServerManagementExperiment)) {
478 0 : actions.add(
479 0 : IconButton(
480 0 : icon: Icon(CwtchIcons.dns_24px),
481 0 : tooltip: AppLocalizations.of(context)!.manageKnownServersButton,
482 0 : splashRadius: Material.defaultSplashRadius / 2,
483 0 : onPressed: () {
484 0 : _pushServers();
485 : },
486 : ),
487 : );
488 : }
489 :
490 : // Search contacts
491 0 : actions.add(
492 0 : IconButton(
493 : // need both conditions for displaying initial empty textfield and also allowing filters to be cleared if this widget gets lost/reset
494 0 : icon: Icon(Provider.of<SearchState>(context).searchOrFiltered ? Icons.search_off : Icons.search),
495 0 : splashRadius: Material.defaultSplashRadius / 2,
496 0 : onPressed: () {
497 0 : Provider.of<SearchState>(context, listen: false).toggleSearch();
498 : },
499 : ),
500 : );
501 : return actions;
502 : }
503 :
504 0 : Widget _buildFilterable() {
505 0 : Widget txtfield = CwtchTextField(
506 0 : controller: ctrlrFilter,
507 0 : hintText: AppLocalizations.of(context)!.search,
508 : autofocus: true,
509 0 : onChanged: (newVal) {
510 0 : String profileHandle = Provider.of<ProfileInfoState>(context, listen: false).onion;
511 0 : Provider.of<FlwtchState>(context, listen: false).cwtch.SearchConversations(profileHandle, newVal).then((value) {
512 0 : Provider.of<SearchState>(context, listen: false).newSearch(value);
513 : });
514 0 : Provider.of<SearchState>(context, listen: false).filter = newVal;
515 : },
516 : );
517 0 : return Column(
518 0 : children: [
519 0 : Padding(padding: EdgeInsets.all(8), child: txtfield),
520 0 : Expanded(child: _buildContactList()),
521 : ],
522 : );
523 : }
524 :
525 0 : Widget _buildContactList() {
526 0 : var tilesFilteredContacts = Provider.of<ProfileInfoState>(context).filteredList().map((ContactInfoState contact) {
527 0 : return MultiProvider(
528 0 : providers: [
529 0 : ChangeNotifierProvider.value(value: contact),
530 0 : ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context).serverList),
531 : ],
532 0 : builder: (context, child) => ContactRow(),
533 : );
534 : });
535 :
536 0 : var initialScroll = Provider.of<ProfileInfoState>(context, listen: false).filteredList().indexWhere((element) => element.identifier == Provider.of<AppState>(context).selectedConversation);
537 0 : if (initialScroll < 0) {
538 : initialScroll = 0;
539 : }
540 :
541 0 : if (Provider.of<SearchState>(context).searchActive) {
542 0 : List<SearchResult> searchResults = Provider.of<SearchState>(context).activeSearchResults;
543 0 : var tilesSearchResult = searchResults.map((SearchResult searchResult) {
544 0 : return MultiProvider(
545 0 : providers: [
546 0 : ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context).contactList.getContact(searchResult.conversationIdentifier)),
547 0 : ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context).serverList),
548 : ],
549 0 : builder: (context, child) => ContactRow(messageIndex: searchResult.messageIndex),
550 : );
551 : });
552 0 : tilesFilteredContacts = tilesFilteredContacts.followedBy(tilesSearchResult);
553 : } else {}
554 :
555 0 : var contactList = ScrollablePositionedList.separated(
556 0 : itemScrollController: Provider.of<ProfileInfoState>(context).contactListScrollController,
557 0 : itemCount: tilesFilteredContacts.length,
558 : initialScrollIndex: initialScroll,
559 : shrinkWrap: true,
560 0 : physics: BouncingScrollPhysics(),
561 0 : semanticChildCount: tilesFilteredContacts.length,
562 0 : itemBuilder: (context, index) {
563 0 : if (tilesFilteredContacts.length > index) {
564 0 : return tilesFilteredContacts.elementAt(index);
565 : }
566 0 : return Container();
567 : },
568 0 : separatorBuilder: (BuildContext context, int index) {
569 0 : return Divider(height: 1);
570 : },
571 : );
572 :
573 : return contactList;
574 : }
575 :
576 0 : void _pushAddContact(bool newGroup) {
577 : // close modal
578 0 : Navigator.popUntil(context, (route) => route.settings.name == "conversations");
579 :
580 0 : Navigator.of(context).push(
581 0 : PageRouteBuilder(
582 0 : settings: RouteSettings(name: "addcontact"),
583 0 : pageBuilder: (builderContext, a1, a2) {
584 0 : return MultiProvider(
585 0 : providers: [ChangeNotifierProvider.value(value: Provider.of<ProfileInfoState>(context))],
586 0 : child: AddContactView(newGroup: newGroup),
587 : );
588 : },
589 0 : transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
590 0 : transitionDuration: Duration(milliseconds: 200),
591 : ),
592 : );
593 : }
594 :
595 0 : void _pushServers() {
596 0 : var profileInfoState = Provider.of<ProfileInfoState>(context, listen: false);
597 :
598 0 : Navigator.of(context).push(
599 0 : PageRouteBuilder(
600 0 : settings: RouteSettings(name: "profileremoteservers"),
601 0 : pageBuilder: (bcontext, a1, a2) {
602 0 : return MultiProvider(
603 0 : providers: [
604 0 : ChangeNotifierProvider.value(value: profileInfoState),
605 0 : Provider.value(value: Provider.of<FlwtchState>(context)),
606 : ],
607 0 : child: ProfileServersView(),
608 : );
609 : },
610 0 : transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
611 0 : transitionDuration: Duration(milliseconds: 200),
612 : ),
613 : );
614 : }
615 :
616 0 : void _modalAddImportChoice() {
617 0 : bool groupsEnabled = Provider.of<Settings>(context, listen: false).isExperimentEnabled(TapirGroupsExperiment);
618 :
619 0 : showModalBottomSheet<void>(
620 0 : context: context,
621 : isScrollControlled: true,
622 0 : builder: (BuildContext context) {
623 0 : return Padding(
624 0 : padding: MediaQuery.of(context).viewInsets,
625 0 : child: RepaintBoundary(
626 0 : child: Container(
627 0 : height: Platform.isAndroid ? 250 : 200, // bespoke value courtesy of the [TextField] docs
628 0 : child: Center(
629 0 : child: Padding(
630 0 : padding: EdgeInsets.all(2.0),
631 0 : child: Column(
632 : mainAxisAlignment: MainAxisAlignment.center,
633 : crossAxisAlignment: CrossAxisAlignment.center,
634 : mainAxisSize: MainAxisSize.max,
635 0 : children: <Widget>[
636 0 : SizedBox(height: 20),
637 0 : Expanded(
638 0 : child: Tooltip(
639 0 : message: AppLocalizations.of(context)!.tooltipAddContact,
640 0 : child: ElevatedButton(
641 0 : style: ElevatedButton.styleFrom(
642 0 : minimumSize: Size.fromWidth(399),
643 0 : maximumSize: Size.fromWidth(400),
644 0 : shape: RoundedRectangleBorder(
645 0 : borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180)),
646 : ),
647 : ),
648 0 : child: Text(
649 0 : AppLocalizations.of(context)!.addContact,
650 0 : semanticsLabel: AppLocalizations.of(context)!.addContact,
651 : textAlign: TextAlign.center,
652 0 : style: TextStyle(fontFamily: "Inter", fontSize: 10.0 * Provider.of<Settings>(context).fontScaling, fontWeight: FontWeight.bold),
653 : ),
654 0 : onPressed: () {
655 0 : _pushAddContact(false);
656 : },
657 : ),
658 : ),
659 : ),
660 0 : SizedBox(height: 20),
661 0 : Expanded(
662 0 : child: Tooltip(
663 0 : message: groupsEnabled ? AppLocalizations.of(context)!.addServerTooltip : AppLocalizations.of(context)!.thisFeatureRequiresGroupExpermientsToBeEnabled,
664 0 : child: ElevatedButton(
665 0 : style: ElevatedButton.styleFrom(
666 0 : minimumSize: Size.fromWidth(399),
667 0 : maximumSize: Size.fromWidth(400),
668 0 : shape: RoundedRectangleBorder(
669 0 : borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180)),
670 : ),
671 : ),
672 0 : child: Text(
673 0 : AppLocalizations.of(context)!.addServerTitle,
674 0 : semanticsLabel: AppLocalizations.of(context)!.addServerTitle,
675 : textAlign: TextAlign.center,
676 0 : style: TextStyle(fontFamily: "Inter", fontSize: 10.0 * Provider.of<Settings>(context).fontScaling, fontWeight: FontWeight.bold),
677 : ),
678 : onPressed: groupsEnabled
679 0 : ? () {
680 0 : _pushAddContact(false);
681 : }
682 : : null,
683 : ),
684 : ),
685 : ),
686 0 : SizedBox(height: 20),
687 0 : Expanded(
688 0 : child: Tooltip(
689 0 : message: groupsEnabled ? AppLocalizations.of(context)!.createGroupTitle : AppLocalizations.of(context)!.thisFeatureRequiresGroupExpermientsToBeEnabled,
690 0 : child: ElevatedButton(
691 0 : style: ElevatedButton.styleFrom(
692 0 : minimumSize: Size.fromWidth(399),
693 0 : maximumSize: Size.fromWidth(400),
694 0 : shape: RoundedRectangleBorder(
695 0 : borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180)),
696 : ),
697 : ),
698 0 : child: Text(
699 0 : AppLocalizations.of(context)!.createGroupTitle,
700 0 : semanticsLabel: AppLocalizations.of(context)!.createGroupTitle,
701 : textAlign: TextAlign.center,
702 0 : style: TextStyle(fontFamily: "Inter", fontSize: 10.0 * Provider.of<Settings>(context).fontScaling, fontWeight: FontWeight.bold),
703 : ),
704 : onPressed: groupsEnabled
705 0 : ? () {
706 0 : _pushAddContact(true);
707 : }
708 : : null,
709 : ),
710 : ),
711 : ),
712 0 : SizedBox(height: 20),
713 : ],
714 : ),
715 : ),
716 : ),
717 : ),
718 : ),
719 : );
720 : },
721 : );
722 : }
723 :
724 0 : void _showQRCode(String profileCode) {
725 0 : showModalBottomSheet<dynamic>(
726 0 : context: context,
727 0 : builder: (BuildContext context) {
728 0 : return Wrap(
729 0 : children: <Widget>[
730 0 : Center(
731 0 : child: QrImageView(
732 : data: profileCode,
733 : version: QrVersions.auto,
734 : size: 400.0,
735 0 : backgroundColor: Provider.of<Settings>(context).theme.backgroundPaneColor,
736 0 : foregroundColor: Provider.of<Settings>(context).theme.mainTextColor,
737 : gapless: false,
738 : ),
739 : ),
740 : ],
741 : );
742 : },
743 : );
744 : }
745 : }
|