Redesign interactions bar and move delving into detailed data to menu

codemagic-setup
Hank Grabowski 2023-11-18 15:13:42 -05:00
rodzic e3967b89bc
commit 3f23e3e2fd
2 zmienionych plików z 100 dodań i 61 usunięć

Wyświetl plik

@ -245,19 +245,28 @@ class _StatusControlState extends State<FlattenedTreeEntryControl> {
Widget buildMenuControl(BuildContext context) {
const editStatus = 'Edit';
const deleteStatus = 'Delete';
const divider = 'Divider';
const goToPost = 'Open Post';
const copyText = 'Copy Post Text';
const copyUrl = 'Copy URL';
const openExternal = 'Open In Browser';
const showLikers = 'Show Likers';
const showResharers = 'Show Reshares';
final options = [
if (widget.showStatusOpenButton && !widget.openRemote) goToPost,
if (item.isMine && !item.timelineEntry.youReshared) editStatus,
if (item.isMine) deleteStatus,
copyText,
divider,
showLikers,
showResharers,
divider,
openExternal,
copyUrl,
copyText,
];
final entry = widget.originalItem.timelineEntry;
return PopupMenuButton<String>(onSelected: (menuOption) async {
if (!mounted) {
return;
@ -299,12 +308,29 @@ class _StatusControlState extends State<FlattenedTreeEntryControl> {
message: 'Post link copied to clipboard',
);
break;
case showLikers:
await context.push('/likes/${entry.id}');
break;
case showResharers:
await context.push('/reshares/${entry.id}');
break;
default:
//do nothing
}
}, itemBuilder: (context) {
return options
.map((o) => PopupMenuItem(value: o, child: Text(o)))
.map(
(o) => PopupMenuItem(
value: o,
enabled: switch (o) {
divider => false,
showResharers => entry.engagementSummary.rebloggedCount > 0,
showLikers => entry.engagementSummary.favoritesCount > 0,
_ => true,
},
child: o == divider ? const Divider() : Text(o),
),
)
.toList();
});
}

Wyświetl plik

@ -6,6 +6,7 @@ import 'package:result_monad/result_monad.dart';
import '../../globals.dart';
import '../../models/timeline_entry.dart';
import '../../models/visibility.dart' as v;
import '../../services/feature_version_checker.dart';
import '../../services/fediverse_server_validator.dart';
import '../../services/timeline_manager.dart';
@ -139,69 +140,81 @@ class _InteractionsBarControlState extends State<InteractionsBarControl> {
});
}
Widget buildButton(
IconData icon,
int count,
bool isEnabled,
String tooltip,
Future Function()? onPressed,
) {
return Row(
children: [
IconButton(
onPressed: isEnabled && !isProcessing ? onPressed : null,
icon: Icon(icon),
tooltip: tooltip,
),
Text('$count'),
],
);
}
Widget buildLikeButton() {
return buildButton(
isFavorited ? Icons.thumb_up : Icons.thumb_up_outlined,
likes,
true,
'Press to toggle like/unlike',
() async => await toggleFavorited(),
);
}
Widget buildCommentButton() {
return buildButton(
Icons.comment,
comments,
true,
'Press to add a comment',
() async => await addComment(),
);
}
Widget buildReshareButton() {
final canReshare = !widget.isMine &&
widget.entry.visibility.type == v.VisibilityType.public;
late final String tooltip;
if (canReshare) {
tooltip = youReshared ? 'Press to undo reshare' : 'Press to reshare';
} else {
if (widget.isMine) {
tooltip = "Can't reshare your own post";
} else if (widget.entry.visibility.type != v.VisibilityType.public) {
tooltip = "Can't reshare a private post";
} else {
tooltip = "Can't reshare at this time";
}
}
return buildButton(
youReshared ? Icons.repeat_on_outlined : Icons.repeat,
reshares,
true,
tooltip,
canReshare && !isProcessing
? () async =>
youReshared ? await unResharePost() : await resharePost()
: null,
);
}
@override
Widget build(BuildContext context) {
_logger.finest('Building: ${widget.entry.toShortString()}');
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
children: [
TextButton(
onPressed: likes == 0
? null
: () {
context.push('/likes/${widget.entry.id}');
},
child: Text('$likes Likes'),
),
TextButton(
onPressed: reshares == 0
? null
: () {
context.push('/reshares/${widget.entry.id}');
},
child: Text('$reshares Reshares'),
),
widget.showOpenControl
? TextButton(
onPressed: comments == 0
? null
: () {
context.push(
'/post/view/${widget.entry.id}/${widget.entry.id}');
},
child: Text('$comments Comments'),
)
: Text('$comments Comments'),
],
),
Row(children: [
IconButton(
onPressed:
isProcessing ? null : () async => await toggleFavorited(),
icon: isFavorited
? const Icon(
Icons.thumb_up,
semanticLabel: 'Like',
)
: const Icon(Icons.thumb_up_outlined)),
if (isPost)
IconButton(
onPressed: widget.isMine && !widget.entry.youReshared
? null
: isProcessing
? null
: () async => youReshared
? await unResharePost()
: await resharePost(),
icon: Icon(
youReshared ? Icons.repeat_on_outlined : Icons.repeat)),
IconButton(
onPressed: isProcessing ? null : addComment,
icon: const Icon(Icons.add_comment)),
]),
buildLikeButton(),
buildCommentButton(),
buildReshareButton(),
],
);
}