Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
camillebrulotte committed Sep 20, 2023
1 parent 0355b01 commit bbd7c6c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
27 changes: 25 additions & 2 deletions lib/core/viewmodels/faq_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// FLUTTER / DART / THIRD-PARTIES
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:notredame/locator.dart';
import 'package:stacked/stacked.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

// MANAGERS
import 'package:notredame/core/managers/settings_manager.dart';

// SERVICES
import 'package:notredame/core/services/launch_url_service.dart';
import 'package:notredame/core/services/analytics_service.dart';

// CONSTANTS
import 'package:notredame/core/constants/app_info.dart';

class FaqViewModel extends BaseViewModel {
final SettingsManager _settingsManager = locator<SettingsManager>();
Expand All @@ -20,8 +25,26 @@ class FaqViewModel extends BaseViewModel {
return 'mailto:$email?subject=$subject';
}

/// used to open a website or the security view
Future<void> launchWebsite(String link, Brightness brightness) async {
await _launchUrlService.launchInBrowser(link, brightness);
}

Future<void> openMail(String addressEmail, BuildContext context) async {
var email = "";
if (addressEmail == AppInfo.email) {
email =
mailtoStr(addressEmail, AppIntl.of(context).email_subject);
} else {
email =
mailtoStr(addressEmail, "");
}

final urlLaunchable = await _launchUrlService.canLaunch(email);

if (urlLaunchable) {
await _launchUrlService.launch(email);
} else {
locator<AnalyticsService>().logError("login_view", "Cannot send email.");
}
}
}
2 changes: 1 addition & 1 deletion lib/core/viewmodels/web_link_card_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ class WebLinkCardViewModel extends BaseViewModel {
}

Future<void> launchWebView(QuickLink link) async {
_navigationService.pushNamed(RouterPaths.webView);
_navigationService.pushNamed(RouterPaths.webView, arguments: link);
}
}
32 changes: 3 additions & 29 deletions lib/ui/views/faq_view.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// FLUTTER / DART / THIRD-PARTIES
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:notredame/locator.dart';
import 'package:notredame/ui/utils/app_theme.dart';
import 'package:stacked/stacked.dart';

// UTILS
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

// VIEWMODEL
Expand All @@ -14,13 +10,8 @@ import 'package:notredame/core/viewmodels/faq_viewmodel.dart';
// MODELS
import 'package:notredame/core/models/faq_actions.dart';

// SERVICES
import 'package:notredame/core/services/launch_url_service.dart';
import 'package:notredame/core/services/analytics_service.dart';

// CONSTANTS
import 'package:notredame/core/constants/faq.dart';
import 'package:notredame/core/constants/app_info.dart';

class FaqView extends StatefulWidget {
final Color backgroundColor;
Expand All @@ -34,8 +25,6 @@ class FaqView extends StatefulWidget {
class _FaqViewState extends State<FaqView> {
final Faq faq = Faq();

final LaunchUrlService _launchUrlService = locator<LaunchUrlService>();

@override
Widget build(BuildContext context) =>
ViewModelBuilder<FaqViewModel>.reactive(
Expand Down Expand Up @@ -212,7 +201,7 @@ class _FaqViewState extends State<FaqView> {
if (type.name == ActionType.webview.name) {
openWebview(model, link);
} else if (type.name == ActionType.email.name) {
openMail(model, link);
openMail(model, context, link);
}
},
style: ButtonStyle(
Expand Down Expand Up @@ -287,22 +276,7 @@ class _FaqViewState extends State<FaqView> {
model.launchWebsite(link, Theme.of(context).brightness);
}

Future<void> openMail(FaqViewModel model, String addressEmail) async {
var email = "";
if (addressEmail == AppInfo.email) {
email =
model.mailtoStr(addressEmail, AppIntl.of(context).email_subject);
} else {
email =
model.mailtoStr(addressEmail, "");
}

final urlLaunchable = await _launchUrlService.canLaunch(email);

if (urlLaunchable) {
await _launchUrlService.launch(email);
} else {
locator<AnalyticsService>().logError("login_view", "Cannot send email.");
}
Future<void> openMail(FaqViewModel model, BuildContext context, String addressEmail) async {
model.openMail(addressEmail, context);
}
}
2 changes: 1 addition & 1 deletion test/viewmodels/faq_viewmodel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:notredame/core/managers/settings_manager.dart';

// SERVICES / MANAGERS
import 'package:notredame/core/services/launch_url_service.dart';
import 'package:notredame/core/managers/settings_manager.dart';

// VIEW MODEL
import 'package:notredame/core/viewmodels/faq_viewmodel.dart';
Expand Down

0 comments on commit bbd7c6c

Please sign in to comment.