2021-06-24 23:10:45 +00:00
|
|
|
import 'dart:convert';
|
2021-11-03 19:53:32 +00:00
|
|
|
import 'dart:io';
|
2022-04-13 01:06:48 +00:00
|
|
|
import 'dart:math';
|
2021-06-24 23:10:45 +00:00
|
|
|
import 'package:cwtch/cwtch_icons_icons.dart';
|
2021-11-02 02:29:58 +00:00
|
|
|
import 'package:cwtch/models/servers.dart';
|
2021-12-14 21:33:30 +00:00
|
|
|
import 'package:cwtch/widgets/folderpicker.dart';
|
2021-12-15 20:17:13 +00:00
|
|
|
import 'package:cwtch/themes/cwtch.dart';
|
|
|
|
import 'package:cwtch/themes/ghost.dart';
|
|
|
|
import 'package:cwtch/themes/mermaid.dart';
|
|
|
|
import 'package:cwtch/themes/midnight.dart';
|
|
|
|
import 'package:cwtch/themes/neon1.dart';
|
|
|
|
import 'package:cwtch/themes/neon2.dart';
|
2021-12-10 04:22:55 +00:00
|
|
|
import 'package:cwtch/themes/opaque.dart';
|
2021-12-15 20:17:13 +00:00
|
|
|
import 'package:cwtch/themes/pumpkin.dart';
|
|
|
|
import 'package:cwtch/themes/vampire.dart';
|
|
|
|
import 'package:cwtch/themes/witch.dart';
|
2022-04-13 01:06:48 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2021-06-24 23:10:45 +00:00
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:cwtch/settings.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
|
|
|
import '../main.dart';
|
|
|
|
import '../config.dart';
|
|
|
|
|
|
|
|
/// Global Settings View provides access to modify all the Globally Relevant Settings including Locale, Theme and Experiments.
|
|
|
|
class GlobalSettingsView extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_GlobalSettingsViewState createState() => _GlobalSettingsViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _GlobalSettingsViewState extends State<GlobalSettingsView> {
|
2022-04-13 01:06:48 +00:00
|
|
|
static const androidSettingsChannel = const MethodChannel('androidSettings');
|
|
|
|
static const androidSettingsChangeChannel = const MethodChannel('androidSettingsChanged');
|
|
|
|
bool powerExempt = false;
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2022-04-13 01:06:48 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
androidSettingsChangeChannel.setMethodCallHandler(handleSettingsChanged);
|
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
2022-04-14 22:34:17 +00:00
|
|
|
isBatteryExempt().then((value) => setState(() {
|
|
|
|
powerExempt = value;
|
|
|
|
}));
|
2022-04-13 01:06:48 +00:00
|
|
|
} else {
|
|
|
|
powerExempt = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handler on method channel for MainActivity/onActivityResult to report the user choice when we ask for power exemption
|
|
|
|
Future<void> handleSettingsChanged(MethodCall call) async {
|
|
|
|
if (call.method == "powerExemptionChange") {
|
|
|
|
if (call.arguments) {
|
|
|
|
setState(() {
|
|
|
|
powerExempt = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//* Android Only Requests
|
|
|
|
|
|
|
|
Future<bool> isBatteryExempt() async {
|
|
|
|
return await androidSettingsChannel.invokeMethod('isBatteryExempt', {}) ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> requestBatteryExemption() async {
|
|
|
|
await androidSettingsChannel.invokeMethod('requestBatteryExemption', {});
|
|
|
|
return Future.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
//* End Android Only Requests
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(AppLocalizations.of(context)!.cwtchSettingsTitle),
|
|
|
|
),
|
|
|
|
body: _buildSettingsList(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildSettingsList() {
|
|
|
|
return Consumer<Settings>(builder: (context, settings, child) {
|
|
|
|
return LayoutBuilder(builder: (BuildContext context, BoxConstraints viewportConstraints) {
|
2021-12-10 04:22:55 +00:00
|
|
|
var appIcon = Icon(Icons.info, color: settings.current().mainTextColor);
|
2021-06-24 23:10:45 +00:00
|
|
|
return Scrollbar(
|
2022-02-05 00:37:25 +00:00
|
|
|
key: Key("SettingsView"),
|
2021-06-24 23:10:45 +00:00
|
|
|
isAlwaysShown: true,
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
clipBehavior: Clip.antiAlias,
|
2022-02-04 02:17:08 +00:00
|
|
|
padding: EdgeInsets.all(20),
|
2021-06-24 23:10:45 +00:00
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
minHeight: viewportConstraints.maxHeight,
|
|
|
|
),
|
|
|
|
child: Column(children: [
|
2022-02-08 21:54:17 +00:00
|
|
|
Row(mainAxisAlignment: MainAxisAlignment.center, children: [Text(AppLocalizations.of(context)!.settingsGroupAppearance, style: TextStyle(fontWeight: FontWeight.bold))]),
|
2021-06-24 23:10:45 +00:00
|
|
|
ListTile(
|
2021-12-10 04:22:55 +00:00
|
|
|
title: Text(AppLocalizations.of(context)!.settingLanguage, style: TextStyle(color: settings.current().mainTextColor)),
|
|
|
|
leading: Icon(CwtchIcons.change_language, color: settings.current().mainTextColor),
|
2022-04-29 16:56:56 +00:00
|
|
|
trailing: Container(
|
|
|
|
width: MediaQuery.of(context).size.width / 4,
|
|
|
|
child: DropdownButton(
|
2022-05-11 19:43:54 +00:00
|
|
|
isExpanded: true,
|
2022-04-29 16:56:56 +00:00
|
|
|
value: Provider.of<Settings>(context).locale.languageCode,
|
|
|
|
onChanged: (String? newValue) {
|
|
|
|
setState(() {
|
|
|
|
settings.switchLocale(Locale(newValue!));
|
|
|
|
saveSettings(context);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
items: AppLocalizations.supportedLocales.map<DropdownMenuItem<String>>((Locale value) {
|
|
|
|
return DropdownMenuItem<String>(
|
|
|
|
value: value.languageCode,
|
|
|
|
child: Text(getLanguageFull(context, value.languageCode)),
|
|
|
|
);
|
|
|
|
}).toList()))),
|
2021-06-24 23:10:45 +00:00
|
|
|
SwitchListTile(
|
2021-12-10 04:22:55 +00:00
|
|
|
title: Text(AppLocalizations.of(context)!.settingTheme, style: TextStyle(color: settings.current().mainTextColor)),
|
|
|
|
value: settings.current().mode == mode_light,
|
2021-06-24 23:10:45 +00:00
|
|
|
onChanged: (bool value) {
|
|
|
|
if (value) {
|
2021-12-10 04:22:55 +00:00
|
|
|
settings.setTheme(settings.theme.theme, mode_light);
|
2021-06-24 23:10:45 +00:00
|
|
|
} else {
|
2021-12-10 04:22:55 +00:00
|
|
|
settings.setTheme(settings.theme.theme, mode_dark);
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save Settings...
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
2021-12-11 05:07:47 +00:00
|
|
|
activeTrackColor: settings.theme.defaultButtonColor,
|
2021-12-10 04:22:55 +00:00
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(CwtchIcons.change_theme, color: settings.current().mainTextColor),
|
2021-06-24 23:10:45 +00:00
|
|
|
),
|
|
|
|
ListTile(
|
2021-12-15 22:29:27 +00:00
|
|
|
title: Text(AppLocalizations.of(context)!.themeColorLabel),
|
2022-04-29 16:56:56 +00:00
|
|
|
trailing: Container(
|
|
|
|
width: MediaQuery.of(context).size.width / 4,
|
|
|
|
child: DropdownButton<String>(
|
|
|
|
key: Key("DropdownTheme"),
|
2022-05-11 19:43:54 +00:00
|
|
|
isExpanded: true,
|
2022-04-29 16:56:56 +00:00
|
|
|
value: Provider.of<Settings>(context).theme.theme,
|
|
|
|
onChanged: (String? newValue) {
|
|
|
|
setState(() {
|
|
|
|
settings.setTheme(newValue!, settings.theme.mode);
|
|
|
|
saveSettings(context);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
items: themes.keys.map<DropdownMenuItem<String>>((String themeId) {
|
|
|
|
return DropdownMenuItem<String>(
|
|
|
|
value: themeId,
|
|
|
|
child: Text(getThemeName(context, themeId)), //"ddi_$themeId", key: Key("ddi_$themeId")),
|
|
|
|
);
|
|
|
|
}).toList())),
|
2022-05-31 20:37:32 +00:00
|
|
|
leading: Icon(Icons.palette, color: settings.current().mainTextColor),
|
2021-12-15 20:17:13 +00:00
|
|
|
),
|
2021-12-10 04:22:55 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text(AppLocalizations.of(context)!.settingUIColumnPortrait, style: TextStyle(color: settings.current().mainTextColor)),
|
|
|
|
leading: Icon(Icons.table_chart, color: settings.current().mainTextColor),
|
2022-02-14 19:00:46 +00:00
|
|
|
trailing: Container(
|
2022-02-14 19:03:28 +00:00
|
|
|
width: MediaQuery.of(context).size.width / 4,
|
2022-02-14 19:00:46 +00:00
|
|
|
child: DropdownButton(
|
2022-05-11 19:43:54 +00:00
|
|
|
isExpanded: true,
|
2022-04-29 16:56:56 +00:00
|
|
|
value: settings.uiColumnModePortrait.toString(),
|
2022-02-14 19:03:28 +00:00
|
|
|
onChanged: (String? newValue) {
|
2022-04-29 16:56:56 +00:00
|
|
|
settings.uiColumnModePortrait = Settings.uiColumnModeFromString(newValue!);
|
2022-02-14 19:03:28 +00:00
|
|
|
saveSettings(context);
|
|
|
|
},
|
2022-04-29 16:56:56 +00:00
|
|
|
items: Settings.uiColumnModeOptions(false).map<DropdownMenuItem<String>>((DualpaneMode value) {
|
2022-02-14 19:03:28 +00:00
|
|
|
return DropdownMenuItem<String>(
|
|
|
|
value: value.toString(),
|
2022-04-29 16:56:56 +00:00
|
|
|
child: Text(Settings.uiColumnModeToString(value, context)),
|
2022-02-14 19:03:28 +00:00
|
|
|
);
|
|
|
|
}).toList()))),
|
2022-04-29 16:56:56 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
AppLocalizations.of(context)!.settingUIColumnLandscape,
|
|
|
|
textWidthBasis: TextWidthBasis.longestLine,
|
|
|
|
softWrap: true,
|
|
|
|
style: TextStyle(color: settings.current().mainTextColor),
|
|
|
|
),
|
2022-05-31 20:37:32 +00:00
|
|
|
leading: Icon(Icons.stay_primary_landscape, color: settings.current().mainTextColor),
|
2022-04-29 16:56:56 +00:00
|
|
|
trailing: Container(
|
|
|
|
width: MediaQuery.of(context).size.width / 4,
|
|
|
|
child: Container(
|
|
|
|
width: MediaQuery.of(context).size.width / 4,
|
|
|
|
child: DropdownButton(
|
|
|
|
isExpanded: true,
|
|
|
|
value: settings.uiColumnModeLandscape.toString(),
|
|
|
|
onChanged: (String? newValue) {
|
|
|
|
settings.uiColumnModeLandscape = Settings.uiColumnModeFromString(newValue!);
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
|
|
|
items: Settings.uiColumnModeOptions(true).map<DropdownMenuItem<String>>((DualpaneMode value) {
|
|
|
|
return DropdownMenuItem<String>(
|
|
|
|
value: value.toString(),
|
|
|
|
child: Text(
|
|
|
|
Settings.uiColumnModeToString(value, context),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList())))),
|
2022-02-04 02:17:08 +00:00
|
|
|
SwitchListTile(
|
|
|
|
title: Text(AppLocalizations.of(context)!.streamerModeLabel, style: TextStyle(color: settings.current().mainTextColor)),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.descriptionStreamerMode),
|
|
|
|
value: settings.streamerMode,
|
|
|
|
onChanged: (bool value) {
|
|
|
|
settings.setStreamerMode(value);
|
|
|
|
// Save Settings...
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
|
|
|
activeTrackColor: settings.theme.defaultButtonColor,
|
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(CwtchIcons.streamer_bunnymask, color: settings.current().mainTextColor),
|
|
|
|
),
|
2022-06-22 21:22:52 +00:00
|
|
|
SwitchListTile(
|
|
|
|
title: Text(AppLocalizations.of(context)!.formattingExperiment, style: TextStyle(color: settings.current().mainTextColor)),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.messageFormattingDescription),
|
|
|
|
value: settings.isExperimentEnabled(FormattingExperiment),
|
|
|
|
onChanged: (bool value) {
|
|
|
|
if (value) {
|
|
|
|
settings.enableExperiment(FormattingExperiment);
|
|
|
|
} else {
|
|
|
|
settings.disableExperiment(FormattingExperiment);
|
|
|
|
}
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
|
|
|
activeTrackColor: settings.theme.defaultButtonActiveColor,
|
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(Icons.text_fields, color: settings.current().mainTextColor),
|
|
|
|
),
|
2022-02-04 02:17:08 +00:00
|
|
|
SizedBox(
|
|
|
|
height: 40,
|
|
|
|
),
|
2022-02-08 21:54:17 +00:00
|
|
|
Row(mainAxisAlignment: MainAxisAlignment.center, children: [Text(AppLocalizations.of(context)!.settingGroupBehaviour, style: TextStyle(fontWeight: FontWeight.bold))]),
|
2022-04-13 01:06:48 +00:00
|
|
|
Visibility(
|
|
|
|
visible: Platform.isAndroid,
|
2022-04-14 22:34:17 +00:00
|
|
|
child: SwitchListTile(
|
|
|
|
title: Text(AppLocalizations.of(context)!.settingAndroidPowerExemption, style: TextStyle(color: settings.current().mainTextColor)),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.settingAndroidPowerExemptionDescription),
|
|
|
|
value: powerExempt,
|
|
|
|
onChanged: (bool value) {
|
|
|
|
if (value) {
|
|
|
|
requestBatteryExemption();
|
|
|
|
} else {
|
|
|
|
// We can't ask for it to be turned off, show an informational popup
|
|
|
|
showBatteryDialog(context);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
activeTrackColor: settings.theme.defaultButtonColor,
|
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(Icons.power, color: settings.current().mainTextColor),
|
|
|
|
),
|
2022-04-13 01:06:48 +00:00
|
|
|
),
|
2022-02-04 02:17:08 +00:00
|
|
|
ListTile(
|
2022-02-08 21:54:17 +00:00
|
|
|
title: Text(AppLocalizations.of(context)!.notificationPolicySettingLabel),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.notificationPolicySettingDescription),
|
2022-04-29 16:56:56 +00:00
|
|
|
trailing: Container(
|
|
|
|
width: MediaQuery.of(context).size.width / 4,
|
|
|
|
child: DropdownButton(
|
2022-05-11 19:43:54 +00:00
|
|
|
isExpanded: true,
|
2022-04-29 16:56:56 +00:00
|
|
|
value: settings.notificationPolicy,
|
|
|
|
onChanged: (NotificationPolicy? newValue) {
|
|
|
|
settings.notificationPolicy = newValue!;
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
|
|
|
items: NotificationPolicy.values.map<DropdownMenuItem<NotificationPolicy>>((NotificationPolicy value) {
|
|
|
|
return DropdownMenuItem<NotificationPolicy>(
|
|
|
|
value: value,
|
|
|
|
child: Text(
|
|
|
|
Settings.notificationPolicyToString(value, context),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList())),
|
2022-02-04 02:17:08 +00:00
|
|
|
leading: Icon(CwtchIcons.chat_bubble_empty_24px, color: settings.current().mainTextColor),
|
|
|
|
),
|
|
|
|
ListTile(
|
2022-02-08 21:54:17 +00:00
|
|
|
title: Text(AppLocalizations.of(context)!.notificationContentSettingLabel),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.notificationContentSettingDescription),
|
2022-02-14 19:00:46 +00:00
|
|
|
trailing: Container(
|
2022-02-14 19:03:28 +00:00
|
|
|
width: MediaQuery.of(context).size.width / 4,
|
|
|
|
child: DropdownButton(
|
2022-02-16 21:49:29 +00:00
|
|
|
isExpanded: true,
|
2022-02-14 19:03:28 +00:00
|
|
|
value: settings.notificationContent,
|
|
|
|
onChanged: (NotificationContent? newValue) {
|
|
|
|
settings.notificationContent = newValue!;
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
|
|
|
items: NotificationContent.values.map<DropdownMenuItem<NotificationContent>>((NotificationContent value) {
|
|
|
|
return DropdownMenuItem<NotificationContent>(
|
|
|
|
value: value,
|
|
|
|
child: Text(
|
|
|
|
Settings.notificationContentToString(value, context),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList())),
|
2022-02-04 02:17:08 +00:00
|
|
|
leading: Icon(CwtchIcons.chat_bubble_empty_24px, color: settings.current().mainTextColor),
|
|
|
|
),
|
2021-06-24 23:10:45 +00:00
|
|
|
SwitchListTile(
|
2021-12-10 04:22:55 +00:00
|
|
|
title: Text(AppLocalizations.of(context)!.blockUnknownLabel, style: TextStyle(color: settings.current().mainTextColor)),
|
2021-06-24 23:10:45 +00:00
|
|
|
subtitle: Text(AppLocalizations.of(context)!.descriptionBlockUnknownConnections),
|
|
|
|
value: settings.blockUnknownConnections,
|
|
|
|
onChanged: (bool value) {
|
|
|
|
if (value) {
|
|
|
|
settings.forbidUnknownConnections();
|
|
|
|
} else {
|
|
|
|
settings.allowUnknownConnections();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save Settings...
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
2021-12-11 05:07:47 +00:00
|
|
|
activeTrackColor: settings.theme.defaultButtonColor,
|
2021-12-10 04:22:55 +00:00
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(CwtchIcons.block_unknown, color: settings.current().mainTextColor),
|
2021-06-24 23:10:45 +00:00
|
|
|
),
|
2022-02-04 02:17:08 +00:00
|
|
|
SizedBox(
|
|
|
|
height: 40,
|
2021-06-24 23:10:45 +00:00
|
|
|
),
|
2022-02-08 21:54:17 +00:00
|
|
|
Row(mainAxisAlignment: MainAxisAlignment.center, children: [Text(AppLocalizations.of(context)!.settingsGroupExperiments, style: TextStyle(fontWeight: FontWeight.bold))]),
|
2021-06-24 23:10:45 +00:00
|
|
|
SwitchListTile(
|
2021-12-10 04:22:55 +00:00
|
|
|
title: Text(AppLocalizations.of(context)!.experimentsEnabled, style: TextStyle(color: settings.current().mainTextColor)),
|
2021-06-24 23:10:45 +00:00
|
|
|
subtitle: Text(AppLocalizations.of(context)!.descriptionExperiments),
|
|
|
|
value: settings.experimentsEnabled,
|
|
|
|
onChanged: (bool value) {
|
|
|
|
if (value) {
|
|
|
|
settings.enableExperiments();
|
|
|
|
} else {
|
|
|
|
settings.disableExperiments();
|
|
|
|
}
|
|
|
|
// Save Settings...
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
2021-12-11 05:07:47 +00:00
|
|
|
activeTrackColor: settings.theme.defaultButtonColor,
|
2021-12-10 04:22:55 +00:00
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(CwtchIcons.enable_experiments, color: settings.current().mainTextColor),
|
2021-06-24 23:10:45 +00:00
|
|
|
),
|
|
|
|
Visibility(
|
|
|
|
visible: settings.experimentsEnabled,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
SwitchListTile(
|
2021-12-10 04:22:55 +00:00
|
|
|
title: Text(AppLocalizations.of(context)!.enableGroups, style: TextStyle(color: settings.current().mainTextColor)),
|
2021-06-24 23:10:45 +00:00
|
|
|
subtitle: Text(AppLocalizations.of(context)!.descriptionExperimentsGroups),
|
|
|
|
value: settings.isExperimentEnabled(TapirGroupsExperiment),
|
|
|
|
onChanged: (bool value) {
|
|
|
|
if (value) {
|
|
|
|
settings.enableExperiment(TapirGroupsExperiment);
|
|
|
|
} else {
|
|
|
|
settings.disableExperiment(TapirGroupsExperiment);
|
|
|
|
}
|
|
|
|
// Save Settings...
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
2021-12-11 05:07:47 +00:00
|
|
|
activeTrackColor: settings.theme.defaultButtonColor,
|
2021-12-10 04:22:55 +00:00
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(CwtchIcons.enable_groups, color: settings.current().mainTextColor),
|
2021-06-24 23:10:45 +00:00
|
|
|
),
|
2021-11-03 19:53:32 +00:00
|
|
|
Visibility(
|
2021-11-25 23:59:54 +00:00
|
|
|
visible: !Platform.isAndroid && !Platform.isIOS,
|
|
|
|
child: SwitchListTile(
|
2021-12-10 04:22:55 +00:00
|
|
|
title: Text(AppLocalizations.of(context)!.settingServers, style: TextStyle(color: settings.current().mainTextColor)),
|
2021-11-03 19:53:32 +00:00
|
|
|
subtitle: Text(AppLocalizations.of(context)!.settingServersDescription),
|
|
|
|
value: settings.isExperimentEnabled(ServerManagementExperiment),
|
|
|
|
onChanged: (bool value) {
|
|
|
|
Provider.of<ServerListState>(context, listen: false).clear();
|
|
|
|
if (value) {
|
|
|
|
settings.enableExperiment(ServerManagementExperiment);
|
|
|
|
} else {
|
|
|
|
settings.disableExperiment(ServerManagementExperiment);
|
|
|
|
}
|
|
|
|
// Save Settings...
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
2021-12-11 05:07:47 +00:00
|
|
|
activeTrackColor: settings.theme.defaultButtonColor,
|
2021-12-10 04:22:55 +00:00
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(CwtchIcons.dns_24px, color: settings.current().mainTextColor),
|
2021-11-03 19:53:32 +00:00
|
|
|
)),
|
2021-09-21 21:57:40 +00:00
|
|
|
SwitchListTile(
|
2021-12-10 04:22:55 +00:00
|
|
|
title: Text(AppLocalizations.of(context)!.settingFileSharing, style: TextStyle(color: settings.current().mainTextColor)),
|
2021-09-21 21:57:40 +00:00
|
|
|
subtitle: Text(AppLocalizations.of(context)!.descriptionFileSharing),
|
|
|
|
value: settings.isExperimentEnabled(FileSharingExperiment),
|
|
|
|
onChanged: (bool value) {
|
|
|
|
if (value) {
|
|
|
|
settings.enableExperiment(FileSharingExperiment);
|
|
|
|
} else {
|
|
|
|
settings.disableExperiment(FileSharingExperiment);
|
2022-02-07 20:23:26 +00:00
|
|
|
settings.disableExperiment(ImagePreviewsExperiment);
|
2021-09-21 21:57:40 +00:00
|
|
|
}
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
2021-12-11 05:07:47 +00:00
|
|
|
activeTrackColor: settings.theme.defaultButtonColor,
|
2021-12-10 04:22:55 +00:00
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(Icons.attach_file, color: settings.current().mainTextColor),
|
2021-09-21 21:57:40 +00:00
|
|
|
),
|
2021-12-14 21:33:30 +00:00
|
|
|
Visibility(
|
|
|
|
visible: settings.isExperimentEnabled(FileSharingExperiment),
|
2021-12-15 21:43:14 +00:00
|
|
|
child: Column(children: [
|
2021-12-14 21:33:30 +00:00
|
|
|
SwitchListTile(
|
2021-12-19 02:39:07 +00:00
|
|
|
title: Text(AppLocalizations.of(context)!.settingImagePreviews, style: TextStyle(color: settings.current().mainTextColor)),
|
2021-12-15 01:25:05 +00:00
|
|
|
subtitle: Text(AppLocalizations.of(context)!.settingImagePreviewsDescription),
|
2021-12-14 21:33:30 +00:00
|
|
|
value: settings.isExperimentEnabled(ImagePreviewsExperiment),
|
|
|
|
onChanged: (bool value) {
|
|
|
|
if (value) {
|
|
|
|
settings.enableExperiment(ImagePreviewsExperiment);
|
|
|
|
settings.downloadPath = Provider.of<FlwtchState>(context, listen: false).cwtch.defaultDownloadPath();
|
|
|
|
} else {
|
|
|
|
settings.disableExperiment(ImagePreviewsExperiment);
|
|
|
|
}
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
2021-12-19 02:39:07 +00:00
|
|
|
activeTrackColor: settings.theme.defaultButtonActiveColor,
|
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
2022-05-31 20:37:32 +00:00
|
|
|
secondary: Icon(Icons.photo, color: settings.current().mainTextColor),
|
2021-12-14 21:33:30 +00:00
|
|
|
),
|
|
|
|
Visibility(
|
2021-12-15 01:25:05 +00:00
|
|
|
visible: settings.isExperimentEnabled(ImagePreviewsExperiment) && !Platform.isAndroid,
|
2021-12-14 21:33:30 +00:00
|
|
|
child: CwtchFolderPicker(
|
2022-02-05 00:37:25 +00:00
|
|
|
testKey: Key("DownloadFolderPicker"),
|
2021-12-17 00:54:53 +00:00
|
|
|
label: AppLocalizations.of(context)!.settingDownloadFolder,
|
|
|
|
initialValue: settings.downloadPath,
|
2022-01-14 22:19:35 +00:00
|
|
|
description: AppLocalizations.of(context)!.fileSharingSettingsDownloadFolderDescription,
|
|
|
|
tooltip: AppLocalizations.of(context)!.fileSharingSettingsDownloadFolderTooltip,
|
2021-12-17 00:54:53 +00:00
|
|
|
onSave: (newVal) {
|
|
|
|
settings.downloadPath = newVal;
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
2021-12-14 21:33:30 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
2021-06-24 23:10:45 +00:00
|
|
|
],
|
|
|
|
)),
|
2022-01-14 22:19:35 +00:00
|
|
|
Visibility(
|
|
|
|
visible: settings.experimentsEnabled,
|
|
|
|
child: SwitchListTile(
|
|
|
|
title: Text(AppLocalizations.of(context)!.enableExperimentClickableLinks, style: TextStyle(color: settings.current().mainTextColor)),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.experimentClickableLinksDescription),
|
|
|
|
value: settings.isExperimentEnabled(ClickableLinksExperiment),
|
|
|
|
onChanged: (bool value) {
|
|
|
|
if (value) {
|
|
|
|
settings.enableExperiment(ClickableLinksExperiment);
|
|
|
|
} else {
|
|
|
|
settings.disableExperiment(ClickableLinksExperiment);
|
|
|
|
}
|
|
|
|
saveSettings(context);
|
|
|
|
},
|
|
|
|
activeTrackColor: settings.theme.defaultButtonActiveColor,
|
|
|
|
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
|
|
|
|
secondary: Icon(Icons.link, color: settings.current().mainTextColor),
|
2022-04-06 21:35:10 +00:00
|
|
|
)),
|
2021-06-24 23:10:45 +00:00
|
|
|
AboutListTile(
|
2021-07-14 17:29:46 +00:00
|
|
|
icon: appIcon,
|
|
|
|
applicationIcon: Padding(padding: EdgeInsets.all(5), child: Icon(CwtchIcons.cwtch_knott)),
|
|
|
|
applicationName: "Cwtch (Flutter UI)",
|
|
|
|
applicationLegalese: '\u{a9} 2021 Open Privacy Research Society',
|
|
|
|
aboutBoxChildren: <Widget>[
|
|
|
|
Padding(
|
2021-12-10 04:22:55 +00:00
|
|
|
padding: EdgeInsets.fromLTRB(24.0 + 10.0 + (appIcon.size ?? 24.0), 16.0, 0.0, 0.0),
|
|
|
|
// About has 24 padding (ln 389) and there appears to be another 10 of padding in the widget
|
2021-07-14 17:29:46 +00:00
|
|
|
child: SelectableText(AppLocalizations.of(context)!.versionBuilddate.replaceAll("%1", EnvironmentConfig.BUILD_VER).replaceAll("%2", EnvironmentConfig.BUILD_DATE)),
|
|
|
|
)
|
|
|
|
]),
|
2022-04-14 22:34:17 +00:00
|
|
|
Visibility(
|
|
|
|
visible: EnvironmentConfig.BUILD_VER == dev_version && !Platform.isAndroid,
|
|
|
|
child: FutureBuilder(
|
2022-04-26 19:16:09 +00:00
|
|
|
future: EnvironmentConfig.BUILD_VER != dev_version || Platform.isAndroid ? null : Provider.of<FlwtchState>(context).cwtch.GetDebugInfo(),
|
2022-04-14 22:34:17 +00:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
Text("libCwtch Debug Info: " + snapshot.data.toString()),
|
|
|
|
Text("Message Cache Size (Mb): " + (Provider.of<FlwtchState>(context).profs.cacheMemUsage() / (1024 * 1024)).toString())
|
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
2021-06-24 23:10:45 +00:00
|
|
|
]))));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-04-13 21:09:17 +00:00
|
|
|
|
|
|
|
showBatteryDialog(BuildContext context) {
|
|
|
|
Widget okButton = ElevatedButton(
|
2022-04-14 22:34:17 +00:00
|
|
|
child: Text(AppLocalizations.of(context)!.okButton),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
);
|
2022-04-13 21:09:17 +00:00
|
|
|
|
|
|
|
// set up the AlertDialog
|
|
|
|
AlertDialog alert = AlertDialog(
|
|
|
|
title: Text(AppLocalizations.of(context)!.settingsAndroidPowerReenablePopup),
|
|
|
|
actions: [
|
|
|
|
okButton,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
// show the dialog
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return alert;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Construct a version string from Package Info
|
|
|
|
String constructVersionString(PackageInfo pinfo) {
|
|
|
|
if (pinfo == null) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return pinfo.version + "." + pinfo.buildNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A slightly verbose way to extract the full language name from
|
|
|
|
/// an individual language code. There might be a more efficient way of doing this.
|
|
|
|
String getLanguageFull(context, String languageCode) {
|
|
|
|
if (languageCode == "en") {
|
|
|
|
return AppLocalizations.of(context)!.localeEn;
|
|
|
|
}
|
|
|
|
if (languageCode == "es") {
|
|
|
|
return AppLocalizations.of(context)!.localeEs;
|
|
|
|
}
|
|
|
|
if (languageCode == "fr") {
|
|
|
|
return AppLocalizations.of(context)!.localeFr;
|
|
|
|
}
|
|
|
|
if (languageCode == "pt") {
|
|
|
|
return AppLocalizations.of(context)!.localePt;
|
|
|
|
}
|
|
|
|
if (languageCode == "de") {
|
|
|
|
return AppLocalizations.of(context)!.localeDe;
|
|
|
|
}
|
2022-02-28 20:04:58 +00:00
|
|
|
if (languageCode == "el") {
|
|
|
|
return AppLocalizations.of(context)!.localeEl;
|
|
|
|
}
|
2021-06-24 23:10:45 +00:00
|
|
|
if (languageCode == "it") {
|
|
|
|
return AppLocalizations.of(context)!.localeIt;
|
|
|
|
}
|
2022-02-28 20:04:58 +00:00
|
|
|
if (languageCode == "no") {
|
|
|
|
return AppLocalizations.of(context)!.localeNo;
|
|
|
|
}
|
2021-07-07 22:35:13 +00:00
|
|
|
if (languageCode == "pl") {
|
|
|
|
return AppLocalizations.of(context)!.localePl;
|
|
|
|
}
|
2022-02-28 20:04:58 +00:00
|
|
|
if (languageCode == "lb") {
|
|
|
|
return AppLocalizations.of(context)!.localeLb;
|
|
|
|
}
|
2021-11-10 17:55:51 +00:00
|
|
|
if (languageCode == "ru") {
|
|
|
|
return AppLocalizations.of(context)!.localeRU;
|
|
|
|
}
|
2022-02-27 19:36:51 +00:00
|
|
|
if (languageCode == "ro") {
|
|
|
|
return AppLocalizations.of(context)!.localeRo;
|
|
|
|
}
|
2022-03-02 19:28:43 +00:00
|
|
|
if (languageCode == "cy") {
|
|
|
|
return AppLocalizations.of(context)!.localeCy;
|
|
|
|
}
|
2022-03-03 18:19:42 +00:00
|
|
|
if (languageCode == "da") {
|
|
|
|
return AppLocalizations.of(context)!.localeDa;
|
|
|
|
}
|
2022-07-29 22:20:01 +00:00
|
|
|
if (languageCode == "tr") {
|
|
|
|
return AppLocalizations.of(context)!.localeTr;
|
|
|
|
}
|
2021-06-24 23:10:45 +00:00
|
|
|
return languageCode;
|
|
|
|
}
|
|
|
|
|
2021-12-15 20:17:13 +00:00
|
|
|
/// Since we don't seem to able to dynamically pull translations, this function maps themes to their names
|
|
|
|
String getThemeName(context, String theme) {
|
|
|
|
switch (theme) {
|
2021-12-15 22:29:27 +00:00
|
|
|
case cwtch_theme:
|
|
|
|
return AppLocalizations.of(context)!.themeNameCwtch;
|
|
|
|
case ghost_theme:
|
|
|
|
return AppLocalizations.of(context)!.themeNameGhost;
|
|
|
|
case mermaid_theme:
|
|
|
|
return AppLocalizations.of(context)!.themeNameMermaid;
|
|
|
|
case midnight_theme:
|
|
|
|
return AppLocalizations.of(context)!.themeNameMidnight;
|
|
|
|
case neon1_theme:
|
|
|
|
return AppLocalizations.of(context)!.themeNameNeon1;
|
|
|
|
case neon2_theme:
|
|
|
|
return AppLocalizations.of(context)!.themeNameNeon2;
|
|
|
|
case pumpkin_theme:
|
|
|
|
return AppLocalizations.of(context)!.themeNamePumpkin;
|
|
|
|
case vampire_theme:
|
|
|
|
return AppLocalizations.of(context)!.themeNameVampire;
|
|
|
|
case witch_theme:
|
|
|
|
return AppLocalizations.of(context)!.themeNameWitch;
|
2021-12-15 20:17:13 +00:00
|
|
|
}
|
|
|
|
return theme;
|
|
|
|
}
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
/// Send an UpdateGlobalSettings to the Event Bus
|
|
|
|
saveSettings(context) {
|
|
|
|
var settings = Provider.of<Settings>(context, listen: false);
|
|
|
|
final updateSettingsEvent = {
|
|
|
|
"EventType": "UpdateGlobalSettings",
|
|
|
|
"Data": {"Data": jsonEncode(settings.asJson())},
|
|
|
|
};
|
|
|
|
final updateSettingsEventJson = jsonEncode(updateSettingsEvent);
|
|
|
|
Provider.of<FlwtchState>(context, listen: false).cwtch.SendAppEvent(updateSettingsEventJson);
|
|
|
|
}
|