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/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:intl/intl.dart';
import 'package:lemmy_api_client/lemmy_api_client.dart';
import 'package:url_launcher/url_launcher.dart' as ul;
@ -18,6 +17,7 @@ import '../util/text_color.dart';
import '../widgets/badge.dart';
import '../widgets/bottom_modal.dart';
import '../widgets/fullscreenable_image.dart';
import '../widgets/info_table_popup.dart';
import '../widgets/markdown_text.dart';
import '../widgets/sortable_infinite_list.dart';
@ -131,33 +131,13 @@ class CommunityPage extends HookWidget {
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('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)}'''),
]),
],
),
]));
showInfoTablePopup(context, {
'id': community.id,
'actorId': community.actorId,
'created by': '@${community.creatorName}',
'hot rank': community.hotRank,
'published': 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/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:intl/intl.dart';
import 'package:lemmy_api_client/lemmy_api_client.dart';
import 'package:url_launcher/url_launcher.dart' as ul;
import '../hooks/stores.dart';
import '../util/extensions/api.dart';
import '../util/goto.dart';
import '../util/text_color.dart';
import '../widgets/badge.dart';
import '../widgets/bottom_modal.dart';
import '../widgets/fullscreenable_image.dart';
import '../widgets/info_table_popup.dart';
import '../widgets/markdown_text.dart';
import '../widgets/sortable_infinite_list.dart';
import 'communities_list.dart';
@ -70,73 +68,15 @@ class InstancePage extends HookWidget {
final site = siteSnap.data;
void _openMoreMenu(BuildContext c) {
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: c,
builder: (context) => BottomModal(
child: Column(
children: [
ListTile(
leading: Icon(Icons.open_in_browser),
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)),
]),
],
),
]));
},
),
],
),
),
);
showInfoTablePopup(context, {
'url': instanceUrl,
'creator': '@${site.site.creatorName}',
'version': site.version,
'enableDownvotes': site.site.enableDownvotes,
'enableNsfw': site.site.enableNsfw,
'published': site.site.published,
'updated': site.site.updated,
});
}
return Scaffold(

View File

@ -4,7 +4,6 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:intl/intl.dart';
import 'package:lemmy_api_client/lemmy_api_client.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:url_launcher/url_launcher.dart' as ul;
@ -17,6 +16,7 @@ import '../util/goto.dart';
import '../util/intl.dart';
import '../util/text_color.dart';
import 'bottom_modal.dart';
import 'info_table_popup.dart';
import 'markdown_text.dart';
import 'write_comment.dart';
@ -45,56 +45,20 @@ class Comment extends HookWidget {
_showCommentInfo(BuildContext context) {
final com = commentTree.comment;
showDialog(
context: context,
child: SimpleDialog(
contentPadding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 15,
),
children: [
Table(
children: [
TableRow(children: [
Text('upvotes:'),
Text(com.upvotes.toString()),
]),
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'),
]),
],
),
]));
showInfoTablePopup(context, {
'id': com.id,
'apId': com.apId,
'userId': com.userId,
'upvotes': com.upvotes,
'downvotes': com.downvotes,
'score': com.score,
'% of upvotes':
'${(100 * (com.upvotes / (com.upvotes + com.downvotes)))}%',
'hotRank': com.hotRank,
'hotRankActive': com.hotRankActive,
'published': com.published,
'updated': com.updated,
});
}
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 'bottom_modal.dart';
import 'fullscreenable_image.dart';
import 'info_table_popup.dart';
import 'markdown_text.dart';
import 'save_post_button.dart';
@ -73,59 +74,21 @@ class Post extends HookWidget {
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('upvotes:'),
Text(post.upvotes.toString()),
]),
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'),
]),
],
),
],
),
);
showInfoTablePopup(context, {
'id': post.id,
'apId': post.apId,
'upvotes': post.upvotes,
'downvotes': post.downvotes,
'score': post.score,
'% of upvotes':
'''${(100 * (post.upvotes / (post.upvotes + post.downvotes))).toInt()}%''',
'hotRank': post.hotRank,
'hotRank active': post.hotRankActive,
'local': post.local,
'published': post.published,
'updated': post.updated ?? 'never',
'newestActivityTime': post.newestActivityTime,
});
},
),
],