Commit d8f341ab authored by Wilko Manger's avatar Wilko Manger

Use tabs for personal and public chats separation

parent 5c67a574
......@@ -33,9 +33,11 @@ class ChatsBloc extends Bloc<ChatsEvent, ChatsState> {
ChatsBloc(this.matrix);
Future<List<ChatOverview>> _loadChats() async {
Future<List<ChatOverview>> _getChats() async {
final me = matrix.user;
await me.sync.first;
final chats = List<ChatOverview>();
// Get all rooms and push them as a single list
......@@ -115,28 +117,26 @@ class ChatsBloc extends Bloc<ChatsEvent, ChatsState> {
return chats.reversed.toList();
}
Future<ChatsState> _loadPersonalChats() async {
var chats = await _loadChats();
Future<ChatsState> _loadChats() async {
final chats = await _getChats();
chats = chats
final personalChats = chats
.where(
(chat) => chat.room.aliases == null || chat.room.aliases.isEmpty,
(chat) =>
chat.room.joinRule == JoinRule.invite ||
chat.room.joinRule == JoinRule.private,
)
.toList();
return ChatsLoaded(chats);
}
Future<ChatsState> _loadPublicChats() async {
var chats = await _loadChats();
chats = chats
final publicChats = chats
.where(
(chat) => chat.room.aliases != null && chat.room.aliases.isNotEmpty,
(chat) =>
chat.room.joinRule == JoinRule.public ||
chat.room.joinRule == JoinRule.knock,
)
.toList();
return ChatsLoaded(chats);
return ChatsLoaded(personal: personalChats, public: publicChats);
}
@override
......@@ -144,12 +144,9 @@ class ChatsBloc extends Bloc<ChatsEvent, ChatsState> {
@override
Stream<ChatsState> mapEventToState(ChatsEvent event) async* {
if (event is LoadPersonalChats) {
yield await _loadPersonalChats();
}
if (event is LoadPublicChats) {
yield await _loadPublicChats();
if (event is LoadChats) {
print('loading chats');
yield await _loadChats();
}
}
}
......@@ -5,6 +5,4 @@ abstract class ChatsEvent extends Equatable {
List<Object> get props => [];
}
class LoadPersonalChats extends ChatsEvent {}
class LoadPublicChats extends ChatsEvent {}
class LoadChats extends ChatsEvent {}
......@@ -40,26 +40,6 @@ class ChatsPage extends StatefulWidget {
}
class _ChatsPageState extends State<ChatsPage> {
int _currentTab = 0;
void _switchTabTo(int index) {
// Temporary: Don't do anything for the calls tab
if (index > 1) {
return;
}
final bloc = context.bloc<ChatsBloc>();
if (_currentTab == 0) {
bloc.add(LoadPublicChats());
} else {
bloc.add(LoadPersonalChats());
}
setState(() {
_currentTab = index;
});
}
void _goToCreateGroup() {
Navigator.of(context).pushNamed(Routes.chatsNew);
}
......@@ -68,69 +48,75 @@ class _ChatsPageState extends State<ChatsPage> {
void didChangeDependencies() {
super.didChangeDependencies();
context.bloc<ChatsBloc>().add(LoadPersonalChats());
context.bloc<ChatsBloc>().add(LoadChats());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(l(context).appName),
actions: <Widget>[
IconButton(
icon: Icon(Icons.settings),
onPressed: () => Navigator.pushNamed(context, Routes.settings),
)
],
),
body: Column(
children: <Widget>[
//ErrorBanner(),
Expanded(
child: AnimatedCrossFade(
duration: Duration(milliseconds: 200),
firstChild: _ChatsTab(),
secondChild: _ChatsTab(),
crossFadeState: _currentTab == 0
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
alignment: Alignment.center,
),
)
],
),
floatingActionButton: FloatingActionButton(
onPressed: _goToCreateGroup,
child: Icon(Icons.chat),
),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.chat_bubble),
title: Text(l(context).personal),
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text(l(context).appName),
actions: <Widget>[
IconButton(
icon: Icon(Icons.settings),
onPressed: () => Navigator.pushNamed(context, Routes.settings),
)
],
bottom: TabBar(
tabs: <Widget>[
Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.group),
SizedBox(width: 8),
Text(l(context).personal.toUpperCase()),
],
),
),
Tab(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(Mdi.bullhorn),
SizedBox(width: 8),
Text(l(context).public.toUpperCase()),
],
),
),
],
),
BottomNavigationBarItem(
icon: Icon(Mdi.bullhorn),
title: Text(l(context).public),
),
BottomNavigationBarItem(
icon: Icon(Icons.phone),
title: Text(l(context).calls),
)
],
currentIndex: _currentTab,
onTap: _switchTabTo,
),
body: TabBarView(
children: <Widget>[
_ChatsTab(personal: true),
_ChatsTab(personal: false),
],
),
floatingActionButton: FloatingActionButton(
onPressed: _goToCreateGroup,
child: Icon(Icons.chat),
),
),
);
}
}
class _ChatsTab extends StatelessWidget {
final bool personal;
const _ChatsTab({Key key, this.personal}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocBuilder<ChatsBloc, ChatsState>(builder: (context, state) {
if (state is ChatsLoaded) {
return ChatOverviewList(chats: state.chats);
return ChatOverviewList(
chats: personal ? state.personal : state.public,
);
} else {
return Center(child: CircularProgressIndicator());
}
......
import 'package:meta/meta.dart';
import 'package:equatable/equatable.dart';
import 'package:pattle/src/section/main/chats/models/chat_overview.dart';
......@@ -9,10 +10,11 @@ abstract class ChatsState extends Equatable {
class ChatsLoading extends ChatsState {}
class ChatsLoaded extends ChatsState {
final List<ChatOverview> chats;
final List<ChatOverview> personal;
final List<ChatOverview> public;
ChatsLoaded(this.chats);
ChatsLoaded({@required this.personal, @required this.public});
@override
List<Object> get props => [chats];
List<Object> get props => [personal];
}
......@@ -220,7 +220,7 @@ packages:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.0+2"
version: "0.12.0+4"
http_parser:
dependency: transitive
description:
......@@ -281,8 +281,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: a5b0bff21144e437cf231325d72c00e6d539b175
resolved-ref: a5b0bff21144e437cf231325d72c00e6d539b175
ref: f506fb387e6fcacbf90fca6551f7f8865cb6812b
resolved-ref: f506fb387e6fcacbf90fca6551f7f8865cb6812b
url: "https://git.pattle.im/pattle/library/matrix-dart-sdk.git"
source: git
version: "0.0.0"
......@@ -290,8 +290,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: aaf9314a2ef78ee4adce31c19b0ef5b50416a88e
resolved-ref: aaf9314a2ef78ee4adce31c19b0ef5b50416a88e
ref: "7dbb3cba4ae124c3557ccb80986dc2e95c8ae276"
resolved-ref: "7dbb3cba4ae124c3557ccb80986dc2e95c8ae276"
url: "https://git.pattle.im/pattle/library/matrix-dart-sdk-sqflite.git"
source: git
version: "0.0.0"
......@@ -316,6 +316,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.6+3"
moor:
dependency: transitive
description:
name: moor
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.2"
moor_ffi:
dependency: transitive
description:
name: moor_ffi
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0"
nested:
dependency: transitive
description:
......@@ -434,7 +448,14 @@ packages:
name: sqflite
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.7+2"
version: "1.3.0"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
stack_trace:
dependency: transitive
description:
......@@ -548,5 +569,5 @@ packages:
source: hosted
version: "2.2.0"
sdks:
dart: ">=2.6.0 <3.0.0"
dart: ">=2.7.0 <3.0.0"
flutter: ">=1.12.1 <2.0.0"
......@@ -75,11 +75,11 @@ dependency_overrides:
matrix_sdk:
git:
url: https://git.pattle.im/pattle/library/matrix-dart-sdk.git
ref: a5b0bff21144e437cf231325d72c00e6d539b175
ref: f506fb387e6fcacbf90fca6551f7f8865cb6812b
matrix_sdk_sqflite:
git:
url: https://git.pattle.im/pattle/library/matrix-dart-sdk-sqflite.git
ref: aaf9314a2ef78ee4adce31c19b0ef5b50416a88e
ref: 7dbb3cba4ae124c3557ccb80986dc2e95c8ae276
dev_dependencies:
flutter_launcher_icons: ^0.7.2+1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment