account switching for threads

This commit is contained in:
zoe 2022-09-07 17:36:13 +02:00
parent 0bbb74332d
commit 631cabbf8d
2 changed files with 85 additions and 12 deletions

View File

@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:localization/localization.dart';
import 'package:loris/business_logic/network_tools/get_post_from_url.dart';
import 'package:loris/business_logic/posts/posts.dart';
import 'package:loris/business_logic/timeline/timeline.dart';
import 'package:loris/global.dart' as global;
@ -9,8 +11,10 @@ class FullPostView extends StatefulWidget {
const FullPostView({
super.key,
required this.originPostModel,
this.identities,
});
final PostModel originPostModel;
final Map<String, PostModel>? identities;
@override
State<FullPostView> createState() => _FullPostViewState();
@ -19,35 +23,101 @@ class FullPostView extends StatefulWidget {
class _FullPostViewState extends State<FullPostView> {
List<PostModel> ancestors = [];
List<PostModel> descendants = [];
Map<String, PostModel> identities = {};
String activeIdentity = "";
int idsChecked = 1;
void loadIdentities() async {
global.settings!.identities.forEach((key, value) async {
if (!identities.containsKey(key)) {
final r = await getPostFromUrl(key, widget.originPostModel.uri);
if (r.values.first != null && mounted) {
setState(() {
identities.addAll({key: r.values.first!});
});
}
if (mounted) {
setState(() {
idsChecked++;
});
}
}
});
}
bool loading = true;
void loadPosts() async {
final r = await getContextForPost(widget.originPostModel);
if (r.value != null) {
if (r.value != null && mounted) {
setState(() {
ancestors = r.value!.ancestors;
descendants = r.value!.descendants;
});
}
if (mounted) {
setState(() {
loading = false;
});
}
}
@override
void initState() {
if (widget.identities != null) {
idsChecked = global.settings!.identities.length;
}
identities = widget.identities ?? {};
identities.addAll({
widget.originPostModel.identity: widget.originPostModel,
});
activeIdentity = widget.originPostModel.identity;
loadPosts();
loadIdentities();
super.initState();
}
@override
Widget build(BuildContext context) {
List<DropdownMenuItem<String>> dropdownButtons = [];
identities.forEach((key, value) {
dropdownButtons.add(
DropdownMenuItem(
value: key,
child: Text(key, style: Theme.of(context).textTheme.bodyMedium),
),
);
});
return SimpleDialog(
contentPadding: const EdgeInsets.all(24),
contentPadding: const EdgeInsets.fromLTRB(0, 24, 0, 0),
children: [
global.settings!.identities.length > idsChecked
? Column(
children: [
SelectableText(
"${"post-found-on".i18n()} $idsChecked ${idsChecked == 1 ? "instance".i18n() : "instances".i18n()}"),
const LinearProgressIndicator(),
],
)
: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
DropdownButtonHideUnderline(
child: DropdownButton<String>(
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();
},
),
),
]),
Container(
height: MediaQuery.of(context).size.height * 2 / 3,
constraints: global.getConstraints(context),
width: global.getWidth(context),
child: SingleChildScrollView(
@ -55,7 +125,8 @@ class _FullPostViewState extends State<FullPostView> {
ancestors: ancestors,
descendants: descendants,
level: 0,
model: widget.originPostModel.reblog ?? widget.originPostModel,
model: identities[activeIdentity]!.reblog ??
identities[activeIdentity]!,
),
),
)
@ -104,9 +175,9 @@ class SingleFullPostDisplay extends StatelessWidget {
c.addAll(ancestorWidgets);
c.add(Post(model: model));
c.addAll(descendantsWidgets);
return Container(
padding: EdgeInsets.fromLTRB(level == 0 ? 0 : 4, 0, 0, 0),
padding:
EdgeInsets.fromLTRB(level == 0 ? 4 : 4, 0, level == 0 ? 4 : 0, 0),
decoration: BoxDecoration(
border: level == 0
? const Border()

View File

@ -71,6 +71,8 @@
"you-do-not-follow-each-other": "you don't follow each other",
"found-account-on": "found account on",
"instances": "instances",
"instance": "instace"
"instance": "instace",
"post-found-on": "found post on",
"show-in-full": "show in full"
}