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

Fix open github docs for postcard #1321

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 6 additions & 9 deletions lib/screen/github_doc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
// that can be found in the LICENSE file.
//

import 'package:autonomy_flutter/screen/app_router.dart';
import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/dio_interceptors.dart';
import 'package:autonomy_flutter/util/dio_util.dart';
import 'package:autonomy_flutter/util/string_ext.dart';
import 'package:autonomy_flutter/util/style.dart';
import 'package:autonomy_flutter/view/back_appbar.dart';
import 'package:autonomy_flutter/view/responsive.dart';
Expand All @@ -32,6 +34,7 @@ class GithubDocPage extends StatefulWidget {
class _GithubDocPageState extends State<GithubDocPage> {
late String document;
late String title;
final _navigationService = injector<NavigationService>();

final dio = baseDio(BaseOptions(
baseUrl: "https://raw.githubusercontent.com",
Expand Down Expand Up @@ -83,14 +86,8 @@ class _GithubDocPageState extends State<GithubDocPage> {
styleSheet: markDownLightStyle(context),
onTapLink: (text, href, title) async {
if (href == null) return;
if (!(await canLaunchUrlString(href))) {
if (!mounted) return;
Navigator.of(context).pushNamed(AppRouter.githubDocPage,
arguments: {
"prefix": widget.payload["prefix"] ?? '',
"document": href,
"title": ""
});
if (href.isAutonomyDocumentLink) {
_navigationService.openAutonomyDocument(href, title);
} else {
launchUrlString(href);
}
Expand Down
20 changes: 11 additions & 9 deletions lib/screen/interactive_postcard/postcard_explain.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/service/postcard_service.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/distance_formater.dart';
Expand All @@ -14,7 +15,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';
import 'package:nft_collection/models/asset_token.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:video_player/video_player.dart';

class PostcardExplain extends StatefulWidget {
Expand All @@ -28,6 +28,7 @@ class PostcardExplain extends StatefulWidget {
}

class _PostcardExplainState extends State<PostcardExplain> {
final _navigationService = injector<NavigationService>();
final VideoPlayerController _controller =
VideoPlayerController.asset("assets/videos/postcard_explain.mp4");
final VideoPlayerController _colouringController =
Expand Down Expand Up @@ -224,14 +225,15 @@ class _PostcardExplainState extends State<PostcardExplain> {
text: "by_continuing".tr(),
),
TextSpan(
text: "terms_and_conditions".tr(),
style: termsConditionsStyle.copyWith(
decoration: TextDecoration.underline),
recognizer: TapGestureRecognizer()
..onTap = () => launchUrl(
Uri.parse(MOMA_TERMS_CONDITIONS_URL),
mode: LaunchMode.externalApplication),
),
text: "terms_and_conditions".tr(),
style: termsConditionsStyle.copyWith(
decoration: TextDecoration.underline),
recognizer: TapGestureRecognizer()
..onTap = () {
_navigationService.openAutonomyDocument(
MOMA_TERMS_CONDITIONS_URL,
"terms_and_conditions".tr());
}),
const TextSpan(
text: ".",
),
Expand Down
21 changes: 18 additions & 3 deletions lib/service/navigation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/error_handler.dart';
import 'package:autonomy_flutter/util/inapp_notifications.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:autonomy_flutter/util/string_ext.dart';
import 'package:autonomy_flutter/util/style.dart';
import 'package:autonomy_flutter/util/ui_helper.dart';
import 'package:autonomy_theme/autonomy_theme.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:nft_collection/models/asset_token.dart';

// ignore: implementation_imports
import 'package:nft_collection/models/asset_token.dart'; // ignore: implementation_imports
import 'package:overlay_support/src/overlay_state_finder.dart';

class NavigationService {
Expand Down Expand Up @@ -361,4 +360,20 @@ class NavigationService {
await UIHelper.showPostcardQRExpired(navigatorKey.currentContext!);
}
}

Future<void> openAutonomyDocument(String href, String title) async {
if (navigatorKey.currentContext != null &&
navigatorKey.currentState?.mounted == true) {
final uri = Uri.parse(href.autonomyRawDocumentLink);
final document = uri.pathSegments.last;
final prefix =
uri.pathSegments.sublist(0, uri.pathSegments.length - 1).join("/");
await Navigator.of(navigatorKey.currentContext!)
.pushNamed(AppRouter.githubDocPage, arguments: {
"prefix": "/$prefix/",
"document": document,
"title": title,
});
}
}
}
7 changes: 7 additions & 0 deletions lib/util/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ const TV_APP_STORE_URL =
const MOMA_TERMS_CONDITIONS_URL =
"https://github.com/bitmark-inc/autonomy-apps/blob/main/docs/postcard_terms.md";

const AUTONOMY_DOCUMENT_PREFIX = "https://github.com/bitmark-inc";

const AUTONOMY_RAW_DOCUMENT_PREFIX =
"https://raw.githubusercontent.com/bitmark-inc";

const MARKDOWN_EXT = ".md";

const String POSTCARD_SIGN_PREFIX = "Tezos Signed Message:";

const CONNECT_FAILED_DURATION = Duration(seconds: 10);
Expand Down
12 changes: 12 additions & 0 deletions lib/util/string_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import 'package:autonomy_flutter/common/environment.dart';
import 'package:autonomy_flutter/util/constants.dart';

extension StringExtension on String {
String capitalize() {
Expand Down Expand Up @@ -82,4 +83,15 @@ extension StringExtension on String {
return splitted.length > 1 &&
splitted[1] == Environment.postcardContractAddress;
}

bool get isAutonomyDocumentLink {
return (startsWith(AUTONOMY_DOCUMENT_PREFIX) ||
startsWith(AUTONOMY_RAW_DOCUMENT_PREFIX)) &&
endsWith(MARKDOWN_EXT);
}

String get autonomyRawDocumentLink {
return replaceFirst(AUTONOMY_DOCUMENT_PREFIX, AUTONOMY_RAW_DOCUMENT_PREFIX)
.replaceFirst("/blob/", "/");
}
}
5 changes: 5 additions & 0 deletions lib/view/artwork_common_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/customer_support_service.dart';
import 'package:autonomy_flutter/service/feralfile_service.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/util/address_utils.dart';
import 'package:autonomy_flutter/util/asset_token_ext.dart';
import 'package:autonomy_flutter/util/au_icons.dart';
Expand Down Expand Up @@ -1864,6 +1865,10 @@ class _PostcardRightsViewState extends State<PostcardRightsView> {
styleSheet: markDownPostcardRightStyle(context),
onTapLink: (text, href, title) async {
if (href == null) return;
if (href.isAutonomyDocumentLink) {
injector<NavigationService>()
.openAutonomyDocument(href, title);
}
launchUrl(Uri.parse(href),
mode: LaunchMode.externalApplication);
},
Expand Down