Skip to content

Commit 15df1d9

Browse files
committed
settings: Add browser preference setting ui
The translation for the label is taken from zulip-mobile. The UI currently does not have a design, and is made to be as simple as possible to implement for now. Fixes: #1228 Signed-off-by: Zixuan James Li <[email protected]>
1 parent 5aeb759 commit 15df1d9

12 files changed

+112
-0
lines changed

assets/l10n/app_en.arb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,10 @@
803803
"@themeSettingSystem": {
804804
"description": "Label for system theme setting."
805805
},
806+
"openLinksWithInAppBrowser": "Open links with in-app browser",
807+
"@openLinksWithInAppBrowser": {
808+
"description": "Label for toggling setting to open links with in-app browser"
809+
},
806810
"pollWidgetQuestionMissing": "No question.",
807811
"@pollWidgetQuestionMissing": {
808812
"description": "Text to display for a poll when the question is missing"

lib/generated/l10n/zulip_localizations.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,12 @@ abstract class ZulipLocalizations {
11731173
/// **'System'**
11741174
String get themeSettingSystem;
11751175

1176+
/// Label for toggling setting to open links with in-app browser
1177+
///
1178+
/// In en, this message translates to:
1179+
/// **'Open links with in-app browser'**
1180+
String get openLinksWithInAppBrowser;
1181+
11761182
/// Text to display for a poll when the question is missing
11771183
///
11781184
/// In en, this message translates to:

lib/generated/l10n/zulip_localizations_ar.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
628628
@override
629629
String get themeSettingSystem => 'System';
630630

631+
@override
632+
String get openLinksWithInAppBrowser => 'Open links with in-app browser';
633+
631634
@override
632635
String get pollWidgetQuestionMissing => 'No question.';
633636

lib/generated/l10n/zulip_localizations_en.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
628628
@override
629629
String get themeSettingSystem => 'System';
630630

631+
@override
632+
String get openLinksWithInAppBrowser => 'Open links with in-app browser';
633+
631634
@override
632635
String get pollWidgetQuestionMissing => 'No question.';
633636

lib/generated/l10n/zulip_localizations_ja.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
628628
@override
629629
String get themeSettingSystem => 'System';
630630

631+
@override
632+
String get openLinksWithInAppBrowser => 'Open links with in-app browser';
633+
631634
@override
632635
String get pollWidgetQuestionMissing => 'No question.';
633636

lib/generated/l10n/zulip_localizations_nb.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
628628
@override
629629
String get themeSettingSystem => 'System';
630630

631+
@override
632+
String get openLinksWithInAppBrowser => 'Open links with in-app browser';
633+
631634
@override
632635
String get pollWidgetQuestionMissing => 'No question.';
633636

lib/generated/l10n/zulip_localizations_pl.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
628628
@override
629629
String get themeSettingSystem => 'System';
630630

631+
@override
632+
String get openLinksWithInAppBrowser => 'Open links with in-app browser';
633+
631634
@override
632635
String get pollWidgetQuestionMissing => 'Brak pytania.';
633636

lib/generated/l10n/zulip_localizations_ru.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ class ZulipLocalizationsRu extends ZulipLocalizations {
628628
@override
629629
String get themeSettingSystem => 'System';
630630

631+
@override
632+
String get openLinksWithInAppBrowser => 'Open links with in-app browser';
633+
631634
@override
632635
String get pollWidgetQuestionMissing => 'Нет вопроса.';
633636

lib/generated/l10n/zulip_localizations_sk.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ class ZulipLocalizationsSk extends ZulipLocalizations {
628628
@override
629629
String get themeSettingSystem => 'System';
630630

631+
@override
632+
String get openLinksWithInAppBrowser => 'Open links with in-app browser';
633+
631634
@override
632635
String get pollWidgetQuestionMissing => 'Bez otázky.';
633636

lib/widgets/settings.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,50 @@ class SettingsPage extends StatelessWidget {
2424
appBar: ZulipAppBar(
2525
title: Text(zulipLocalizations.settingsPageTitle)),
2626
body: Column(children: [
27+
_BrowserPreferenceSetting(),
2728
_ThemeSetting(),
2829
]));
2930
}
3031
}
3132

33+
class _BrowserPreferenceSetting extends StatefulWidget {
34+
const _BrowserPreferenceSetting();
35+
36+
@override
37+
State<_BrowserPreferenceSetting> createState() => _BrowserPreferenceSettingState();
38+
}
39+
40+
class _BrowserPreferenceSettingState extends State<_BrowserPreferenceSetting> {
41+
late bool openLinksWithInAppBrowser;
42+
43+
@override
44+
void didChangeDependencies() {
45+
super.didChangeDependencies();
46+
openLinksWithInAppBrowser =
47+
GlobalStoreWidget.of(context).globalSettings.effectiveBrowserPreference
48+
== BrowserPreference.embedded;
49+
}
50+
51+
void _handleChange(bool openLinksWithInAppBrowser) {
52+
GlobalStoreWidget.of(context).updateGlobalSettings(
53+
GlobalSettingsCompanion(browserPreference: Value(
54+
openLinksWithInAppBrowser ? BrowserPreference.embedded
55+
: BrowserPreference.external)));
56+
setState(() {
57+
this.openLinksWithInAppBrowser = openLinksWithInAppBrowser;
58+
});
59+
}
60+
61+
@override
62+
Widget build(BuildContext context) {
63+
final zulipLocalizations = ZulipLocalizations.of(context);
64+
return SwitchListTile.adaptive(
65+
title: Text(zulipLocalizations.openLinksWithInAppBrowser),
66+
value: openLinksWithInAppBrowser,
67+
onChanged: _handleChange);
68+
}
69+
}
70+
3271
class _ThemeSetting extends StatefulWidget {
3372
const _ThemeSetting();
3473

0 commit comments

Comments
 (0)