LCOV - code coverage report
Current view: top level - lib/views - globalsettingsexperimentsview.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 162 0.0 %
Date: 2024-09-24 21:50:54 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:io';
       2             : 
       3             : import 'package:flutter/material.dart';
       4             : import 'package:provider/provider.dart';
       5             : import 'package:flutter_gen/gen_l10n/app_localizations.dart';
       6             : 
       7             : import '../cwtch_icons_icons.dart';
       8             : import '../main.dart';
       9             : import '../models/servers.dart';
      10             : import '../settings.dart';
      11             : import '../themes/opaque.dart';
      12             : import '../widgets/folderpicker.dart';
      13             : import 'globalsettingsview.dart';
      14             : 
      15             : class GlobalSettingsExperimentsView extends StatefulWidget {
      16           0 :   @override
      17           0 :   _GlobalSettingsExperimentsViewState createState() => _GlobalSettingsExperimentsViewState();
      18             : }
      19             : 
      20             : class _GlobalSettingsExperimentsViewState extends State<GlobalSettingsExperimentsView> {
      21             :   ScrollController settingsListScrollController = ScrollController();
      22             : 
      23           0 :   Widget build(BuildContext context) {
      24           0 :     return Consumer<Settings>(builder: (ccontext, settings, child) {
      25           0 :       return LayoutBuilder(builder: (BuildContext context, BoxConstraints viewportConstraints) {
      26           0 :         return Scrollbar(
      27           0 :             key: Key("ExperimentsSettingsView"),
      28             :             trackVisibility: true,
      29           0 :             controller: settingsListScrollController,
      30           0 :             child: SingleChildScrollView(
      31             :                 clipBehavior: Clip.antiAlias,
      32           0 :                 controller: settingsListScrollController,
      33           0 :                 child: ConstrainedBox(
      34           0 :                     constraints: BoxConstraints(minHeight: viewportConstraints.maxHeight, maxWidth: viewportConstraints.maxWidth),
      35           0 :                     child: Container(
      36           0 :                         color: settings.theme.backgroundPaneColor,
      37           0 :                         child: Column(children: [
      38           0 :                           SwitchListTile(
      39           0 :                             title: Text(AppLocalizations.of(context)!.experimentsEnabled),
      40           0 :                             subtitle: Text(AppLocalizations.of(context)!.descriptionExperiments),
      41           0 :                             value: settings.experimentsEnabled,
      42           0 :                             onChanged: (bool value) {
      43             :                               if (value) {
      44           0 :                                 settings.enableExperiments();
      45             :                               } else {
      46           0 :                                 settings.disableExperiments();
      47             :                               }
      48             :                               // Save Settings...
      49           0 :                               saveSettings(context);
      50             :                             },
      51           0 :                             activeTrackColor: settings.theme.defaultButtonColor,
      52           0 :                             inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
      53           0 :                             secondary: Icon(CwtchIcons.enable_experiments, color: settings.current().mainTextColor),
      54             :                           ),
      55           0 :                           Visibility(
      56           0 :                               visible: settings.experimentsEnabled,
      57           0 :                               child: Column(
      58           0 :                                 children: [
      59           0 :                                   SwitchListTile(
      60           0 :                                     title: Text(AppLocalizations.of(context)!.enableGroups),
      61           0 :                                     subtitle: Text(AppLocalizations.of(context)!.descriptionExperimentsGroups),
      62           0 :                                     value: settings.isExperimentEnabled(TapirGroupsExperiment),
      63           0 :                                     onChanged: (bool value) {
      64             :                                       if (value) {
      65           0 :                                         settings.enableExperiment(TapirGroupsExperiment);
      66             :                                       } else {
      67           0 :                                         settings.disableExperiment(TapirGroupsExperiment);
      68             :                                       }
      69             :                                       // Save Settings...
      70           0 :                                       saveSettings(context);
      71             :                                     },
      72           0 :                                     activeTrackColor: settings.theme.defaultButtonColor,
      73           0 :                                     inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
      74           0 :                                     secondary: Icon(CwtchIcons.enable_groups, color: settings.current().mainTextColor),
      75             :                                   ),
      76           0 :                                   Visibility(
      77           0 :                                       visible: !Platform.isAndroid && !Platform.isIOS,
      78           0 :                                       child: SwitchListTile(
      79           0 :                                         title: Text(AppLocalizations.of(context)!.settingServers),
      80           0 :                                         subtitle: Provider.of<FlwtchState>(context, listen: false).cwtch.IsServersCompiled()
      81           0 :                                             ? Text(AppLocalizations.of(context)!.settingServersDescription)
      82           0 :                                             : Text("This version of Cwtch has been compiled without support for the server hosting experiment."),
      83           0 :                                         value: Provider.of<FlwtchState>(context, listen: false).cwtch.IsServersCompiled() && settings.isExperimentEnabled(ServerManagementExperiment),
      84           0 :                                         onChanged: Provider.of<FlwtchState>(context, listen: false).cwtch.IsServersCompiled()
      85           0 :                                             ? (bool value) {
      86           0 :                                                 Provider.of<ServerListState>(context, listen: false).clear();
      87             :                                                 if (value) {
      88           0 :                                                   settings.enableExperiment(ServerManagementExperiment);
      89             :                                                 } else {
      90           0 :                                                   settings.disableExperiment(ServerManagementExperiment);
      91             :                                                 }
      92             :                                                 // Save Settings...
      93           0 :                                                 saveSettings(context);
      94             :                                               }
      95             :                                             : null,
      96           0 :                                         activeTrackColor: settings.theme.defaultButtonColor,
      97           0 :                                         inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
      98           0 :                                         secondary: Icon(CwtchIcons.dns_24px),
      99             :                                       )),
     100           0 :                                   SwitchListTile(
     101           0 :                                     title: Text(AppLocalizations.of(context)!.settingFileSharing),
     102           0 :                                     subtitle: Text(AppLocalizations.of(context)!.descriptionFileSharing),
     103           0 :                                     value: settings.isExperimentEnabled(FileSharingExperiment),
     104           0 :                                     onChanged: (bool value) {
     105             :                                       if (value) {
     106           0 :                                         if (checkDownloadDirectory(context, settings)) {
     107           0 :                                           settings.enableExperiment(FileSharingExperiment);
     108             :                                         } else {
     109           0 :                                           settings.enableExperiment(FileSharingExperiment);
     110           0 :                                           settings.disableExperiment(ImagePreviewsExperiment);
     111             :                                         }
     112             :                                       } else {
     113           0 :                                         settings.disableExperiment(FileSharingExperiment);
     114           0 :                                         settings.disableExperiment(ImagePreviewsExperiment);
     115             :                                       }
     116           0 :                                       saveSettings(context);
     117             :                                     },
     118           0 :                                     activeTrackColor: settings.theme.defaultButtonColor,
     119           0 :                                     inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     120           0 :                                     secondary: Icon(CwtchIcons.attached_file_3, color: settings.current().mainTextColor),
     121             :                                   ),
     122           0 :                                   Visibility(
     123           0 :                                     visible: settings.isExperimentEnabled(FileSharingExperiment),
     124           0 :                                     child: Column(children: [
     125           0 :                                       SwitchListTile(
     126           0 :                                         title: Text(AppLocalizations.of(context)!.settingImagePreviews),
     127           0 :                                         subtitle: Text(AppLocalizations.of(context)!.settingImagePreviewsDescription),
     128           0 :                                         value: settings.isExperimentEnabled(ImagePreviewsExperiment),
     129           0 :                                         onChanged: (bool value) {
     130             :                                           if (value) {
     131           0 :                                             if (checkDownloadDirectory(context, settings)) {
     132           0 :                                               settings.enableExperiment(ImagePreviewsExperiment);
     133             :                                             } else {
     134           0 :                                               settings.disableExperiment(ImagePreviewsExperiment);
     135             :                                             }
     136             :                                           } else {
     137           0 :                                             settings.disableExperiment(ImagePreviewsExperiment);
     138             :                                           }
     139           0 :                                           saveSettings(context);
     140             :                                         },
     141           0 :                                         activeTrackColor: settings.theme.defaultButtonColor,
     142           0 :                                         inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     143           0 :                                         secondary: Icon(Icons.photo, color: settings.current().mainTextColor),
     144             :                                       ),
     145           0 :                                       Visibility(
     146           0 :                                         visible: settings.isExperimentEnabled(ImagePreviewsExperiment) && !Platform.isAndroid,
     147           0 :                                         child: CwtchFolderPicker(
     148           0 :                                           testKey: Key("DownloadFolderPicker"),
     149           0 :                                           label: AppLocalizations.of(context)!.settingDownloadFolder,
     150           0 :                                           initialValue: settings.downloadPath,
     151           0 :                                           textStyle: settings.scaleFonts(defaultDropDownMenuItemTextStyle),
     152           0 :                                           description: AppLocalizations.of(context)!.fileSharingSettingsDownloadFolderDescription,
     153           0 :                                           tooltip: AppLocalizations.of(context)!.fileSharingSettingsDownloadFolderTooltip,
     154           0 :                                           onSave: (newVal) {
     155           0 :                                             settings.downloadPath = newVal;
     156           0 :                                             saveSettings(context);
     157             :                                           },
     158             :                                         ),
     159             :                                       ),
     160             :                                     ]),
     161             :                                   ),
     162           0 :                                   Visibility(
     163           0 :                                       visible: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported(),
     164           0 :                                       child: SwitchListTile(
     165           0 :                                         title: Text(AppLocalizations.of(context)!.blodeuweddExperimentEnable),
     166           0 :                                         subtitle: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported()
     167           0 :                                             ? Text(AppLocalizations.of(context)!.blodeuweddDescription)
     168           0 :                                             : Text(AppLocalizations.of(context)!.blodeuweddNotSupported),
     169           0 :                                         value: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported() && settings.isExperimentEnabled(BlodeuweddExperiment),
     170           0 :                                         onChanged: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported()
     171           0 :                                             ? (bool value) {
     172             :                                                 if (value) {
     173           0 :                                                   settings.enableExperiment(BlodeuweddExperiment);
     174             :                                                 } else {
     175           0 :                                                   settings.disableExperiment(BlodeuweddExperiment);
     176             :                                                 }
     177           0 :                                                 saveSettings(context);
     178             :                                               }
     179             :                                             : null,
     180           0 :                                         activeTrackColor: settings.theme.defaultButtonColor,
     181           0 :                                         inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     182           0 :                                         secondary: Icon(Icons.assistant, color: settings.current().mainTextColor),
     183             :                                       )),
     184           0 :                                   Visibility(
     185           0 :                                     visible: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported() && settings.isExperimentEnabled(BlodeuweddExperiment),
     186           0 :                                     child: CwtchFolderPicker(
     187           0 :                                       testKey: Key("DownloadFolderPicker"),
     188           0 :                                       label: AppLocalizations.of(context)!.settingDownloadFolder,
     189           0 :                                       initialValue: settings.blodeuweddPath,
     190           0 :                                       description: AppLocalizations.of(context)!.blodeuweddPath,
     191           0 :                                       tooltip: AppLocalizations.of(context)!.blodeuweddPath,
     192           0 :                                       onSave: (newVal) {
     193           0 :                                         settings.blodeuweddPath = newVal;
     194           0 :                                         saveSettings(context);
     195             :                                       },
     196             :                                     ),
     197             :                                   ),
     198             :                                 ],
     199             :                               )),
     200           0 :                           Visibility(
     201           0 :                               visible: settings.experimentsEnabled,
     202           0 :                               child: SwitchListTile(
     203           0 :                                 title: Text(AppLocalizations.of(context)!.enableExperimentClickableLinks),
     204           0 :                                 subtitle: Text(AppLocalizations.of(context)!.experimentClickableLinksDescription),
     205           0 :                                 value: settings.isExperimentEnabled(ClickableLinksExperiment),
     206           0 :                                 onChanged: (bool value) {
     207             :                                   if (value) {
     208           0 :                                     settings.enableExperiment(ClickableLinksExperiment);
     209             :                                   } else {
     210           0 :                                     settings.disableExperiment(ClickableLinksExperiment);
     211             :                                   }
     212           0 :                                   saveSettings(context);
     213             :                                 },
     214           0 :                                 activeTrackColor: settings.theme.defaultButtonColor,
     215           0 :                                 inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     216           0 :                                 secondary: Icon(Icons.link, color: settings.current().mainTextColor),
     217             :                               )),
     218           0 :                           Visibility(
     219           0 :                               visible: settings.experimentsEnabled,
     220           0 :                               child: SwitchListTile(
     221           0 :                                 title: Text(AppLocalizations.of(context)!.enableExperimentQRCode),
     222           0 :                                 subtitle: Text(AppLocalizations.of(context)!.experimentQRCodeDescription),
     223           0 :                                 value: settings.isExperimentEnabled(QRCodeExperiment),
     224           0 :                                 onChanged: (bool value) {
     225             :                                   if (value) {
     226           0 :                                     settings.enableExperiment(QRCodeExperiment);
     227             :                                   } else {
     228           0 :                                     settings.disableExperiment(QRCodeExperiment);
     229             :                                   }
     230           0 :                                   saveSettings(context);
     231             :                                 },
     232           0 :                                 activeTrackColor: settings.theme.defaultButtonColor,
     233           0 :                                 inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     234           0 :                                 secondary: Icon(Icons.qr_code, color: settings.current().mainTextColor),
     235             :                               )),
     236             :                         ])))));
     237             :       });
     238             :     });
     239             :   }
     240             : 
     241           0 :   bool checkDownloadDirectory(context, settings) {
     242             :     bool showError = false;
     243           0 :     if (settings.downloadPath != "") {
     244             :     } else {
     245             :       // check if the default download path exists
     246           0 :       var path = Provider.of<FlwtchState>(context, listen: false).cwtch.defaultDownloadPath();
     247             :       if (path != null) {
     248           0 :         settings.downloadPath = path;
     249             :       } else {
     250             :         showError = true;
     251             :       }
     252             :     }
     253             : 
     254           0 :     if (!showError && Directory(settings.downloadPath).existsSync()) {
     255             :       return true;
     256             :     } else {
     257           0 :       final snackBar = SnackBar(
     258           0 :         content: Text(AppLocalizations.of(context)!.errorDownloadDirectoryDoesNotExist),
     259             :       );
     260           0 :       ScaffoldMessenger.of(context).showSnackBar(snackBar);
     261             :       return false;
     262             :     }
     263             :   }
     264             : }

Generated by: LCOV version 1.14