channel list fixes

This commit is contained in:
Mike Schwörer 2024-07-12 23:08:56 +02:00
parent 89d1e0f641
commit 778451fa4c
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 34 additions and 22 deletions

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:simplecloudnotifier/api/api_client.dart'; import 'package:simplecloudnotifier/api/api_client.dart';
@ -142,22 +143,31 @@ class _ChannelRootPageState extends State<ChannelRootPage> with RouteAware {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return RefreshIndicator( return Scaffold(
onRefresh: () => Future.sync( body: RefreshIndicator(
() => _pagingController.refresh(), onRefresh: () => Future.sync(
), () => _pagingController.refresh(),
child: PagedListView<int, ChannelWithSubscription>( ),
pagingController: _pagingController, child: PagedListView<int, ChannelWithSubscription>(
builderDelegate: PagedChildBuilderDelegate<ChannelWithSubscription>( pagingController: _pagingController,
itemBuilder: (context, item, index) => ChannelListItem( builderDelegate: PagedChildBuilderDelegate<ChannelWithSubscription>(
channel: item.channel, itemBuilder: (context, item, index) => ChannelListItem(
subscription: item.subscription, channel: item.channel,
onPressed: () { subscription: item.subscription,
Navi.push(context, () => ChannelViewPage(channel: item.channel, subscription: item.subscription, needsReload: _enqueueReload)); onPressed: () {
}, Navi.push(context, () => ChannelViewPage(channel: item.channel, subscription: item.subscription, needsReload: _enqueueReload));
},
),
), ),
), ),
), ),
floatingActionButton: FloatingActionButton(
onPressed: () {
//TODO scan qr code to subscribe channel
},
backgroundColor: ,
child: const Icon(FontAwesomeIcons.qrcode),
),
); );
} }

View File

@ -37,7 +37,7 @@ enum EditState { none, editing, saving }
class _ChannelViewPageState extends State<ChannelViewPage> { class _ChannelViewPageState extends State<ChannelViewPage> {
late ImmediateFuture<String?> _futureSubscribeKey; late ImmediateFuture<String?> _futureSubscribeKey;
late ImmediateFuture<List<Subscription>> _futureSubscriptions; late ImmediateFuture<List<(Subscription, UserPreview?)>> _futureSubscriptions;
late ImmediateFuture<UserPreview> _futureOwner; late ImmediateFuture<UserPreview> _futureOwner;
final TextEditingController _ctrlDisplayName = TextEditingController(); final TextEditingController _ctrlDisplayName = TextEditingController();
@ -61,10 +61,10 @@ class _ChannelViewPageState extends State<ChannelViewPage> {
} else { } else {
_futureSubscribeKey = ImmediateFuture<String?>.ofFuture(_getSubScribeKey(userAcc)); _futureSubscribeKey = ImmediateFuture<String?>.ofFuture(_getSubScribeKey(userAcc));
} }
_futureSubscriptions = ImmediateFuture<List<Subscription>>.ofFuture(_listSubscriptions(userAcc)); _futureSubscriptions = ImmediateFuture<List<(Subscription, UserPreview?)>>.ofFuture(_listSubscriptions(userAcc));
} else { } else {
_futureSubscribeKey = ImmediateFuture<String?>.ofValue(null); _futureSubscribeKey = ImmediateFuture<String?>.ofValue(null);
_futureSubscriptions = ImmediateFuture<List<Subscription>>.ofValue([]); _futureSubscriptions = ImmediateFuture<List<(Subscription, UserPreview?)>>.ofValue([]);
} }
if (widget.channel.ownerUserID == userAcc.userID) { if (widget.channel.ownerUserID == userAcc.userID) {
@ -156,13 +156,13 @@ class _ChannelViewPageState extends State<ChannelViewPage> {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
for (final sub in snapshot.data!.where((sub) => sub.subscriptionID != widget.subscription?.subscriptionID)) for (final (sub, user) in snapshot.data!.where((v) => v.$1.subscriptionID != widget.subscription?.subscriptionID))
UI.metaCard( UI.metaCard(
context: context, context: context,
icon: FontAwesomeIcons.solidDiagramSuccessor, icon: FontAwesomeIcons.solidDiagramSuccessor,
title: 'Subscription (other)', title: 'Subscription (' + (user?.username ?? user?.userID ?? 'other') + ')',
values: [_formatSubscriptionStatus(sub)], values: [_formatSubscriptionStatus(sub)],
iconActions: _getForignSubActions(sub), iconActions: _getForeignSubActions(sub),
), ),
], ],
); );
@ -461,7 +461,7 @@ class _ChannelViewPageState extends State<ChannelViewPage> {
} }
} }
Future<List<Subscription>> _listSubscriptions(AppAuth auth) async { Future<List<(Subscription, UserPreview?)>> _listSubscriptions(AppAuth auth) async {
try { try {
await Future.delayed(const Duration(seconds: 0), () {}); // this is annoyingly important - otherwise we call setLoadingIndeterminate directly in initStat() and get an exception.... await Future.delayed(const Duration(seconds: 0), () {}); // this is annoyingly important - otherwise we call setLoadingIndeterminate directly in initStat() and get an exception....
@ -469,9 +469,11 @@ class _ChannelViewPageState extends State<ChannelViewPage> {
var subs = await APIClient.getChannelSubscriptions(auth, widget.channel.channelID); var subs = await APIClient.getChannelSubscriptions(auth, widget.channel.channelID);
var userMap = {for (var v in (await Future.wait(subs.map((e) => e.subscriberUserID).toSet().map((e) => APIClient.getUserPreview(auth, e)).toList()))) v.userID: v};
//await Future.delayed(const Duration(seconds: 10), () {}); //await Future.delayed(const Duration(seconds: 10), () {});
return subs; return subs.map((e) => (e, userMap[e.subscriberUserID] ?? null)).toList();
} finally { } finally {
_incLoadingIndeterminateCounter(-1); _incLoadingIndeterminateCounter(-1);
} }
@ -493,7 +495,7 @@ class _ChannelViewPageState extends State<ChannelViewPage> {
} }
} }
List<(IconData, void Function())> _getForignSubActions(Subscription sub) { List<(IconData, void Function())> _getForeignSubActions(Subscription sub) {
if (sub.confirmed) { if (sub.confirmed) {
return [(FontAwesomeIcons.solidSquareXmark, () => _cancelForeignSubscription(sub))]; return [(FontAwesomeIcons.solidSquareXmark, () => _cancelForeignSubscription(sub))];
} else { } else {