LCOV - code coverage report
Current view: top level - lib/views - groupsettingsview.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 126 0.0 %
Date: 2024-10-08 18:18:56 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:cwtch/cwtch_icons_icons.dart';
       2             : import 'package:cwtch/models/appstate.dart';
       3             : import 'package:cwtch/models/contact.dart';
       4             : import 'package:cwtch/models/profile.dart';
       5             : import 'package:cwtch/themes/opaque.dart';
       6             : import 'package:flutter/services.dart';
       7             : import 'package:cwtch/widgets/buttontextfield.dart';
       8             : import 'package:cwtch/widgets/cwtchlabel.dart';
       9             : import 'package:flutter/material.dart';
      10             : import 'package:cwtch/settings.dart';
      11             : import 'package:cwtch/widgets/textfield.dart';
      12             : import 'package:provider/provider.dart';
      13             : import 'package:flutter_gen/gen_l10n/app_localizations.dart';
      14             : 
      15             : import '../main.dart';
      16             : 
      17             : /// Group Settings View Provides way to Configure group settings
      18             : class GroupSettingsView extends StatefulWidget {
      19           0 :   @override
      20           0 :   _GroupSettingsViewState createState() => _GroupSettingsViewState();
      21             : }
      22             : 
      23             : class _GroupSettingsViewState extends State<GroupSettingsView> {
      24           0 :   @override
      25             :   void dispose() {
      26           0 :     super.dispose();
      27             :   }
      28             : 
      29             :   final ctrlrNick = TextEditingController(text: "");
      30             :   final ctrlrGroupAddr = TextEditingController(text: "");
      31             :   ScrollController groupSettingsScrollController = ScrollController();
      32             : 
      33           0 :   @override
      34             :   void initState() {
      35           0 :     super.initState();
      36           0 :     final nickname = Provider.of<ContactInfoState>(context, listen: false).nickname;
      37           0 :     if (nickname.isNotEmpty) {
      38           0 :       ctrlrNick.text = nickname;
      39             :     }
      40           0 :     final groupAddr = Provider.of<ContactInfoState>(context, listen: false).onion;
      41           0 :     if (groupAddr.isNotEmpty) {
      42           0 :       ctrlrGroupAddr.text = groupAddr;
      43             :     }
      44             :   }
      45             : 
      46           0 :   @override
      47             :   Widget build(BuildContext context) {
      48           0 :     return Scaffold(
      49           0 :       appBar: AppBar(
      50           0 :         title: Container(
      51           0 :             height: Provider.of<Settings>(context).fontScaling * 24.0,
      52             :             clipBehavior: Clip.hardEdge,
      53           0 :             decoration: BoxDecoration(),
      54           0 :             child: Text(Provider.of<ContactInfoState>(context).nickname + " " + AppLocalizations.of(context)!.conversationSettings)),
      55             :       ),
      56           0 :       body: _buildSettingsList(),
      57             :     );
      58             :   }
      59             : 
      60           0 :   Widget _buildSettingsList() {
      61           0 :     return Consumer<Settings>(builder: (context, settings, child) {
      62           0 :       return LayoutBuilder(builder: (BuildContext context, BoxConstraints viewportConstraints) {
      63           0 :         return Scrollbar(
      64             :             trackVisibility: true,
      65           0 :             controller: groupSettingsScrollController,
      66           0 :             child: SingleChildScrollView(
      67             :                 clipBehavior: Clip.antiAlias,
      68           0 :                 controller: groupSettingsScrollController,
      69           0 :                 child: ConstrainedBox(
      70           0 :                     constraints: BoxConstraints(
      71           0 :                       minHeight: viewportConstraints.maxHeight,
      72             :                     ),
      73           0 :                     child: Container(
      74           0 :                         color: settings.theme.backgroundPaneColor,
      75           0 :                         padding: EdgeInsets.all(12),
      76           0 :                         child: Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.stretch, children: [
      77             :                           // Nickname Save Button
      78           0 :                           Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
      79           0 :                             SizedBox(
      80             :                               height: 20,
      81             :                             ),
      82           0 :                             CwtchLabel(label: AppLocalizations.of(context)!.displayNameLabel),
      83           0 :                             SizedBox(
      84             :                               height: 20,
      85             :                             ),
      86           0 :                             CwtchButtonTextField(
      87           0 :                               controller: ctrlrNick,
      88             :                               readonly: false,
      89           0 :                               onPressed: () {
      90           0 :                                 var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
      91           0 :                                 var handle = Provider.of<ContactInfoState>(context, listen: false).identifier;
      92           0 :                                 Provider.of<ContactInfoState>(context, listen: false).nickname = ctrlrNick.text;
      93           0 :                                 Provider.of<FlwtchState>(context, listen: false).cwtch.SetConversationAttribute(profileOnion, handle, "profile.name", ctrlrNick.text);
      94             :                                 // todo translations
      95           0 :                                 final snackBar = SnackBar(content: Text("Group Nickname changed successfully"));
      96           0 :                                 ScaffoldMessenger.of(context).showSnackBar(snackBar);
      97             :                               },
      98           0 :                               icon: Icon(Icons.save),
      99           0 :                               tooltip: AppLocalizations.of(context)!.saveBtn,
     100             :                             )
     101             :                           ]),
     102           0 :                           Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
     103           0 :                             SizedBox(
     104             :                               height: 20,
     105             :                             ),
     106           0 :                             CwtchLabel(label: AppLocalizations.of(context)!.server),
     107           0 :                             SizedBox(
     108             :                               height: 20,
     109             :                             ),
     110           0 :                             CwtchTextField(
     111           0 :                               controller: TextEditingController(text: Provider.of<ContactInfoState>(context, listen: false).server),
     112           0 :                               validator: (value) {
     113             :                                 return null;
     114             :                               },
     115             :                               hintText: '',
     116             :                             )
     117             :                           ]),
     118             : 
     119           0 :                           Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
     120           0 :                             SizedBox(
     121             :                               height: 20,
     122             :                             ),
     123           0 :                             CwtchLabel(label: AppLocalizations.of(context)!.conversationSettings),
     124           0 :                             SizedBox(
     125             :                               height: 20,
     126             :                             ),
     127           0 :                             ListTile(
     128           0 :                                 title: Text(AppLocalizations.of(context)!.conversationNotificationPolicySettingLabel, style: TextStyle(color: settings.current().mainTextColor)),
     129           0 :                                 subtitle: Text(AppLocalizations.of(context)!.conversationNotificationPolicySettingDescription),
     130           0 :                                 leading: Icon(CwtchIcons.chat_bubble_empty_24px, color: settings.current().mainTextColor),
     131           0 :                                 trailing: DropdownButton(
     132           0 :                                   value: Provider.of<ContactInfoState>(context).notificationsPolicy,
     133           0 :                                   items: ConversationNotificationPolicy.values.map<DropdownMenuItem<ConversationNotificationPolicy>>((ConversationNotificationPolicy value) {
     134           0 :                                     return DropdownMenuItem<ConversationNotificationPolicy>(
     135             :                                       value: value,
     136           0 :                                       child: Text(value.toName(context), style: settings.scaleFonts(defaultDropDownMenuItemTextStyle)),
     137             :                                     );
     138           0 :                                   }).toList(),
     139           0 :                                   onChanged: (ConversationNotificationPolicy? newVal) {
     140           0 :                                     Provider.of<ContactInfoState>(context, listen: false).notificationsPolicy = newVal!;
     141           0 :                                     var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
     142           0 :                                     var identifier = Provider.of<ContactInfoState>(context, listen: false).identifier;
     143             :                                     const NotificationPolicyKey = "profile.notification-policy";
     144           0 :                                     Provider.of<FlwtchState>(context, listen: false).cwtch.SetConversationAttribute(profileOnion, identifier, NotificationPolicyKey, newVal.toString());
     145             :                                   },
     146             :                                 )),
     147             :                           ]),
     148             : 
     149           0 :                           Column(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.end, children: [
     150           0 :                             SizedBox(
     151             :                               height: 20,
     152             :                             ),
     153           0 :                             Tooltip(
     154           0 :                                 message: AppLocalizations.of(context)!.archiveConversation,
     155           0 :                                 child: OutlinedButton.icon(
     156           0 :                                   onPressed: () {
     157           0 :                                     var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
     158           0 :                                     var handle = Provider.of<ContactInfoState>(context, listen: false).identifier;
     159             :                                     // locally update cache...
     160           0 :                                     Provider.of<ContactInfoState>(context, listen: false).isArchived = true;
     161           0 :                                     Provider.of<FlwtchState>(context, listen: false).cwtch.ArchiveConversation(profileOnion, handle);
     162           0 :                                     Future.delayed(Duration(milliseconds: 500), () {
     163           0 :                                       Provider.of<AppState>(context, listen: false).selectedConversation = null;
     164           0 :                                       Navigator.of(context).popUntil((route) => route.settings.name == "conversations"); // dismiss dialog
     165             :                                     });
     166             :                                   },
     167           0 :                                   icon: Icon(CwtchIcons.leave_chat),
     168           0 :                                   label: Text(AppLocalizations.of(context)!.archiveConversation),
     169             :                                 )),
     170           0 :                             SizedBox(
     171             :                               height: 20,
     172             :                             ),
     173           0 :                             Row(crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.end, children: [
     174           0 :                               Tooltip(
     175           0 :                                   message: AppLocalizations.of(context)!.leaveConversation,
     176           0 :                                   child: OutlinedButton.icon(
     177           0 :                                     onPressed: () {
     178           0 :                                       showAlertDialog(context);
     179             :                                     },
     180           0 :                                     icon: Icon(CwtchIcons.leave_group),
     181           0 :                                     label: Text(
     182           0 :                                       AppLocalizations.of(context)!.leaveConversation,
     183             :                                     ),
     184             :                                   ))
     185             :                             ])
     186             :                           ])
     187             :                         ])))));
     188             :       });
     189             :     });
     190             :   }
     191             : 
     192           0 :   void _copyOnion() {
     193           0 :     Clipboard.setData(new ClipboardData(text: Provider.of<ContactInfoState>(context, listen: false).onion));
     194           0 :     final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.copiedToClipboardNotification));
     195           0 :     ScaffoldMessenger.of(context).showSnackBar(snackBar);
     196             :   }
     197             : 
     198           0 :   showAlertDialog(BuildContext context) {
     199             :     // set up the buttons
     200           0 :     Widget cancelButton = ElevatedButton(
     201           0 :       child: Text(AppLocalizations.of(context)!.cancel),
     202           0 :       onPressed: () {
     203           0 :         Navigator.of(context).pop(); // dismiss dialog
     204             :       },
     205             :     );
     206           0 :     Widget continueButton = ElevatedButton(
     207           0 :       style: ButtonStyle(padding: MaterialStateProperty.all(EdgeInsets.all(20))),
     208           0 :       child: Text(AppLocalizations.of(context)!.yesLeave),
     209           0 :       onPressed: () {
     210           0 :         var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
     211           0 :         var identifier = Provider.of<ContactInfoState>(context, listen: false).identifier;
     212             :         // locally update cache...
     213           0 :         Provider.of<ContactInfoState>(context, listen: false).isArchived = true;
     214           0 :         Provider.of<ProfileInfoState>(context, listen: false).contactList.removeContact(identifier);
     215           0 :         Provider.of<FlwtchState>(context, listen: false).cwtch.DeleteContact(profileOnion, identifier);
     216           0 :         Future.delayed(Duration(milliseconds: 500), () {
     217           0 :           Provider.of<AppState>(context, listen: false).selectedConversation = null;
     218           0 :           Navigator.of(context).popUntil((route) => route.settings.name == "conversations"); // dismiss dialog
     219             :         });
     220             :       },
     221             :     );
     222             : 
     223             :     // set up the AlertDialog
     224           0 :     AlertDialog alert = AlertDialog(
     225           0 :       title: Text(AppLocalizations.of(context)!.reallyLeaveThisGroupPrompt),
     226           0 :       actions: [
     227             :         cancelButton,
     228             :         continueButton,
     229             :       ],
     230             :     );
     231             : 
     232             :     // show the dialog
     233           0 :     showDialog(
     234             :       context: context,
     235           0 :       builder: (BuildContext context) {
     236             :         return alert;
     237             :       },
     238             :     );
     239             :   }
     240             : }

Generated by: LCOV version 1.14