Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COG-103 opening urls #104

Merged
merged 1 commit into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/translations/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ class AppLocalizations {
'serviceCheck.response': {
'en': 'Response',
},
'urlLauncher.toast': {
'en': 'URL error occurred',
},
};

String getTranslation(String key) {
Expand Down
27 changes: 27 additions & 0 deletions lib/utils/url_launcher.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:cogboardmobileapp/translations/app_localizations.dart';
import 'package:flutter/material.dart';
import 'package:toast/toast.dart';
import 'package:url_launcher/url_launcher.dart';

mixin UrlLauncher {
void _displayToast(BuildContext context) {
Toast.show(
AppLocalizations.of(context).getTranslation('urlLauncher.toast'),
context,
duration: Toast.LENGTH_LONG,
gravity: Toast.BOTTOM,
);
}

Future<void> launchUrl(String url, BuildContext context) async {
if (await canLaunch(url)) {
try {
await launch(url);
} catch (e) {
_displayToast(context);
}
} else {
_displayToast(context);
}
}
}
48 changes: 33 additions & 15 deletions lib/widgets/widgets/aem_bundle_info/aem_bundle_info_widget.dart
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
import 'package:cogboardmobileapp/models/widget_model.dart';
import 'package:cogboardmobileapp/translations/app_localizations.dart';
import 'package:cogboardmobileapp/utils/url_launcher.dart';
import 'package:cogboardmobileapp/widgets/widgets/details_container.dart';
import 'package:cogboardmobileapp/widgets/widgets/details_header.dart';
import 'package:cogboardmobileapp/widgets/widgets/widget_details_item.dart';
import 'package:flutter/material.dart';

class AemBundleInfoWidget extends StatelessWidget {
class AemBundleInfoWidget extends StatelessWidget with UrlLauncher {
final DashboardWidget widget;

AemBundleInfoWidget({
@required this.widget,
});

List get getBundleStatus {
void openUrl(BuildContext context) {
launchUrl(widget.content['url'], context);
}

List getBundleStatus(BuildContext context) {
Map status = widget.content["bundleStatus"];
return status.entries
.map((item) => WidgetDetailsItem(
detail: "${item.key.toString().toUpperCase()}: ${item.value}",
.map((item) => GestureDetector(
onTap: () => openUrl(context),
child: WidgetDetailsItem(
detail: "${item.key.toString().toUpperCase()}: ${item.value}",
),
))
.toList();
}

List get getExcludedBundles {
List getExcludedBundles(BuildContext context) {
List bundles = widget.content["excludedBundles"];
return bundles
.map((bundle) => WidgetDetailsItem(
.map(
(bundle) => GestureDetector(
onTap: () => openUrl(context),
child: WidgetDetailsItem(
detail: "$bundle",
))
),
),
)
.toList();
}

List get getInactiveBundles {
List getInactiveBundles(BuildContext context) {
List bundles = widget.content["inactiveBundles"];
return bundles
.map((bundle) => WidgetDetailsItem(
.map(
(bundle) => GestureDetector(
onTap: () => openUrl(context),
child: WidgetDetailsItem(
detail: "$bundle",
))
),
),
)
.toList();
}

Expand All @@ -46,7 +64,7 @@ class AemBundleInfoWidget extends StatelessWidget {
Container(
child: Column(
children: [
...getBundleStatus,
...getBundleStatus(context),
],
),
margin: const EdgeInsets.fromLTRB(0, 30.0, 0, 0),
Expand All @@ -57,13 +75,13 @@ class AemBundleInfoWidget extends StatelessWidget {
),
margin: const EdgeInsets.fromLTRB(30.0, 0, 30.0, 0),
),
getExcludedBundles.length != 0
getExcludedBundles(context).length != 0
? Column(
children: [
DetailsHeader(
header: AppLocalizations.of(context).getTranslation('aemBundleInfo.exludedBundles'),
),
...getExcludedBundles,
...getExcludedBundles(context),
],
)
: DetailsHeader(header: AppLocalizations.of(context).getTranslation('aemBundleInfo.noExcludedBundles')),
Expand All @@ -73,13 +91,13 @@ class AemBundleInfoWidget extends StatelessWidget {
),
margin: const EdgeInsets.fromLTRB(30.0, 0, 30.0, 0),
),
getInactiveBundles.length != 0
getInactiveBundles(context).length != 0
? Column(
children: [
DetailsHeader(
header: AppLocalizations.of(context).getTranslation('aemBundleInfo.inactiveBundles'),
),
...getInactiveBundles,
...getInactiveBundles(context),
],
)
: DetailsHeader(header: AppLocalizations.of(context).getTranslation('aemBundleInfo.noInactiveBundles')),
Expand Down
8 changes: 5 additions & 3 deletions lib/widgets/widgets/aem_healthcheck/aem_healthcheck_item.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:cogboardmobileapp/utils/url_launcher.dart';
import 'package:flutter/material.dart';

class AemHealthcheckItem extends StatelessWidget {
class AemHealthcheckItem extends StatelessWidget with UrlLauncher {
final String healthcheckName;
final String healthcheckValue;
final String url;
Expand All @@ -11,7 +12,8 @@ class AemHealthcheckItem extends StatelessWidget {
@required this.url,
});

void openUrl() {
void openUrl(BuildContext context) {
launchUrl(url, context);
}

@override
Expand All @@ -34,7 +36,7 @@ class AemHealthcheckItem extends StatelessWidget {
),
margin: const EdgeInsets.fromLTRB(5.0, 0, 0, 0),
),
onTap: openUrl,
onTap: () => openUrl(context),
);
}
}
9 changes: 6 additions & 3 deletions lib/widgets/widgets/jira_buckets/jira_bucket_item.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import 'package:cogboardmobileapp/models/jira_bucket_model.dart';
import 'package:cogboardmobileapp/utils/url_launcher.dart';
import 'package:flutter/material.dart';

class JiraBucketItem extends StatelessWidget {
class JiraBucketItem extends StatelessWidget with UrlLauncher {
final JiraBucketModel bucket;

JiraBucketItem({
this.bucket,
});

void handleBucketPressed() {}
void handleBucketPressed(BuildContext context) {
launchUrl(bucket.url, context);
}

@override
Widget build(BuildContext context) {
Expand All @@ -27,7 +30,7 @@ class JiraBucketItem extends StatelessWidget {
),
margin: const EdgeInsets.fromLTRB(30.0, 10.0, 0, 10.0),
),
onTap: handleBucketPressed,
onTap: () => handleBucketPressed(context),
),
),
Expanded(
Expand Down
8 changes: 5 additions & 3 deletions lib/widgets/widgets/link_list/link_list_item.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:cogboardmobileapp/utils/url_launcher.dart';
import 'package:flutter/material.dart';

class LinkListItem extends StatelessWidget {
class LinkListItem extends StatelessWidget with UrlLauncher {
final String name;
final String url;

Expand All @@ -9,7 +10,8 @@ class LinkListItem extends StatelessWidget {
@required this.url,
});

void openUrl() {
void openUrl(BuildContext context) {
launchUrl(url, context);
}

@override
Expand All @@ -32,7 +34,7 @@ class LinkListItem extends StatelessWidget {
),
margin: const EdgeInsets.fromLTRB(5.0, 10, 0, 0),
),
onTap: openUrl,
onTap: () => openUrl(context),
);
}
}
11 changes: 7 additions & 4 deletions lib/widgets/widgets/open_url_button.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import 'package:cogboardmobileapp/constants/constants.dart';
import 'package:cogboardmobileapp/models/widget_model.dart';
import 'package:cogboardmobileapp/utils/url_launcher.dart';
import 'package:flutter/material.dart';

class OpenUrlButton extends StatelessWidget {
class OpenUrlButton extends StatelessWidget with UrlLauncher {
final DashboardWidget widget;

OpenUrlButton({
@required this.widget,
});

String get getWidgetUrl {
String get widgetUrl {
return widget.content['url'];
}

Expand All @@ -22,7 +23,9 @@ class OpenUrlButton extends StatelessWidget {
String get statusCodeMessage =>
errorStatus ? '$expectedStatusCode expected, got $statusCode' : widget.content['statusCode'].toString();

void openDetailsUrl() {}
void openDetailsUrl(BuildContext context) {
launchUrl(widgetUrl, context);
}

String get getUrlDisplayName {
switch (widget.type) {
Expand Down Expand Up @@ -54,7 +57,7 @@ class OpenUrlButton extends StatelessWidget {
padding: const EdgeInsets.all(30.0),
child: Container(
child: OutlineButton(
onPressed: openDetailsUrl,
onPressed: () => openDetailsUrl(context),
child: Text(
getUrlDisplayName,
style: TextStyle(
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ dependencies:
intl: ^0.16.1
flutter_local_notifications: ^3.0.0
timezone: ^0.5.9
url_launcher: ^5.7.10
toast: ^0.1.5
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
Expand Down