Skip to content

Commit 199df7c

Browse files
committed
settings: Add browser preference setting ui
The translation for the label is taken from zulip-mobile. The user facing string refers to "in in-app browser" when the actual value is `UrlLaunchMode.platformDefault`. This is consistent with the behavior the user sees when the link is a HTTP URL on Android and iOS, which should cover the majority of use cases of this setting (and probably what the user would expect). 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 <zixuan@zulip.com>
1 parent f251521 commit 199df7c

12 files changed

+123
-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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:drift/drift.dart' hide Column;
22
import 'package:flutter/material.dart';
33

44
import '../generated/l10n/zulip_localizations.dart';
5+
import '../model/binding.dart';
56
import '../model/database.dart';
67
import '../model/settings.dart';
78
import 'app_bar.dart';
@@ -23,11 +24,53 @@ class SettingsPage extends StatelessWidget {
2324
appBar: ZulipAppBar(
2425
title: Text(zulipLocalizations.settingsPageTitle)),
2526
body: Column(children: [
27+
const _BrowserPreferenceSetting(),
2628
const _ThemeSetting(),
2729
]));
2830
}
2931
}
3032

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+
// On Android and iOS, an in-app browser will be used for HTTP URLs if the
47+
// launch mode is [UrlLaunchMode.platformDefault]. External browsers/apps
48+
// can still be used for other types of links.
49+
openLinksWithInAppBrowser =
50+
GlobalStoreWidget.of(context).globalSettings.urlLaunchMode
51+
== UrlLaunchMode.platformDefault;
52+
}
53+
54+
void _handleChange(bool newOpenLinksWithInAppBrowser) {
55+
GlobalStoreWidget.of(context).updateGlobalSettings(
56+
GlobalSettingsCompanion(browserPreference: Value(
57+
newOpenLinksWithInAppBrowser ? BrowserPreference.embedded
58+
: BrowserPreference.external)));
59+
setState(() {
60+
openLinksWithInAppBrowser = newOpenLinksWithInAppBrowser;
61+
});
62+
}
63+
64+
@override
65+
Widget build(BuildContext context) {
66+
final zulipLocalizations = ZulipLocalizations.of(context);
67+
return SwitchListTile.adaptive(
68+
title: Text(zulipLocalizations.openLinksWithInAppBrowser),
69+
value: openLinksWithInAppBrowser,
70+
onChanged: _handleChange);
71+
}
72+
}
73+
3174
class _ThemeSetting extends StatefulWidget {
3275
const _ThemeSetting();
3376

0 commit comments

Comments
 (0)