Skip to content

Commit 0952c06

Browse files
committed
wip/link welcome: Show a dialog on first upgrading from legacy app
Fixes 1580.
1 parent b90b799 commit 0952c06

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

lib/model/settings.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ enum GlobalSettingType {
119119
/// we give it a placeholder value which isn't a real setting.
120120
placeholder,
121121

122+
/// Describes a pseudo-setting not directly exposed in the UI.
123+
internal,
124+
122125
/// Describes a setting which enables an in-progress feature of the app.
123126
///
124127
/// Sometimes when building a complex feature it's useful to merge PRs that
@@ -170,6 +173,10 @@ enum BoolGlobalSetting {
170173
/// (Having one stable value in this enum is also handy for tests.)
171174
placeholderIgnore(GlobalSettingType.placeholder, false),
172175

176+
/// A pseudo-setting recording whether the user has been shown the
177+
/// welcome dialog for upgrading from the legacy app.
178+
upgradeWelcomeDialogShown(GlobalSettingType.internal, false),
179+
173180
/// An experimental flag to toggle rendering KaTeX content in messages.
174181
renderKatex(GlobalSettingType.experimentalFeatureFlag, false),
175182

lib/widgets/app.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class _ZulipAppState extends State<ZulipApp> with WidgetsBindingObserver {
160160
void initState() {
161161
super.initState();
162162
WidgetsBinding.instance.addObserver(this);
163+
UpgradeWelcomeDialog.maybeShow();
163164
}
164165

165166
@override

lib/widgets/dialog.dart

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import 'package:flutter/material.dart';
22

33
import '../generated/l10n/zulip_localizations.dart';
4+
import '../model/settings.dart';
45
import 'actions.dart';
6+
import 'app.dart';
7+
import 'content.dart';
8+
import 'store.dart';
59

610
Widget _dialogActionText(String text) {
711
return Text(
@@ -112,3 +116,69 @@ DialogStatus<bool> showSuggestedActionDialog({
112116
]));
113117
return DialogStatus(future);
114118
}
119+
120+
/// A brief dialog box welcoming the user to this new Zulip app,
121+
/// shown upon upgrading from the legacy app.
122+
class UpgradeWelcomeDialog extends StatelessWidget {
123+
const UpgradeWelcomeDialog._();
124+
125+
static void maybeShow() async {
126+
final navigator = await ZulipApp.navigator;
127+
final context = navigator.context;
128+
assert(context.mounted);
129+
if (!context.mounted) return; // TODO(linter): this is impossible as there's no actual async gap, but the use_build_context_synchronously lint doesn't see that
130+
131+
final globalSettings = GlobalStoreWidget.settingsOf(context);
132+
switch (globalSettings.legacyUpgradeState) {
133+
case LegacyUpgradeState.noLegacy:
134+
// This install didn't replace the legacy app.
135+
return;
136+
137+
case LegacyUpgradeState.unknown:
138+
// Not clear if this replaced the legacy app;
139+
// skip the dialog that would assume it had.
140+
// TODO(log)
141+
return;
142+
143+
case LegacyUpgradeState.found:
144+
case LegacyUpgradeState.migrated:
145+
// This install replaced the legacy app.
146+
// Show the dialog, if we haven't already.
147+
if (globalSettings.getBool(BoolGlobalSetting.upgradeWelcomeDialogShown)) {
148+
return;
149+
}
150+
}
151+
152+
final future = showDialog<void>(
153+
context: context,
154+
builder: (context) => UpgradeWelcomeDialog._());
155+
156+
await future; // Wait for the dialog to be dismissed.
157+
158+
await globalSettings.setBool(BoolGlobalSetting.upgradeWelcomeDialogShown, true);
159+
}
160+
161+
static const String _announcementUrl =
162+
'https://blog.zulip.com/flutter-mobile-app-launch';
163+
164+
@override
165+
Widget build(BuildContext context) {
166+
final zulipLocalizations = ZulipLocalizations.of(context);
167+
return AlertDialog(
168+
title: Text(zulipLocalizations.upgradeWelcomeDialogTitle),
169+
content: SingleChildScrollView(
170+
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
171+
Text(zulipLocalizations.upgradeWelcomeDialogMessage),
172+
GestureDetector(
173+
onTap: () => PlatformActions.launchUrl(context,
174+
Uri.parse(_announcementUrl)),
175+
child: Text(
176+
style: TextStyle(color: ContentTheme.of(context).colorLink),
177+
zulipLocalizations.upgradeWelcomeDialogLinkText)),
178+
])),
179+
actions: [
180+
TextButton(onPressed: () => Navigator.pop(context),
181+
child: Text(zulipLocalizations.upgradeWelcomeDialogDismiss)),
182+
]);
183+
}
184+
}

0 commit comments

Comments
 (0)