Skip to content

Commit

Permalink
Add support for alternate link sources (#1516)
Browse files Browse the repository at this point in the history
* Support alternative link sources

* Alternative -> Alternate

* Ensure alternate navigation occurs within same webview
  • Loading branch information
micahmo authored Sep 26, 2024
1 parent 08fc608 commit cc58c97
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 62 deletions.
4 changes: 4 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
},
"alreadyPostedTo": "Already posted to",
"@alreadyPostedTo": {},
"alternateSources": "Alternate Sources",
"@alternateSources": {
"description": "Action for viewing a link from alternate sources"
},
"always": "Always",
"@always": {},
"andXMore": "and {count} more",
Expand Down
15 changes: 15 additions & 0 deletions lib/post/pages/legacy_post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:super_sliver_list/super_sliver_list.dart';
import 'package:thunder/comment/utils/navigate_comment.dart';
import 'package:thunder/core/auth/bloc/auth_bloc.dart';
import 'package:thunder/core/enums/fab_action.dart';
import 'package:thunder/core/enums/media_type.dart';
import 'package:thunder/core/models/comment_view_tree.dart';
import 'package:thunder/core/models/post_view_media.dart';
import 'package:thunder/core/singletons/lemmy_client.dart';
Expand All @@ -31,6 +32,7 @@ import 'package:thunder/shared/snackbar.dart';
import 'package:thunder/shared/text/selectable_text_modal.dart';
import 'package:thunder/shared/thunder_popup_menu_item.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/links.dart';

@Deprecated('Use the new PostPage widget')
class PostPage extends StatefulWidget {
Expand Down Expand Up @@ -231,6 +233,19 @@ class _PostPageState extends State<PostPage> {
icon: Icons.select_all_rounded,
title: l10n.selectText,
),
if (state.postView?.media.first.mediaType == MediaType.link && state.postView!.media.first.originalUrl?.isNotEmpty == true)
ThunderPopupMenuItem(
onTap: () {
handleLinkLongPress(
context,
state.postView!.media.first.originalUrl!,
state.postView!.media.first.originalUrl!,
initialPage: LinkBottomSheetPage.alternateLinks,
);
},
icon: Icons.link_rounded,
title: l10n.alternateSources,
),
],
),
],
Expand Down
15 changes: 15 additions & 0 deletions lib/post/widgets/post_page_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/services.dart';

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:thunder/core/enums/media_type.dart';
import 'package:thunder/core/models/post_view_media.dart';

import 'package:thunder/core/singletons/lemmy_client.dart';
Expand All @@ -12,6 +13,7 @@ import 'package:thunder/shared/sort_picker.dart';
import 'package:thunder/shared/thunder_popup_menu_item.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/user/widgets/user_selector.dart';
import 'package:thunder/utils/links.dart';

/// Holds the app bar for the post page.
class PostPageAppBar extends StatelessWidget {
Expand Down Expand Up @@ -201,6 +203,19 @@ class PostAppBarActions extends StatelessWidget {
icon: Icons.people_alt_rounded,
title: l10n.viewPostAsDifferentAccount,
),
if (state.postView?.media.first.mediaType == MediaType.link && state.postView!.media.first.originalUrl?.isNotEmpty == true)
ThunderPopupMenuItem(
onTap: () {
handleLinkLongPress(
context,
state.postView!.media.first.originalUrl!,
state.postView!.media.first.originalUrl!,
initialPage: LinkBottomSheetPage.alternateLinks,
);
},
icon: Icons.link_rounded,
title: l10n.alternateSources,
),
],
),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/common_markdown_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class CommonMarkdownBody extends StatelessWidget {
);
},
onTapLink: (text, url, title) => handleLinkTap(context, state, text, url),
onLongPressLink: (text, url, title) => handleLinkLongPress(context, state, text, url),
onLongPressLink: (text, url, title) => handleLinkLongPress(context, text, url),
styleSheet: hideContent
? spoilerMarkdownStyleSheet
: MarkdownStyleSheet.fromTheme(theme).copyWith(
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/link_information.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _LinkInformationState extends State<LinkInformation> {
}

if (widget.mediaType == MediaType.link) {
handleLinkLongPress(context, state, widget.originURL!, widget.originURL);
handleLinkLongPress(context, widget.originURL!, widget.originURL);
}
},
child: Container(
Expand Down
4 changes: 2 additions & 2 deletions lib/shared/link_preview_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class LinkPreviewCard extends StatelessWidget {
child: InkWell(
splashColor: theme.colorScheme.primary.withOpacity(0.4),
onTap: () => triggerOnTap(context),
onLongPress: originURL != null ? () => handleLinkLongPress(context, thunderState, originURL!, originURL) : null,
onLongPress: originURL != null ? () => handleLinkLongPress(context, originURL!, originURL) : null,
borderRadius: BorderRadius.circular((edgeToEdgeImages ? 0 : 12)),
),
),
Expand Down Expand Up @@ -226,7 +226,7 @@ class LinkPreviewCard extends StatelessWidget {
child: InkWell(
splashColor: theme.colorScheme.primary.withOpacity(0.4),
onTap: () => triggerOnTap(context),
onLongPress: originURL != null ? () => handleLinkLongPress(context, thunderState, originURL!, originURL) : null,
onLongPress: originURL != null ? () => handleLinkLongPress(context, originURL!, originURL) : null,
),
),
),
Expand Down
14 changes: 14 additions & 0 deletions lib/shared/webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import 'package:thunder/shared/thunder_popup_menu_item.dart';
import 'package:thunder/utils/links.dart';
import 'package:url_launcher/url_launcher.dart';

import 'package:webview_flutter/webview_flutter.dart';
Expand Down Expand Up @@ -162,6 +163,19 @@ class NavigationControls extends StatelessWidget {
icon: Icons.share_rounded,
title: l10n.share,
),
ThunderPopupMenuItem(
onTap: () {
handleLinkLongPress(
context,
url,
url,
initialPage: LinkBottomSheetPage.alternateLinks,
customNavigation: (url) => webViewController.loadRequest(Uri.parse(url)),
);
},
icon: Icons.link_rounded,
title: l10n.alternateSources,
),
],
),
const SizedBox(width: 8.0),
Expand Down
Loading

0 comments on commit cc58c97

Please sign in to comment.