Better chat screen

This commit is contained in:
LittleSheep 2024-06-23 02:25:45 +08:00
parent bb67edd227
commit e221016c8d
3 changed files with 130 additions and 81 deletions

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:solian/models/channel.dart'; import 'package:solian/models/channel.dart';
@ -80,13 +79,29 @@ class _ChatScreenState extends State<ChatScreen> {
); );
} }
return RefreshIndicator( final prefixSlivers = [
onRefresh: () => getChannels(), Obx(() {
child: CustomScrollView( if (call.current.value != null) {
slivers: [ return const SliverToBoxAdapter(
SliverAppBar( child: ChatCallCurrentIndicator(),
);
} else {
return const SliverToBoxAdapter();
}
}),
];
return DefaultTabController(
length: 2,
child: NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) {
return [
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
context),
sliver: SliverAppBar(
title: AppBarTitle('chat'.tr), title: AppBarTitle('chat'.tr),
centerTitle: false, centerTitle: true,
floating: true, floating: true,
titleSpacing: SolianTheme.titleSpacing(context), titleSpacing: SolianTheme.titleSpacing(context),
toolbarHeight: SolianTheme.toolbarHeight(context), toolbarHeight: SolianTheme.toolbarHeight(context),
@ -140,23 +155,60 @@ class _ChatScreenState extends State<ChatScreen> {
width: SolianTheme.isLargeScreen(context) ? 8 : 16, width: SolianTheme.isLargeScreen(context) ? 8 : 16,
), ),
], ],
bottom: TabBar(
tabs: [
Tab(
icon: const Icon(Icons.tag),
text: 'channels'.tr,
), ),
Obx(() { Tab(
if (call.current.value != null) { icon: const Icon(Icons.chat),
return const SliverToBoxAdapter( text: 'channelCategoryDirect'.tr,
child: ChatCallCurrentIndicator(),
);
} else {
return const SliverToBoxAdapter();
}
}),
if (_isBusy)
SliverToBoxAdapter(
child: const LinearProgressIndicator().animate().scaleX(),
), ),
ChannelListWidget(channels: _channels, selfId: _accountId ?? 0),
], ],
), ),
),
),
];
},
body: Builder(builder: (context) {
if (_isBusy) {
return const Center(child: CircularProgressIndicator());
}
return TabBarView(
children: [
RefreshIndicator(
onRefresh: () => getChannels(),
child: CustomScrollView(
slivers: [
...prefixSlivers,
ChannelListWidget(
channels:
_channels.where((x) => x.type == 0).toList(),
selfId: _accountId ?? 0,
),
],
),
),
RefreshIndicator(
onRefresh: () => getChannels(),
child: CustomScrollView(
slivers: [
...prefixSlivers,
ChannelListWidget(
channels:
_channels.where((x) => x.type == 1).toList(),
selfId: _accountId ?? 0,
noCategory: true,
),
],
),
),
],
);
}),
),
); );
}, },
), ),

View File

@ -127,6 +127,7 @@ class SolianMessages extends Translations {
'realmDeletionConfirm': 'Confirm realm deletion', 'realmDeletionConfirm': 'Confirm realm deletion',
'realmDeletionConfirmCaption': 'realmDeletionConfirmCaption':
'Are you sure to delete realm @realm? This action cannot be undone!', 'Are you sure to delete realm @realm? This action cannot be undone!',
'channels': 'Channels',
'channelNew': 'Create a new channel', 'channelNew': 'Create a new channel',
'channelNewInRealmHint': 'Create channel in realm @realm', 'channelNewInRealmHint': 'Create channel in realm @realm',
'channelOrganizing': 'Organize a channel', 'channelOrganizing': 'Organize a channel',
@ -328,6 +329,7 @@ class SolianMessages extends Translations {
'realmLeaveConfirmCaption': '你确认要离开领域 @realm 吗?你在该领域发表的内容不会被删除。', 'realmLeaveConfirmCaption': '你确认要离开领域 @realm 吗?你在该领域发表的内容不会被删除。',
'realmDeletionConfirm': '确认删除领域', 'realmDeletionConfirm': '确认删除领域',
'realmDeletionConfirmCaption': '你确定要删除领域 @realm 嘛?该操作不可撤销。', 'realmDeletionConfirmCaption': '你确定要删除领域 @realm 嘛?该操作不可撤销。',
'channels': '频道',
'channelNew': '创建新频道', 'channelNew': '创建新频道',
'channelNewInRealmHint': '在领域 @realm 里创建新频道', 'channelNewInRealmHint': '在领域 @realm 里创建新频道',
'channelOrganizing': '组织频道', 'channelOrganizing': '组织频道',

View File

@ -23,13 +23,11 @@ class ChannelListWidget extends StatefulWidget {
class _ChannelListWidgetState extends State<ChannelListWidget> { class _ChannelListWidgetState extends State<ChannelListWidget> {
final List<Channel> _globalChannels = List.empty(growable: true); final List<Channel> _globalChannels = List.empty(growable: true);
final List<Channel> _directMessages = List.empty(growable: true);
final Map<String, List<Channel>> _inRealms = {}; final Map<String, List<Channel>> _inRealms = {};
void mapChannels() { void mapChannels() {
_inRealms.clear(); _inRealms.clear();
_globalChannels.clear(); _globalChannels.clear();
_directMessages.clear();
if (widget.noCategory) { if (widget.noCategory) {
_globalChannels.addAll(widget.channels); _globalChannels.addAll(widget.channels);
@ -42,8 +40,6 @@ class _ChannelListWidgetState extends State<ChannelListWidget> {
_inRealms[channel.realm!.alias] = List.empty(growable: true); _inRealms[channel.realm!.alias] = List.empty(growable: true);
} }
_inRealms[channel.realm!.alias]!.add(channel); _inRealms[channel.realm!.alias]!.add(channel);
} else if (channel.type == 1) {
_directMessages.add(channel);
} else { } else {
_globalChannels.add(channel); _globalChannels.add(channel);
} }
@ -56,6 +52,12 @@ class _ChannelListWidgetState extends State<ChannelListWidget> {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
} }
@override
void initState() {
mapChannels();
super.initState();
}
Widget buildItem(Channel element) { Widget buildItem(Channel element) {
if (element.type == 1) { if (element.type == 1) {
final otherside = element.members! final otherside = element.members!
@ -125,13 +127,6 @@ class _ChannelListWidgetState extends State<ChannelListWidget> {
return SliverList.list( return SliverList.list(
children: [ children: [
..._globalChannels.map((e) => buildItem(e)), ..._globalChannels.map((e) => buildItem(e)),
if (_directMessages.isNotEmpty)
ExpansionTile(
tilePadding: const EdgeInsets.symmetric(horizontal: 24),
title: Text('channelCategoryDirect'.tr),
subtitle: Text('channelCategoryDirectHint'.tr),
children: _directMessages.map((e) => buildItem(e)).toList(),
),
..._inRealms.entries.map((element) { ..._inRealms.entries.map((element) {
return ExpansionTile( return ExpansionTile(
tilePadding: const EdgeInsets.symmetric(horizontal: 24), tilePadding: const EdgeInsets.symmetric(horizontal: 24),