From 4b581400d5a75b36766cff4939fd273be90ce979 Mon Sep 17 00:00:00 2001 From: zoe Date: Wed, 7 Sep 2022 22:07:11 +0200 Subject: [PATCH] finish threads! :) --- lib/dialogues/full_post_view.dart | 134 ++++++++++++++++++++++-------- 1 file changed, 100 insertions(+), 34 deletions(-) diff --git a/lib/dialogues/full_post_view.dart b/lib/dialogues/full_post_view.dart index ac67b01..a9c68af 100644 --- a/lib/dialogues/full_post_view.dart +++ b/lib/dialogues/full_post_view.dart @@ -12,9 +12,15 @@ class FullPostView extends StatefulWidget { super.key, required this.originPostModel, this.identities, + this.hidden = true, + this.ancestors, + this.descendants, }); final PostModel originPostModel; final Map? identities; + final bool hidden; + final List? ancestors; + final List? descendants; @override State createState() => _FullPostViewState(); @@ -26,6 +32,7 @@ class _FullPostViewState extends State { Map identities = {}; String activeIdentity = ""; int idsChecked = 1; + bool sensitive = false; void loadIdentities() async { global.settings!.identities.forEach((key, value) async { @@ -46,17 +53,37 @@ class _FullPostViewState extends State { } void loadPosts() async { - final r = await getContextForPost(widget.originPostModel); - if (r.value != null && mounted) { - setState(() { - ancestors = r.value!.ancestors; - descendants = r.value!.descendants; - }); + if (widget.ancestors == null || widget.descendants == null) { + final r = await getContextForPost(widget.originPostModel); + if (r.value != null && mounted) { + setState(() { + ancestors = r.value!.ancestors; + descendants = r.value!.descendants; + }); + } + for (var a in ancestors) { + if (a.sensitive) { + sensitive = true; + } + } + for (var d in descendants) { + if (d.sensitive) { + sensitive = true; + } + } } } @override void initState() { + if (widget.ancestors != null) { + ancestors = widget.ancestors!; + } + if (widget.descendants != null) { + descendants = widget.descendants!; + } + + sensitive = widget.originPostModel.sensitive; if (widget.identities != null) { idsChecked = global.settings!.identities.length; } @@ -86,44 +113,77 @@ class _FullPostViewState extends State { children: [ global.settings!.identities.length > idsChecked ? Column( + crossAxisAlignment: CrossAxisAlignment.stretch, children: [ SelectableText( "${"post-found-on".i18n()} $idsChecked ${idsChecked == 1 ? "instance".i18n() : "instances".i18n()}"), const LinearProgressIndicator(), ], ) - : Row(mainAxisAlignment: MainAxisAlignment.center, children: [ - DropdownButtonHideUnderline( - child: DropdownButton( - alignment: Alignment.center, - value: activeIdentity, - style: Theme.of(context).textTheme.bodyMedium, - iconEnabledColor: Theme.of(context).colorScheme.onSurface, - items: dropdownButtons, - onChanged: (value) { - setState(() { - Navigator.of(context).pop(); - showDialog( - context: context, - builder: (context) => FullPostView( - originPostModel: identities[value]!, - identities: identities, - ), - ); - }); - loadPosts(); - }, - ), - ), - ]), + : Padding( + padding: const EdgeInsets.fromLTRB(8, 0, 8, 0), + child: Wrap( + alignment: WrapAlignment.spaceAround, + crossAxisAlignment: WrapCrossAlignment.center, + children: [ + DropdownButtonHideUnderline( + child: DropdownButton( + alignment: Alignment.center, + value: activeIdentity, + style: Theme.of(context).textTheme.bodyMedium, + iconEnabledColor: + Theme.of(context).colorScheme.onSurface, + items: dropdownButtons, + onChanged: (value) { + setState(() { + Navigator.of(context).pop(); + showDialog( + context: context, + builder: (context) => FullPostView( + originPostModel: identities[value]!, + identities: identities, + ), + ); + }); + loadPosts(); + }, + ), + ), + if (sensitive) + ElevatedButton.icon( + onPressed: () { + setState(() { + Navigator.of(context).pop(); + showDialog( + context: context, + builder: (context) => FullPostView( + originPostModel: widget.originPostModel, + hidden: !widget.hidden, + identities: identities, + ancestors: ancestors, + descendants: descendants, + ), + ); + }); + }, + icon: Icon(widget.hidden + ? Icons.visibility + : Icons.visibility_off), + label: Text( + widget.hidden ? "show".i18n() : "hide".i18n(), + )) + ]), + ), Container( - height: MediaQuery.of(context).size.height * 2 / 3, - constraints: global.getConstraints(context), + constraints: BoxConstraints( + maxHeight: MediaQuery.of(context).size.height, + maxWidth: global.getConstraints(context).maxWidth), width: global.getWidth(context), child: SingleChildScrollView( child: SingleFullPostDisplay( ancestors: ancestors, descendants: descendants, + hidden: widget.hidden, level: 0, model: identities[activeIdentity]!.reblog ?? identities[activeIdentity]!, @@ -142,17 +202,19 @@ class SingleFullPostDisplay extends StatelessWidget { required this.model, required this.ancestors, required this.descendants, + this.hidden = true, }); final int level; final PostModel model; final List ancestors; final List descendants; + final bool hidden; @override Widget build(BuildContext context) { List ancestorWidgets = ancestors .map( - (e) => Post(model: e), + (e) => Post(model: e, hideSensitive: hidden), ) .toList(); @@ -167,13 +229,17 @@ class SingleFullPostDisplay extends StatelessWidget { model: element, ancestors: const [], descendants: descendants, + hidden: hidden, )); } } List c = []; c.addAll(ancestorWidgets); - c.add(Post(model: model)); + c.add(Post( + model: model, + hideSensitive: hidden, + )); c.addAll(descendantsWidgets); return Container( padding: