-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add instance page to long press menu (#824)
* Add instance page * Use new AppLocalizations style * Remove strings from es * Update gesture setting for instance page * Remove alternateSiteName * Remove unnecessary strings
- Loading branch information
Showing
8 changed files
with
179 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:lemmy_api_client/v3.dart'; | ||
import 'package:thunder/instance/instance_view.dart'; | ||
import 'package:thunder/utils/instance.dart'; | ||
import 'package:thunder/utils/links.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
|
||
class InstancePage extends StatefulWidget { | ||
final Site site; | ||
|
||
const InstancePage({ | ||
super.key, | ||
required this.site, | ||
}); | ||
|
||
@override | ||
State<InstancePage> createState() => _InstancePageState(); | ||
} | ||
|
||
class _InstancePageState extends State<InstancePage> { | ||
@override | ||
Widget build(BuildContext context) { | ||
final AppLocalizations l10n = AppLocalizations.of(context)!; | ||
final ThemeData theme = Theme.of(context); | ||
|
||
return Container( | ||
color: theme.colorScheme.background, | ||
child: SafeArea( | ||
top: false, | ||
child: CustomScrollView( | ||
slivers: <Widget>[ | ||
SliverAppBar( | ||
pinned: true, | ||
title: Text(fetchInstanceNameFromUrl(widget.site.actorId) ?? ''), | ||
actions: [ | ||
IconButton( | ||
tooltip: l10n.openInBrowser, | ||
onPressed: () => openLink(context, url: widget.site.actorId), | ||
icon: Icon( | ||
Icons.open_in_browser_rounded, | ||
semanticLabel: l10n.openInBrowser, | ||
), | ||
), | ||
], | ||
), | ||
SliverToBoxAdapter( | ||
child: Padding( | ||
padding: const EdgeInsets.all(20), | ||
child: Material( | ||
child: InstanceView(site: widget.site), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:cached_network_image/cached_network_image.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:lemmy_api_client/v3.dart'; | ||
import 'package:thunder/shared/common_markdown_body.dart'; | ||
|
||
class InstanceView extends StatelessWidget { | ||
final Site site; | ||
|
||
const InstanceView({super.key, required this.site}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final ThemeData theme = Theme.of(context); | ||
|
||
return Column( | ||
children: [ | ||
Row( | ||
children: [ | ||
CircleAvatar( | ||
backgroundColor: site.icon != null ? Colors.transparent : theme.colorScheme.secondaryContainer, | ||
foregroundImage: site.icon != null ? CachedNetworkImageProvider(site.icon!) : null, | ||
maxRadius: 24, | ||
child: site.icon == null | ||
? Text( | ||
site.name[0], | ||
semanticsLabel: '', | ||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16), | ||
) | ||
: null, | ||
), | ||
const SizedBox(width: 16.0), | ||
Expanded( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.start, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Text( | ||
site.name, | ||
overflow: TextOverflow.ellipsis, | ||
maxLines: 1, | ||
style: theme.textTheme.headlineSmall?.copyWith(fontWeight: FontWeight.w600), | ||
), | ||
Row( | ||
children: [ | ||
Flexible( | ||
child: Text( | ||
site.description ?? '', | ||
style: theme.textTheme.bodyMedium, | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
const Divider(), | ||
CommonMarkdownBody(body: site.sidebar ?? ''), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:lemmy_api_client/v3.dart'; | ||
import 'package:swipeable_page_route/swipeable_page_route.dart'; | ||
import 'package:thunder/core/auth/bloc/auth_bloc.dart'; | ||
import 'package:thunder/instance/instance_page.dart'; | ||
import 'package:thunder/thunder/bloc/thunder_bloc.dart'; | ||
import 'package:thunder/utils/swipe.dart'; | ||
|
||
Future<void> navigateToInstancePage(BuildContext context, {required String instanceHost}) async { | ||
ThunderBloc thunderBloc = context.read<ThunderBloc>(); | ||
AuthBloc authBloc = context.read<AuthBloc>(); | ||
|
||
final bool reduceAnimations = thunderBloc.state.reduceAnimations; | ||
|
||
FullSiteView? fullSiteView; | ||
try { | ||
fullSiteView = await LemmyApiV3(instanceHost).run(const GetSite()).timeout(const Duration(seconds: 5)); | ||
} catch (e) {} | ||
|
||
if (fullSiteView?.siteView?.site != null && context.mounted) { | ||
Navigator.of(context).push( | ||
SwipeablePageRoute( | ||
transitionDuration: reduceAnimations ? const Duration(milliseconds: 100) : null, | ||
backGestureDetectionWidth: 45, | ||
canOnlySwipeFromEdge: !thunderBloc.state.enableFullScreenSwipeNavigationGesture, | ||
builder: (context) => MultiBlocProvider( | ||
providers: [ | ||
BlocProvider.value(value: thunderBloc), | ||
], | ||
child: InstancePage( | ||
site: fullSiteView!.siteView!.site, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |