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