settings pane headers, and notification settings options

This commit is contained in:
Dan Ballard 2022-02-03 21:17:08 -05:00
parent e6246cf44a
commit c550437aa5
2 changed files with 155 additions and 30 deletions

View File

@ -22,6 +22,17 @@ enum DualpaneMode {
CopyPortrait, CopyPortrait,
} }
enum NotificationPolicy {
None,
OptIn,
OptOut,
}
enum NotificationContent {
SimpleEvent,
ContactInfo,
}
/// Settings govern the *Globally* relevant settings like Locale, Theme and Experiments. /// Settings govern the *Globally* relevant settings like Locale, Theme and Experiments.
/// We also provide access to the version information here as it is also accessed from the /// We also provide access to the version information here as it is also accessed from the
/// Settings Pane. /// Settings Pane.
@ -29,12 +40,16 @@ class Settings extends ChangeNotifier {
Locale locale; Locale locale;
late PackageInfo packageInfo; late PackageInfo packageInfo;
OpaqueThemeType theme; OpaqueThemeType theme;
// explicitly set experiments to false until told otherwise... // explicitly set experiments to false until told otherwise...
bool experimentsEnabled = false; bool experimentsEnabled = false;
HashMap<String, bool> experiments = HashMap.identity(); HashMap<String, bool> experiments = HashMap.identity();
DualpaneMode _uiColumnModePortrait = DualpaneMode.Single; DualpaneMode _uiColumnModePortrait = DualpaneMode.Single;
DualpaneMode _uiColumnModeLandscape = DualpaneMode.CopyPortrait; DualpaneMode _uiColumnModeLandscape = DualpaneMode.CopyPortrait;
NotificationPolicy _notificationPolicy = NotificationPolicy.OptOut;
NotificationContent _notificationContent = NotificationContent.SimpleEvent;
bool blockUnknownConnections = false; bool blockUnknownConnections = false;
bool streamerMode = false; bool streamerMode = false;
String _downloadPath = ""; String _downloadPath = "";
@ -94,6 +109,9 @@ class Settings extends ChangeNotifier {
_uiColumnModePortrait = uiColumnModeFromString(settings["UIColumnModePortrait"]); _uiColumnModePortrait = uiColumnModeFromString(settings["UIColumnModePortrait"]);
_uiColumnModeLandscape = uiColumnModeFromString(settings["UIColumnModeLandscape"]); _uiColumnModeLandscape = uiColumnModeFromString(settings["UIColumnModeLandscape"]);
_notificationPolicy = notificationPolicyFromString(settings["NotificationPolicy"]);
_notificationContent = notificationContentFromString(settings["NotificationContent"]);
// auto-download folder // auto-download folder
_downloadPath = settings["DownloadPath"] ?? ""; _downloadPath = settings["DownloadPath"] ?? "";
@ -173,17 +191,33 @@ class Settings extends ChangeNotifier {
} }
DualpaneMode get uiColumnModePortrait => _uiColumnModePortrait; DualpaneMode get uiColumnModePortrait => _uiColumnModePortrait;
set uiColumnModePortrait(DualpaneMode newval) { set uiColumnModePortrait(DualpaneMode newval) {
this._uiColumnModePortrait = newval; this._uiColumnModePortrait = newval;
notifyListeners(); notifyListeners();
} }
DualpaneMode get uiColumnModeLandscape => _uiColumnModeLandscape; DualpaneMode get uiColumnModeLandscape => _uiColumnModeLandscape;
set uiColumnModeLandscape(DualpaneMode newval) { set uiColumnModeLandscape(DualpaneMode newval) {
this._uiColumnModeLandscape = newval; this._uiColumnModeLandscape = newval;
notifyListeners(); notifyListeners();
} }
NotificationPolicy get notificationPolicy => _notificationPolicy;
set notificationPolicy(NotificationPolicy newpol) {
this._notificationPolicy = newpol;
notifyListeners();
}
NotificationContent get notificationContent => _notificationContent;
set notificationContent(NotificationContent newcon) {
this._notificationContent = newcon;
notifyListeners();
}
List<int> uiColumns(bool isLandscape) { List<int> uiColumns(bool isLandscape) {
var m = (!isLandscape || uiColumnModeLandscape == DualpaneMode.CopyPortrait) ? uiColumnModePortrait : uiColumnModeLandscape; var m = (!isLandscape || uiColumnModeLandscape == DualpaneMode.CopyPortrait) ? uiColumnModePortrait : uiColumnModeLandscape;
switch (m) { switch (m) {
@ -238,6 +272,43 @@ class Settings extends ChangeNotifier {
} }
} }
static NotificationPolicy notificationPolicyFromString(String? np) {
switch (np) {
case "None":
return NotificationPolicy.None;
case "OptIn":
return NotificationPolicy.OptIn;
case "OptOut":
return NotificationPolicy.OptOut;
}
return NotificationPolicy.OptOut;
}
static NotificationContent notificationContentFromString(String? nc) {
switch (nc) {
case "SimpleEvent":
return NotificationContent.SimpleEvent;
case "ContactInfo":
return NotificationContent.ContactInfo;
}
return NotificationContent.SimpleEvent;
}
static String notificationPolicyToString(NotificationPolicy np, BuildContext context) {
switch (np) {
case NotificationPolicy.None: return "None";
case NotificationPolicy.OptIn: return "OptIn";
case NotificationPolicy.OptOut: return "OptOut";
}
}
static String notificationContentToString(NotificationContent nc, BuildContext context) {
switch (nc) {
case NotificationContent.SimpleEvent: return "SimpleEvent";
case NotificationContent.ContactInfo: return "ContactInfo";
}
}
// checks experiment settings and file extension for image previews // checks experiment settings and file extension for image previews
// (ignores file size; if the user manually accepts the file, assume it's okay to preview) // (ignores file size; if the user manually accepts the file, assume it's okay to preview)
bool shouldPreview(String path) { bool shouldPreview(String path) {
@ -247,18 +318,21 @@ class Settings extends ChangeNotifier {
} }
String get downloadPath => _downloadPath; String get downloadPath => _downloadPath;
set downloadPath(String newval) { set downloadPath(String newval) {
_downloadPath = newval; _downloadPath = newval;
notifyListeners(); notifyListeners();
} }
bool get allowAdvancedTorConfig => _allowAdvancedTorConfig; bool get allowAdvancedTorConfig => _allowAdvancedTorConfig;
set allowAdvancedTorConfig(bool torConfig) { set allowAdvancedTorConfig(bool torConfig) {
_allowAdvancedTorConfig = torConfig; _allowAdvancedTorConfig = torConfig;
notifyListeners(); notifyListeners();
} }
bool get useTorCache => _useTorCache; bool get useTorCache => _useTorCache;
set useTorCache(bool useTorCache) { set useTorCache(bool useTorCache) {
_useTorCache = useTorCache; _useTorCache = useTorCache;
notifyListeners(); notifyListeners();
@ -266,18 +340,21 @@ class Settings extends ChangeNotifier {
// Settings / Gettings for setting the custom tor config.. // Settings / Gettings for setting the custom tor config..
String get torConfig => _customTorConfig; String get torConfig => _customTorConfig;
set torConfig(String torConfig) { set torConfig(String torConfig) {
_customTorConfig = torConfig; _customTorConfig = torConfig;
notifyListeners(); notifyListeners();
} }
int get socksPort => _socksPort; int get socksPort => _socksPort;
set socksPort(int newSocksPort) { set socksPort(int newSocksPort) {
_socksPort = newSocksPort; _socksPort = newSocksPort;
notifyListeners(); notifyListeners();
} }
int get controlPort => _controlPort; int get controlPort => _controlPort;
set controlPort(int controlPort) { set controlPort(int controlPort) {
_controlPort = controlPort; _controlPort = controlPort;
notifyListeners(); notifyListeners();
@ -285,6 +362,7 @@ class Settings extends ChangeNotifier {
// Setters / Getters for toggling whether the app should use a custom tor config // Setters / Getters for toggling whether the app should use a custom tor config
bool get useCustomTorConfig => _useCustomTorConfig; bool get useCustomTorConfig => _useCustomTorConfig;
set useCustomTorConfig(bool useCustomTorConfig) { set useCustomTorConfig(bool useCustomTorConfig) {
_useCustomTorConfig = useCustomTorConfig; _useCustomTorConfig = useCustomTorConfig;
notifyListeners(); notifyListeners();
@ -302,6 +380,8 @@ class Settings extends ChangeNotifier {
"ThemeMode": theme.mode, "ThemeMode": theme.mode,
"PreviousPid": -1, "PreviousPid": -1,
"BlockUnknownConnections": blockUnknownConnections, "BlockUnknownConnections": blockUnknownConnections,
"NotificationPolicy": _notificationPolicy.toString(),
"NotificationContent": _notificationContent.toString(),
"StreamerMode": streamerMode, "StreamerMode": streamerMode,
"ExperimentsEnabled": this.experimentsEnabled, "ExperimentsEnabled": this.experimentsEnabled,
"Experiments": experiments, "Experiments": experiments,

View File

@ -53,11 +53,13 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
isAlwaysShown: true, isAlwaysShown: true,
child: SingleChildScrollView( child: SingleChildScrollView(
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
padding: EdgeInsets.all(20),
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints( constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight, minHeight: viewportConstraints.maxHeight,
), ),
child: Column(children: [ child: Column(children: [
Row(mainAxisAlignment: MainAxisAlignment.center, children: [Text("Apperance", style: TextStyle(fontWeight: FontWeight.bold))]),
ListTile( ListTile(
title: Text(AppLocalizations.of(context)!.settingLanguage, style: TextStyle(color: settings.current().mainTextColor)), title: Text(AppLocalizations.of(context)!.settingLanguage, style: TextStyle(color: settings.current().mainTextColor)),
leading: Icon(CwtchIcons.change_language, color: settings.current().mainTextColor), leading: Icon(CwtchIcons.change_language, color: settings.current().mainTextColor),
@ -135,24 +137,76 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
style: TextStyle(color: settings.current().mainTextColor), style: TextStyle(color: settings.current().mainTextColor),
), ),
leading: Icon(Icons.table_chart, color: settings.current().mainTextColor), leading: Icon(Icons.table_chart, color: settings.current().mainTextColor),
trailing: Container( trailing: DropdownButton(
width: MediaQuery.of(context).size.width / 4, value: settings.uiColumnModeLandscape.toString(),
child: DropdownButton( onChanged: (String? newValue) {
isExpanded: true, settings.uiColumnModeLandscape = Settings.uiColumnModeFromString(newValue!);
value: settings.uiColumnModeLandscape.toString(), saveSettings(context);
onChanged: (String? newValue) { },
settings.uiColumnModeLandscape = Settings.uiColumnModeFromString(newValue!); items: Settings.uiColumnModeOptions(true).map<DropdownMenuItem<String>>((DualpaneMode value) {
saveSettings(context); return DropdownMenuItem<String>(
}, value: value.toString(),
items: Settings.uiColumnModeOptions(true).map<DropdownMenuItem<String>>((DualpaneMode value) { child: Text(
return DropdownMenuItem<String>( Settings.uiColumnModeToString(value, context),
value: value.toString(), overflow: TextOverflow.ellipsis,
child: Text( ),
Settings.uiColumnModeToString(value, context), );
overflow: TextOverflow.ellipsis, }).toList())),
), SwitchListTile(
); title: Text(AppLocalizations.of(context)!.streamerModeLabel, style: TextStyle(color: settings.current().mainTextColor)),
}).toList()))), 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),
),
SizedBox(
height: 40,
),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [Text("Behaviour", style: TextStyle(fontWeight: FontWeight.bold))]),
ListTile(
title: Text(/*AppLocalizations.of(context)!.themeColorLabel*/ "Notification Policy"),
trailing: DropdownButton(
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()),
leading: Icon(CwtchIcons.chat_bubble_empty_24px, color: settings.current().mainTextColor),
),
ListTile(
title: Text(/*AppLocalizations.of(context)!.themeColorLabel*/ "Notification Content"),
trailing: DropdownButton(
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()),
leading: Icon(CwtchIcons.chat_bubble_empty_24px, color: settings.current().mainTextColor),
),
SwitchListTile( SwitchListTile(
title: Text(AppLocalizations.of(context)!.blockUnknownLabel, style: TextStyle(color: settings.current().mainTextColor)), title: Text(AppLocalizations.of(context)!.blockUnknownLabel, style: TextStyle(color: settings.current().mainTextColor)),
subtitle: Text(AppLocalizations.of(context)!.descriptionBlockUnknownConnections), subtitle: Text(AppLocalizations.of(context)!.descriptionBlockUnknownConnections),
@ -171,19 +225,10 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
inactiveTrackColor: settings.theme.defaultButtonDisabledColor, inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
secondary: Icon(CwtchIcons.block_unknown, color: settings.current().mainTextColor), secondary: Icon(CwtchIcons.block_unknown, color: settings.current().mainTextColor),
), ),
SwitchListTile( SizedBox(
title: Text(AppLocalizations.of(context)!.streamerModeLabel, style: TextStyle(color: settings.current().mainTextColor)), height: 40,
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),
), ),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [Text("Experiments", style: TextStyle(fontWeight: FontWeight.bold))]),
SwitchListTile( SwitchListTile(
title: Text(AppLocalizations.of(context)!.experimentsEnabled, style: TextStyle(color: settings.current().mainTextColor)), title: Text(AppLocalizations.of(context)!.experimentsEnabled, style: TextStyle(color: settings.current().mainTextColor)),
subtitle: Text(AppLocalizations.of(context)!.descriptionExperiments), subtitle: Text(AppLocalizations.of(context)!.descriptionExperiments),