Skip to content

Commit

Permalink
refactor: 5075 - explicit localization of OFF world links (#5076)
Browse files Browse the repository at this point in the history
* refactor: 5075 - explicit localization of OFF world links

Impacted files:
* `external_page.dart`: removed useless parameter
* `knowledge_panel_text_card.dart`: removed useless parameter
* `knowledge_panel_world_map_card.dart`: removed useless parameter
* `launch_url_helper.dart`: removed useless parameter; removed redundant method
* `loading_dialog.dart`: removed useless parameter
* `login_page.dart`: removed useless parameter
* `new_product_page.dart`: removed useless parameter
* `smooth_html_widget.dart`: removed useless parameter
* `smooth_product_carousel.dart`: removed useless parameter
* `user_preferences_account.dart`: explicitly localized the OFF world subdomain
* `user_preferences_connect.dart`: removed useless parameter
* `user_preferences_contribute.dart`: removed useless parameter
* `user_preferences_faq.dart`: explicitly localized the OFF world subdomain; removed useless parameter
* `website_card.dart`: removed useless parameter

* Update user_preferences_faq.dart

Removed one parameter.
  • Loading branch information
monsieurtanuki authored Feb 20, 2024
1 parent 494acb8 commit 11b1212
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 75 deletions.
1 change: 0 additions & 1 deletion packages/smooth_app/lib/generic_lib/loading_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class LoadingDialog<T> {
recognizer: TapGestureRecognizer()
..onTap = () => LaunchUrlHelper.launchURL(
Status.openNewIssueUrl,
false,
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SmoothHtmlWidget extends StatelessWidget {
textStyle: textStyle,
onTapUrl: (String url) async {
try {
await LaunchUrlHelper.launchURL(url, false);
await LaunchUrlHelper.launchURL(url);
} catch (_) {
if (context.mounted) {
final AppLocalizations appLocalizations =
Expand Down
33 changes: 2 additions & 31 deletions packages/smooth_app/lib/helpers/launch_url_helper.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import 'dart:io';
import 'dart:ui';

import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:url_launcher/url_launcher.dart';

class LaunchUrlHelper {
LaunchUrlHelper._();

/// ifOFF true adds the users country code in front of the url
/// Throws a error when already populated
/// YES https:// openfoodfacts.org/...
/// NO https://de.openfoodfacts.org/...
///
static Future<void> launchURL(String url, bool isOFF) async {
if (isOFF) {
url = _replaceSubdomainWithCodes(url);
}

/// Launches the url in an external browser.
static Future<void> launchURL(String url) async {
AnalyticsHelper.trackOutlink(url: url);

try {
Expand All @@ -30,24 +21,4 @@ class LaunchUrlHelper {
throw 'Could not launch $url,Error: $e';
}
}

static String _replaceSubdomainWithCodes(String url) {
if (!url.contains('https://openfoodfacts.')) {
throw 'Error do not use local identifier in url';
}

String? countryCode =
PlatformDispatcher.instance.locale.countryCode?.toLowerCase();

if (countryCode == null) {
countryCode = 'world.';
} else {
countryCode = '$countryCode.';
}

url = url.replaceAll(
'https://openfoodfacts.', 'https://${countryCode}openfoodfacts.');

return url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class KnowledgePanelTextCard extends StatelessWidget {
iconData: null,
onPressed: () async => LaunchUrlHelper.launchURL(
textElement.sourceUrl!,
false,
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class KnowledgePanelWorldMapCard extends StatelessWidget {
'OpenStreetMap contributors',
onTap: () => LaunchUrlHelper.launchURL(
'https://www.openstreetmap.org/copyright',
false,
),
),
],
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/pages/navigator/external_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class _ExternalPageState extends State<ExternalPage> {
),
);
} else {
await LaunchUrlHelper.launchURL(url, false);
await LaunchUrlHelper.launchURL(url);
}

if (mounted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ class UserPreferencesAccount extends AbstractUserPreferences {
_getListTile(
appLocalizations.view_profile,
() async => LaunchUrlHelper.launchURL(
'https://openfoodfacts.org/editor/$userId',
true,
ProductQuery.replaceSubdomain(
'https://world.openfoodfacts.org/editor/$userId',
),
),
Icons.open_in_new,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class UserPreferencesConnect extends AbstractUserPreferences {
labels: <String>[title],
builder: (_) => UserPreferencesListTile(
title: Text(title),
onTap: onTap ?? () async => LaunchUrlHelper.launchURL(url!, false),
onTap: onTap ?? () async => LaunchUrlHelper.launchURL(url!),
trailing:
UserPreferencesListTile.getTintedIcon(Icons.open_in_new, context),
leading: leadingIconData != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class UserPreferencesContribute extends AbstractUserPreferences {
ProductQuery.replaceSubdomain(
'https://world.openfoodfacts.org/contribute',
),
false,
),
Icons.volunteer_activism_outlined,
externalLink: true,
Expand All @@ -90,7 +89,6 @@ class UserPreferencesContribute extends AbstractUserPreferences {
appLocalizations.contribute_join_skill_pool,
() async => LaunchUrlHelper.launchURL(
'https://docs.google.com/forms/d/e/1FAIpQLSfGHAn5KxW7ko3_GlDfQpVGKpPAMHMbDvY2IjtxfJSXxKJQ2A/viewform?usp=sf_link',
false,
),
Icons.group,
externalLink: true,
Expand All @@ -104,7 +102,6 @@ class UserPreferencesContribute extends AbstractUserPreferences {
appLocalizations.contribute_donate_header,
() async => LaunchUrlHelper.launchURL(
AppLocalizations.of(context).donate_url,
false,
),
Icons.volunteer_activism,
icon:
Expand Down Expand Up @@ -133,7 +130,6 @@ class UserPreferencesContribute extends AbstractUserPreferences {
if (result == true) {
await LaunchUrlHelper.launchURL(
GlobalVars.appStore.getEnrollInBetaURL()!,
false,
);
}
},
Expand Down Expand Up @@ -216,15 +212,17 @@ class UserPreferencesContribute extends AbstractUserPreferences {
SmoothAlertContentButton(
label: 'Slack',
icon: Icons.open_in_new,
onPressed: () => LaunchUrlHelper.launchURL(
'https://slack.openfoodfacts.org/', false),
onPressed: () async => LaunchUrlHelper.launchURL(
'https://slack.openfoodfacts.org/',
),
),
const SizedBox(height: SMALL_SPACE),
SmoothAlertContentButton(
label: 'GitHub',
icon: Icons.open_in_new,
onPressed: () => LaunchUrlHelper.launchURL(
'https://github.com/openfoodfacts', false),
onPressed: () async => LaunchUrlHelper.launchURL(
'https://github.com/openfoodfacts',
),
),
const SizedBox(height: 10),
UserPreferencesSwitchWidget(
Expand Down Expand Up @@ -266,8 +264,9 @@ class UserPreferencesContribute extends AbstractUserPreferences {
],
),
positiveAction: SmoothActionButton(
onPressed: () => LaunchUrlHelper.launchURL(
'https://translate.openfoodfacts.org/', false),
onPressed: () async => LaunchUrlHelper.launchURL(
'https://translate.openfoodfacts.org/',
),
text: appLocalizations.contribute_translate_link_text,
),
negativeAction: SmoothActionButton(
Expand Down Expand Up @@ -376,12 +375,9 @@ class _ContributorsDialog extends StatelessWidget {
message: contributor.login,
child: InkWell(
customBorder: const CircleBorder(),
onTap: () {
LaunchUrlHelper.launchURL(
contributor.profilePath,
false,
);
},
onTap: () async => LaunchUrlHelper.launchURL(
contributor.profilePath,
),
child: Ink(
decoration: BoxDecoration(
borderRadius:
Expand Down Expand Up @@ -413,8 +409,9 @@ class _ContributorsDialog extends StatelessWidget {
},
),
positiveAction: SmoothActionButton(
onPressed: () => LaunchUrlHelper.launchURL(
'https://github.com/openfoodfacts/smooth-app', false),
onPressed: () async => LaunchUrlHelper.launchURL(
'https://github.com/openfoodfacts/smooth-app',
),
text: AppLocalizations.of(context).contribute,
minWidth: 150,
),
Expand Down
28 changes: 17 additions & 11 deletions packages/smooth_app/lib/pages/preferences/user_preferences_faq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class UserPreferencesFaq extends AbstractUserPreferences {
labels: <String>[title],
builder: (_) => UserPreferencesListTile(
title: Text(title),
onTap: onTap ?? () async => LaunchUrlHelper.launchURL(url!, false),
onTap: onTap ?? () async => LaunchUrlHelper.launchURL(url!),
trailing: icon ??
UserPreferencesListTile.getTintedIcon(Icons.open_in_new, context),
leading: SizedBox(
Expand Down Expand Up @@ -257,34 +257,40 @@ class UserPreferencesFaq extends AbstractUserPreferences {
),
const SizedBox(height: VERY_SMALL_SPACE),
SmoothAlertContentButton(
onPressed: () => LaunchUrlHelper.launchURL(
'https://openfoodfacts.org/who-we-are', true),
onPressed: () async => LaunchUrlHelper.launchURL(
ProductQuery.replaceSubdomain(
'https://world.openfoodfacts.org/who-we-are',
),
),
label: appLocalizations.learnMore,
icon: Icons.open_in_new,
),
const SizedBox(height: VERY_SMALL_SPACE),
SmoothAlertContentButton(
onPressed: () => LaunchUrlHelper.launchURL(
'https://openfoodfacts.org/terms-of-use',
true,
onPressed: () async => LaunchUrlHelper.launchURL(
ProductQuery.replaceSubdomain(
'https://world.openfoodfacts.org/terms-of-use',
),
),
label: appLocalizations.termsOfUse,
icon: Icons.open_in_new,
),
const SizedBox(height: VERY_SMALL_SPACE),
SmoothAlertContentButton(
onPressed: () => LaunchUrlHelper.launchURL(
'https://openfoodfacts.org/legal',
true,
onPressed: () async => LaunchUrlHelper.launchURL(
ProductQuery.replaceSubdomain(
'https://world.openfoodfacts.org/legal',
),
),
label: appLocalizations.legalNotices,
icon: Icons.open_in_new,
),
const SizedBox(height: VERY_SMALL_SPACE),
SmoothAlertContentButton(
onPressed: () => LaunchUrlHelper.launchURL(
'https://openfoodfacts.org/privacy',
true,
ProductQuery.replaceSubdomain(
'https://world.openfoodfacts.org/privacy',
),
),
label: appLocalizations.privacy_policy,
icon: Icons.open_in_new,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ class _ProductPageState extends State<ProductPage>
icon: CupertinoIcons.tag_fill,
onPressed: () async => LaunchUrlHelper.launchURL(
'https://prices.openfoodfacts.org/app/products/${upToDateProduct.barcode!}',
false,
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/pages/product/website_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WebsiteCard extends StatelessWidget {
final String website = _getWebsite();
return buildProductSmoothCard(
body: InkWell(
onTap: () => LaunchUrlHelper.launchURL(website, false),
onTap: () async => LaunchUrlHelper.launchURL(website),
borderRadius: ROUNDED_BORDER_RADIUS,
child: Container(
width: double.infinity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class _LoginPageState extends State<LoginPage> with TraceableClientMixin {
text: appLocalizations.okay,
onPressed: () async {
final String formLink = UserFeedbackHelper.getFeedbackFormLink();
LaunchUrlHelper.launchURL(formLink, false);
LaunchUrlHelper.launchURL(formLink);
Navigator.of(context).pop();
},
),
Expand Down
6 changes: 2 additions & 4 deletions packages/smooth_app/lib/widgets/smooth_product_carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,7 @@ class _SearchCardContentTagLine extends StatelessWidget {
return InkWell(
borderRadius: ANGULAR_BORDER_RADIUS,
onTap: tagLine.hasLink
? () async {
await LaunchUrlHelper.launchURL(tagLine.url, false);
}
? () async => LaunchUrlHelper.launchURL(tagLine.url)
: null,
child: Center(
child: AutoSizeText(
Expand Down Expand Up @@ -527,7 +525,7 @@ class _SearchCardContentAppReview extends StatelessWidget {
text: localizations.app_review_negative_modal_positive_button,
onPressed: () {
final String formLink = UserFeedbackHelper.getFeedbackFormLink();
LaunchUrlHelper.launchURL(formLink, false);
LaunchUrlHelper.launchURL(formLink);
Navigator.of(context).pop();
},
),
Expand Down

0 comments on commit 11b1212

Please sign in to comment.