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 : padding: EdgeInsets.symmetric(vertical: 0, horizontal: 20),
34 0 : child: ConstrainedBox(
35 0 : constraints: BoxConstraints(
36 0 : minHeight: viewportConstraints.maxHeight,
37 : ),
38 0 : child: Column(children: [
39 0 : SwitchListTile(
40 0 : title: Text(AppLocalizations.of(context)!.experimentsEnabled),
41 0 : subtitle: Text(AppLocalizations.of(context)!.descriptionExperiments),
42 0 : value: settings.experimentsEnabled,
43 0 : onChanged: (bool value) {
44 : if (value) {
45 0 : settings.enableExperiments();
46 : } else {
47 0 : settings.disableExperiments();
48 : }
49 : // Save Settings...
50 0 : saveSettings(context);
51 : },
52 0 : activeTrackColor: settings.theme.defaultButtonColor,
53 0 : inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
54 0 : secondary: Icon(CwtchIcons.enable_experiments, color: settings.current().mainTextColor),
55 : ),
56 0 : Visibility(
57 0 : visible: settings.experimentsEnabled,
58 0 : child: Column(
59 0 : children: [
60 0 : SwitchListTile(
61 0 : title: Text(AppLocalizations.of(context)!.enableGroups),
62 0 : subtitle: Text(AppLocalizations.of(context)!.descriptionExperimentsGroups),
63 0 : value: settings.isExperimentEnabled(TapirGroupsExperiment),
64 0 : onChanged: (bool value) {
65 : if (value) {
66 0 : settings.enableExperiment(TapirGroupsExperiment);
67 : } else {
68 0 : settings.disableExperiment(TapirGroupsExperiment);
69 : }
70 : // Save Settings...
71 0 : saveSettings(context);
72 : },
73 0 : activeTrackColor: settings.theme.defaultButtonColor,
74 0 : inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
75 0 : secondary: Icon(CwtchIcons.enable_groups, color: settings.current().mainTextColor),
76 : ),
77 0 : Visibility(
78 0 : visible: !Platform.isAndroid && !Platform.isIOS,
79 0 : child: SwitchListTile(
80 0 : title: Text(AppLocalizations.of(context)!.settingServers),
81 0 : subtitle: Provider.of<FlwtchState>(context, listen: false).cwtch.IsServersCompiled()
82 0 : ? Text(AppLocalizations.of(context)!.settingServersDescription)
83 0 : : Text("This version of Cwtch has been compiled without support for the server hosting experiment."),
84 0 : value: Provider.of<FlwtchState>(context, listen: false).cwtch.IsServersCompiled() && settings.isExperimentEnabled(ServerManagementExperiment),
85 0 : onChanged: Provider.of<FlwtchState>(context, listen: false).cwtch.IsServersCompiled()
86 0 : ? (bool value) {
87 0 : Provider.of<ServerListState>(context, listen: false).clear();
88 : if (value) {
89 0 : settings.enableExperiment(ServerManagementExperiment);
90 : } else {
91 0 : settings.disableExperiment(ServerManagementExperiment);
92 : }
93 : // Save Settings...
94 0 : saveSettings(context);
95 : }
96 : : null,
97 0 : activeTrackColor: settings.theme.defaultButtonColor,
98 0 : inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
99 0 : inactiveThumbColor: settings.theme.defaultButtonDisabledColor,
100 0 : secondary: Icon(CwtchIcons.dns_24px),
101 : )),
102 0 : SwitchListTile(
103 0 : title: Text(AppLocalizations.of(context)!.settingFileSharing),
104 0 : subtitle: Text(AppLocalizations.of(context)!.descriptionFileSharing),
105 0 : value: settings.isExperimentEnabled(FileSharingExperiment),
106 0 : onChanged: (bool value) {
107 : if (value) {
108 0 : if (checkDownloadDirectory(context, settings)) {
109 0 : settings.enableExperiment(FileSharingExperiment);
110 : } else {
111 0 : settings.enableExperiment(FileSharingExperiment);
112 0 : settings.disableExperiment(ImagePreviewsExperiment);
113 : }
114 : } else {
115 0 : settings.disableExperiment(FileSharingExperiment);
116 0 : settings.disableExperiment(ImagePreviewsExperiment);
117 : }
118 0 : saveSettings(context);
119 : },
120 0 : activeTrackColor: settings.theme.defaultButtonColor,
121 0 : inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
122 0 : secondary: Icon(CwtchIcons.attached_file_3, color: settings.current().mainTextColor),
123 : ),
124 0 : Visibility(
125 0 : visible: settings.isExperimentEnabled(FileSharingExperiment),
126 0 : child: Column(children: [
127 0 : SwitchListTile(
128 0 : title: Text(AppLocalizations.of(context)!.settingImagePreviews),
129 0 : subtitle: Text(AppLocalizations.of(context)!.settingImagePreviewsDescription),
130 0 : value: settings.isExperimentEnabled(ImagePreviewsExperiment),
131 0 : onChanged: (bool value) {
132 : if (value) {
133 0 : if (checkDownloadDirectory(context, settings)) {
134 0 : settings.enableExperiment(ImagePreviewsExperiment);
135 : } else {
136 0 : settings.disableExperiment(ImagePreviewsExperiment);
137 : }
138 : } else {
139 0 : settings.disableExperiment(ImagePreviewsExperiment);
140 : }
141 0 : saveSettings(context);
142 : },
143 0 : activeTrackColor: settings.theme.defaultButtonActiveColor,
144 0 : inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
145 0 : secondary: Icon(Icons.photo, color: settings.current().mainTextColor),
146 : ),
147 0 : Visibility(
148 0 : visible: settings.isExperimentEnabled(ImagePreviewsExperiment) && !Platform.isAndroid,
149 0 : child: CwtchFolderPicker(
150 0 : testKey: Key("DownloadFolderPicker"),
151 0 : label: AppLocalizations.of(context)!.settingDownloadFolder,
152 0 : initialValue: settings.downloadPath,
153 0 : textStyle: settings.scaleFonts(defaultDropDownMenuItemTextStyle),
154 0 : description: AppLocalizations.of(context)!.fileSharingSettingsDownloadFolderDescription,
155 0 : tooltip: AppLocalizations.of(context)!.fileSharingSettingsDownloadFolderTooltip,
156 0 : onSave: (newVal) {
157 0 : settings.downloadPath = newVal;
158 0 : saveSettings(context);
159 : },
160 : ),
161 : ),
162 : ]),
163 : ),
164 0 : Visibility(
165 0 : visible: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported(),
166 0 : child: SwitchListTile(
167 0 : title: Text(AppLocalizations.of(context)!.blodeuweddExperimentEnable),
168 0 : subtitle: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported()
169 0 : ? Text(AppLocalizations.of(context)!.blodeuweddDescription)
170 0 : : Text(AppLocalizations.of(context)!.blodeuweddNotSupported),
171 0 : value: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported() && settings.isExperimentEnabled(BlodeuweddExperiment),
172 0 : onChanged: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported()
173 0 : ? (bool value) {
174 : if (value) {
175 0 : settings.enableExperiment(BlodeuweddExperiment);
176 : } else {
177 0 : settings.disableExperiment(BlodeuweddExperiment);
178 : }
179 0 : saveSettings(context);
180 : }
181 : : null,
182 0 : activeTrackColor: settings.theme.defaultButtonColor,
183 0 : inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
184 0 : inactiveThumbColor: settings.theme.defaultButtonDisabledColor,
185 0 : secondary: Icon(Icons.assistant, color: settings.current().mainTextColor),
186 : )),
187 0 : Visibility(
188 0 : visible: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported() && settings.isExperimentEnabled(BlodeuweddExperiment),
189 0 : child: CwtchFolderPicker(
190 0 : testKey: Key("DownloadFolderPicker"),
191 0 : label: AppLocalizations.of(context)!.settingDownloadFolder,
192 0 : initialValue: settings.blodeuweddPath,
193 0 : description: AppLocalizations.of(context)!.blodeuweddPath,
194 0 : tooltip: AppLocalizations.of(context)!.blodeuweddPath,
195 0 : onSave: (newVal) {
196 0 : settings.blodeuweddPath = newVal;
197 0 : saveSettings(context);
198 : },
199 : ),
200 : ),
201 : ],
202 : )),
203 0 : Visibility(
204 0 : visible: settings.experimentsEnabled,
205 0 : child: SwitchListTile(
206 0 : title: Text(AppLocalizations.of(context)!.enableExperimentClickableLinks),
207 0 : subtitle: Text(AppLocalizations.of(context)!.experimentClickableLinksDescription),
208 0 : value: settings.isExperimentEnabled(ClickableLinksExperiment),
209 0 : onChanged: (bool value) {
210 : if (value) {
211 0 : settings.enableExperiment(ClickableLinksExperiment);
212 : } else {
213 0 : settings.disableExperiment(ClickableLinksExperiment);
214 : }
215 0 : saveSettings(context);
216 : },
217 0 : activeTrackColor: settings.theme.defaultButtonActiveColor,
218 0 : inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
219 0 : secondary: Icon(Icons.link, color: settings.current().mainTextColor),
220 : )),
221 0 : Visibility(
222 0 : visible: settings.experimentsEnabled,
223 0 : child: SwitchListTile(
224 0 : title: Text(AppLocalizations.of(context)!.enableExperimentQRCode),
225 0 : subtitle: Text(AppLocalizations.of(context)!.experimentQRCodeDescription),
226 0 : value: settings.isExperimentEnabled(QRCodeExperiment),
227 0 : onChanged: (bool value) {
228 : if (value) {
229 0 : settings.enableExperiment(QRCodeExperiment);
230 : } else {
231 0 : settings.disableExperiment(QRCodeExperiment);
232 : }
233 0 : saveSettings(context);
234 : },
235 0 : activeTrackColor: settings.theme.defaultButtonActiveColor,
236 0 : inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
237 0 : secondary: Icon(Icons.qr_code, color: settings.current().mainTextColor),
238 : )),
239 : ]))));
240 : });
241 : });
242 : }
243 :
244 0 : bool checkDownloadDirectory(context, settings) {
245 : bool showError = false;
246 0 : if (settings.downloadPath != "") {
247 : } else {
248 : // check if the default download path exists
249 0 : var path = Provider.of<FlwtchState>(context, listen: false).cwtch.defaultDownloadPath();
250 : if (path != null) {
251 0 : settings.downloadPath = path;
252 : } else {
253 : showError = true;
254 : }
255 : }
256 :
257 0 : if (!showError && Directory(settings.downloadPath).existsSync()) {
258 : return true;
259 : } else {
260 0 : final snackBar = SnackBar(
261 0 : content: Text(AppLocalizations.of(context)!.errorDownloadDirectoryDoesNotExist),
262 : );
263 0 : ScaffoldMessenger.of(context).showSnackBar(snackBar);
264 : return false;
265 : }
266 : }
267 : }
|