Add more menu and info popup
This commit is contained in:
parent
71272af69c
commit
99fe7de64b
|
@ -1,14 +1,26 @@
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
|
import 'package:esys_flutter_share/esys_flutter_share.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lemmur/util/goto.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 '../comment_tree.dart';
|
import '../comment_tree.dart';
|
||||||
import '../util/api_extensions.dart';
|
import '../util/api_extensions.dart';
|
||||||
|
import '../util/goto.dart';
|
||||||
import '../util/text_color.dart';
|
import '../util/text_color.dart';
|
||||||
|
import 'bottom_modal.dart';
|
||||||
import 'markdown_text.dart';
|
import 'markdown_text.dart';
|
||||||
|
|
||||||
|
const colors = [
|
||||||
|
Colors.pink,
|
||||||
|
Colors.green,
|
||||||
|
Colors.amber,
|
||||||
|
Colors.cyan,
|
||||||
|
Colors.indigo,
|
||||||
|
];
|
||||||
|
|
||||||
class Comment extends StatelessWidget {
|
class Comment extends StatelessWidget {
|
||||||
final int indent;
|
final int indent;
|
||||||
final int postCreatorId;
|
final int postCreatorId;
|
||||||
|
@ -19,8 +31,43 @@ class Comment extends StatelessWidget {
|
||||||
@required this.postCreatorId,
|
@required this.postCreatorId,
|
||||||
});
|
});
|
||||||
|
|
||||||
void _openMoreMenu() {
|
void _openMoreMenu(BuildContext context) {
|
||||||
print('OPEN MORE MENU');
|
final com = commentTree.comment;
|
||||||
|
showModalBottomSheet(
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
context: context,
|
||||||
|
builder: (context) => BottomModal(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
leading: Icon(Icons.open_in_browser),
|
||||||
|
title: Text('Open in browser'),
|
||||||
|
onTap: () async => await ul.canLaunch(com.apId)
|
||||||
|
? ul.launch(com.apId)
|
||||||
|
: Scaffold.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("can't open in browser"))),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: Icon(Icons.share),
|
||||||
|
title: Text('Share url'),
|
||||||
|
onTap: () =>
|
||||||
|
Share.text('Share comment url', com.apId, 'text/plain'),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: Icon(Icons.share),
|
||||||
|
title: Text('Share text'),
|
||||||
|
onTap: () =>
|
||||||
|
Share.text('Share comment text', com.content, 'text/plain'),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: Icon(Icons.info_outline),
|
||||||
|
title: Text('Nerd stuff'),
|
||||||
|
onTap: () => _showCommentInfo(context),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _save(bool save) {
|
void _save(bool save) {
|
||||||
|
@ -35,6 +82,61 @@ class Comment extends StatelessWidget {
|
||||||
print('COMMENT VOTE: ${vote.toString()}');
|
print('COMMENT VOTE: ${vote.toString()}');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_showCommentInfo(BuildContext context) {
|
||||||
|
print('hello');
|
||||||
|
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'),
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
bool get isOP => commentTree.comment.creatorId == postCreatorId;
|
bool get isOP => commentTree.comment.creatorId == postCreatorId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -112,16 +214,23 @@ class Comment extends StatelessWidget {
|
||||||
if (comment.bannedFromCommunity)
|
if (comment.bannedFromCommunity)
|
||||||
_CommentTag('BANNED FROM COMMUNITY', Colors.red),
|
_CommentTag('BANNED FROM COMMUNITY', Colors.red),
|
||||||
Spacer(),
|
Spacer(),
|
||||||
Text(comment.score.toString()),
|
InkWell(
|
||||||
Text(' · '),
|
onTap: () => _showCommentInfo(context),
|
||||||
Text(timeago.format(comment.published, locale: 'en_short')),
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Text(comment.score.toString()),
|
||||||
|
Text(' · '),
|
||||||
|
Text(timeago.format(comment.published)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
]),
|
]),
|
||||||
Row(children: [body]),
|
Row(children: [body]),
|
||||||
Row(children: [
|
Row(children: [
|
||||||
Spacer(),
|
Spacer(),
|
||||||
_CommentAction(
|
_CommentAction(
|
||||||
icon: Icons.more_horiz,
|
icon: Icons.more_horiz,
|
||||||
onPressed: _openMoreMenu,
|
onPressed: () => _openMoreMenu(context),
|
||||||
tooltip: 'more',
|
tooltip: 'more',
|
||||||
),
|
),
|
||||||
_CommentAction(
|
_CommentAction(
|
||||||
|
@ -152,7 +261,8 @@ class Comment extends StatelessWidget {
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border(
|
border: Border(
|
||||||
left: indent > 0
|
left: indent > 0
|
||||||
? BorderSide(color: Colors.red, width: 5)
|
? BorderSide(
|
||||||
|
color: colors[indent % colors.length], width: 5)
|
||||||
: BorderSide.none,
|
: BorderSide.none,
|
||||||
top: BorderSide(width: 0.2))),
|
top: BorderSide(width: 0.2))),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue