Merge pull request #80 from krawieck/info-table-popup

Info table popup
This commit is contained in:
Marcin Wojnarowski 2020-10-27 21:16:19 +00:00 committed by GitHub
commit ff2942fae4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 202 deletions

View File

@ -3,7 +3,6 @@ import 'package:esys_flutter_share/esys_flutter_share.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:intl/intl.dart';
import 'package:lemmy_api_client/lemmy_api_client.dart'; import 'package:lemmy_api_client/lemmy_api_client.dart';
import 'package:url_launcher/url_launcher.dart' as ul; import 'package:url_launcher/url_launcher.dart' as ul;
@ -18,6 +17,7 @@ import '../util/text_color.dart';
import '../widgets/badge.dart'; import '../widgets/badge.dart';
import '../widgets/bottom_modal.dart'; import '../widgets/bottom_modal.dart';
import '../widgets/fullscreenable_image.dart'; import '../widgets/fullscreenable_image.dart';
import '../widgets/info_table_popup.dart';
import '../widgets/markdown_text.dart'; import '../widgets/markdown_text.dart';
import '../widgets/sortable_infinite_list.dart'; import '../widgets/sortable_infinite_list.dart';
@ -131,33 +131,13 @@ class CommunityPage extends HookWidget {
leading: Icon(Icons.info_outline), leading: Icon(Icons.info_outline),
title: Text('Nerd stuff'), title: Text('Nerd stuff'),
onTap: () { onTap: () {
showDialog( showInfoTablePopup(context, {
context: context, 'id': community.id,
child: SimpleDialog( 'actorId': community.actorId,
contentPadding: const EdgeInsets.symmetric( 'created by': '@${community.creatorName}',
horizontal: 20, 'hot rank': community.hotRank,
vertical: 15, 'published': community.published,
), });
children: [
Table(
children: [
TableRow(children: [
Text('created by:'),
Text('@${community.creatorName}'),
]),
TableRow(children: [
Text('hot rank:'),
Text(community.hotRank.toString()),
]),
TableRow(children: [
Text('published:'),
Text(
'''${DateFormat.yMMMd().format(community.published)}'''
''' ${DateFormat.Hms().format(community.published)}'''),
]),
],
),
]));
}, },
), ),
], ],

View File

@ -3,17 +3,15 @@ import 'package:esys_flutter_share/esys_flutter_share.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:intl/intl.dart';
import 'package:lemmy_api_client/lemmy_api_client.dart'; import 'package:lemmy_api_client/lemmy_api_client.dart';
import 'package:url_launcher/url_launcher.dart' as ul;
import '../hooks/stores.dart'; import '../hooks/stores.dart';
import '../util/extensions/api.dart'; import '../util/extensions/api.dart';
import '../util/goto.dart'; import '../util/goto.dart';
import '../util/text_color.dart'; import '../util/text_color.dart';
import '../widgets/badge.dart'; import '../widgets/badge.dart';
import '../widgets/bottom_modal.dart';
import '../widgets/fullscreenable_image.dart'; import '../widgets/fullscreenable_image.dart';
import '../widgets/info_table_popup.dart';
import '../widgets/markdown_text.dart'; import '../widgets/markdown_text.dart';
import '../widgets/sortable_infinite_list.dart'; import '../widgets/sortable_infinite_list.dart';
import 'communities_list.dart'; import 'communities_list.dart';
@ -70,73 +68,15 @@ class InstancePage extends HookWidget {
final site = siteSnap.data; final site = siteSnap.data;
void _openMoreMenu(BuildContext c) { void _openMoreMenu(BuildContext c) {
showModalBottomSheet( showInfoTablePopup(context, {
backgroundColor: Colors.transparent, 'url': instanceUrl,
context: c, 'creator': '@${site.site.creatorName}',
builder: (context) => BottomModal( 'version': site.version,
child: Column( 'enableDownvotes': site.site.enableDownvotes,
children: [ 'enableNsfw': site.site.enableNsfw,
ListTile( 'published': site.site.published,
leading: Icon(Icons.open_in_browser), 'updated': site.site.updated,
title: Text('Open in browser'), });
onTap: () async => await ul.canLaunch('https://$instanceUrl')
? ul.launch('https://$instanceUrl')
: Scaffold.of(context).showSnackBar(
SnackBar(content: Text("can't open in browser"))),
),
ListTile(
leading: Icon(Icons.info_outline),
title: Text('Nerd stuff'),
onTap: () {
showDialog(
context: context,
child: SimpleDialog(
contentPadding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 15,
),
children: [
Table(
children: [
TableRow(children: [
Text('url:'),
Text(instanceUrl),
]),
TableRow(children: [
Text('creator:'),
Text('@${site.site.creatorName}')
]),
TableRow(children: [
Text('version:'),
Text(site.version),
]),
TableRow(children: [
Text('enableDownvotes:'),
Text(site.site.enableDownvotes.toString()),
]),
TableRow(children: [
Text('enableNsfw:'),
Text(site.site.enableNsfw.toString()),
]),
TableRow(children: [
Text('published:'),
Text(DateFormat.yMMMMd()
.format(site.site.published)),
]),
TableRow(children: [
Text('updated:'),
Text(DateFormat.yMMMMd()
.format(site.site.updated)),
]),
],
),
]));
},
),
],
),
),
);
} }
return Scaffold( return Scaffold(

View File

@ -4,7 +4,6 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:intl/intl.dart';
import 'package:lemmy_api_client/lemmy_api_client.dart'; import 'package:lemmy_api_client/lemmy_api_client.dart';
import 'package:timeago/timeago.dart' as timeago; import 'package:timeago/timeago.dart' as timeago;
import 'package:url_launcher/url_launcher.dart' as ul; import 'package:url_launcher/url_launcher.dart' as ul;
@ -17,6 +16,7 @@ import '../util/goto.dart';
import '../util/intl.dart'; import '../util/intl.dart';
import '../util/text_color.dart'; import '../util/text_color.dart';
import 'bottom_modal.dart'; import 'bottom_modal.dart';
import 'info_table_popup.dart';
import 'markdown_text.dart'; import 'markdown_text.dart';
import 'write_comment.dart'; import 'write_comment.dart';
@ -45,56 +45,20 @@ class Comment extends HookWidget {
_showCommentInfo(BuildContext context) { _showCommentInfo(BuildContext context) {
final com = commentTree.comment; final com = commentTree.comment;
showDialog( showInfoTablePopup(context, {
context: context, 'id': com.id,
child: SimpleDialog( 'apId': com.apId,
contentPadding: const EdgeInsets.symmetric( 'userId': com.userId,
horizontal: 20, 'upvotes': com.upvotes,
vertical: 15, 'downvotes': com.downvotes,
), 'score': com.score,
children: [ '% of upvotes':
Table( '${(100 * (com.upvotes / (com.upvotes + com.downvotes)))}%',
children: [ 'hotRank': com.hotRank,
TableRow(children: [ 'hotRankActive': com.hotRankActive,
Text('upvotes:'), 'published': com.published,
Text(com.upvotes.toString()), 'updated': com.updated,
]), });
TableRow(children: [
Text('downvotes:'),
Text(com.downvotes.toString()),
]),
TableRow(children: [
Text('score:'),
Text(com.score.toString()),
]),
TableRow(children: [
Text('% of upvotes:'),
Text(
'''${(100 * (com.upvotes / (com.upvotes + com.downvotes))).toInt()}%'''),
]),
TableRow(children: [
Text('hotrank:'),
Text(com.hotRank.toString()),
]),
TableRow(children: [
Text('hotrank active:'),
Text(com.hotRankActive.toString()),
]),
TableRow(children: [
Text('published:'),
Text('''${DateFormat.yMMMd().format(com.published)}'''
''' ${DateFormat.Hms().format(com.published)}'''),
]),
TableRow(children: [
Text('updated:'),
Text(com.updated != null
? '''${DateFormat.yMMMd().format(com.updated)}'''
''' ${DateFormat.Hms().format(com.updated)}'''
: 'never'),
]),
],
),
]));
} }
bool get isOP => commentTree.comment.creatorId == postCreatorId; bool get isOP => commentTree.comment.creatorId == postCreatorId;

View File

@ -0,0 +1,21 @@
import 'package:flutter/material.dart';
void showInfoTablePopup(BuildContext context, Map<String, dynamic> table) {
showDialog(
context: context,
child: SimpleDialog(
contentPadding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 15,
),
children: [
Table(
children: table.entries
.map((e) => TableRow(
children: [Text('${e.key}:'), Text(e.value.toString())]))
.toList(),
),
],
),
);
}

View File

@ -17,6 +17,7 @@ import '../util/extensions/api.dart';
import '../util/goto.dart'; import '../util/goto.dart';
import 'bottom_modal.dart'; import 'bottom_modal.dart';
import 'fullscreenable_image.dart'; import 'fullscreenable_image.dart';
import 'info_table_popup.dart';
import 'markdown_text.dart'; import 'markdown_text.dart';
import 'save_post_button.dart'; import 'save_post_button.dart';
@ -73,59 +74,21 @@ class Post extends HookWidget {
leading: Icon(Icons.info_outline), leading: Icon(Icons.info_outline),
title: Text('Nerd stuff'), title: Text('Nerd stuff'),
onTap: () { onTap: () {
showDialog( showInfoTablePopup(context, {
context: context, 'id': post.id,
child: SimpleDialog( 'apId': post.apId,
contentPadding: const EdgeInsets.symmetric( 'upvotes': post.upvotes,
horizontal: 20, 'downvotes': post.downvotes,
vertical: 15, 'score': post.score,
), '% of upvotes':
children: [ '''${(100 * (post.upvotes / (post.upvotes + post.downvotes))).toInt()}%''',
Table( 'hotRank': post.hotRank,
children: [ 'hotRank active': post.hotRankActive,
TableRow(children: [ 'local': post.local,
Text('upvotes:'), 'published': post.published,
Text(post.upvotes.toString()), 'updated': post.updated ?? 'never',
]), 'newestActivityTime': post.newestActivityTime,
TableRow(children: [ });
Text('downvotes:'),
Text(post.downvotes.toString()),
]),
TableRow(children: [
Text('score:'),
Text(post.score.toString()),
]),
TableRow(children: [
Text('% of upvotes:'),
Text(
'''${(100 * (post.upvotes / (post.upvotes + post.downvotes))).toInt()}%'''),
]),
TableRow(children: [
Text('hotrank:'),
Text(post.hotRank.toString()),
]),
TableRow(children: [
Text('hotrank active:'),
Text(post.hotRankActive.toString()),
]),
TableRow(children: [
Text('published:'),
Text(
'''${DateFormat.yMMMd().format(post.published)}'''
''' ${DateFormat.Hms().format(post.published)}'''),
]),
TableRow(children: [
Text('updated:'),
Text(post.updated != null
? '''${DateFormat.yMMMd().format(post.updated)}'''
''' ${DateFormat.Hms().format(post.updated)}'''
: 'never'),
]),
],
),
],
),
);
}, },
), ),
], ],