|
1 | 1 | import 'package:flutter/material.dart';
|
2 | 2 |
|
3 | 3 | import '../generated/l10n/zulip_localizations.dart';
|
| 4 | +import '../model/settings.dart'; |
4 | 5 | import 'actions.dart';
|
| 6 | +import 'app.dart'; |
| 7 | +import 'content.dart'; |
| 8 | +import 'store.dart'; |
5 | 9 |
|
6 | 10 | Widget _dialogActionText(String text) {
|
7 | 11 | return Text(
|
@@ -112,3 +116,69 @@ DialogStatus<bool> showSuggestedActionDialog({
|
112 | 116 | ]));
|
113 | 117 | return DialogStatus(future);
|
114 | 118 | }
|
| 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