Commit f879bf41 authored by Wilko Manger's avatar Wilko Manger

Use ChatMember in settings

parent 86adc65f
......@@ -16,6 +16,7 @@
// along with Pattle. If not, see <https://www.gnu.org/licenses/>.
import 'package:bloc/bloc.dart';
import 'package:pattle/src/section/main/models/chat_member.dart';
import '../../../matrix.dart';
......@@ -31,16 +32,22 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
SettingsBloc(this._matrix);
@override
SettingsState get initialState => SettingsInitialized();
SettingsState get initialState => SettingsInitialized(
ChatMember(
_matrix.user,
name: _matrix.user.name,
isYou: true,
),
);
@override
Stream<SettingsState> mapEventToState(SettingsEvent event) async* {
if (event is UpdateDisplayName) {
yield UpdatingDisplayName();
yield UpdatingDisplayName(state.me);
await _matrix.user.setName(event.name);
yield DisplayNameUpdated();
yield DisplayNameUpdated(state.me);
}
}
}
......@@ -22,8 +22,6 @@ import 'package:pattle/src/resources/localizations.dart';
import 'package:pattle/src/resources/theme.dart';
import 'package:pattle/src/section/main/settings/bloc.dart';
import '../../../matrix.dart';
class _NamePageState extends State<NamePage> {
final _textController = TextEditingController();
......@@ -31,11 +29,11 @@ class _NamePageState extends State<NamePage> {
void didChangeDependencies() {
super.didChangeDependencies();
final name = Matrix.of(context).user.name;
final me = BlocProvider.of<SettingsBloc>(context).state.me;
_textController.value = TextEditingValue(
text: name,
selection: TextSelection(baseOffset: 0, extentOffset: name.length),
text: me.name,
selection: TextSelection(baseOffset: 0, extentOffset: me.name.length),
);
}
......
......@@ -21,7 +21,6 @@ import 'package:pattle/src/resources/theme.dart';
import 'package:pattle/src/section/main/widgets/chat_member_avatar.dart';
import '../../../matrix.dart';
import '../../../util/local_user.dart';
import '../../../app.dart';
import 'bloc.dart';
......@@ -44,9 +43,6 @@ class _SettingsPageState extends State<SettingsPage> {
@override
Widget build(BuildContext context) {
final bloc = BlocProvider.of<SettingsBloc>(context);
// TODO: Use ChatMember
final me = Matrix.of(context).user;
return Scaffold(
appBar: AppBar(
title: Text(l(context).settings),
......@@ -64,33 +60,39 @@ class _SettingsPageState extends State<SettingsPage> {
},
child: Padding(
padding: EdgeInsets.all(16),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Hero(
tag: me.id,
child: ChatMemberAvatar(
member: me.toChatMember(),
radius: 36,
),
),
Padding(
padding: EdgeInsets.only(left: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
me.name,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
),
child: BlocBuilder<SettingsBloc, SettingsState>(
builder: (context, state) {
final me = state.me;
return Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Hero(
tag: me.user.id,
child: ChatMemberAvatar(
member: me,
radius: 36,
),
),
Padding(
padding: EdgeInsets.only(left: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
me.name,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
Text(me.user.id.toString())
],
),
Text(me.id.toString())
],
),
)
],
)
],
);
},
),
),
),
......
......@@ -20,9 +20,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pattle/src/resources/localizations.dart';
import 'package:pattle/src/resources/theme.dart';
import 'package:pattle/src/section/main/widgets/chat_member_avatar.dart';
import '../../../matrix.dart';
import '../../../util/local_user.dart';
import '../../../app.dart';
import 'bloc.dart';
......@@ -44,69 +41,72 @@ class ProfilePage extends StatefulWidget {
class _ProfilePageState extends State<ProfilePage> {
@override
Widget build(BuildContext context) {
// TODO: Use ChatMember
final me = Matrix.of(context).user;
return Scaffold(
appBar: AppBar(
title: Text(l(context).profile),
),
body: Center(
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(16),
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Hero(
tag: me.id,
child: ChatMemberAvatar(
member: me.toChatMember(),
radius: 96,
),
body: BlocBuilder<SettingsBloc, SettingsState>(
builder: (context, state) {
final me = state.me;
return Center(
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(16),
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Hero(
tag: me.user.id,
child: ChatMemberAvatar(
member: me,
radius: 96,
),
),
Positioned(
right: -1,
bottom: -1,
child: FloatingActionButton(
child: Icon(Icons.photo_camera),
onPressed: () {},
),
)
],
),
Positioned(
right: -1,
bottom: -1,
child: FloatingActionButton(
child: Icon(Icons.photo_camera),
onPressed: () {},
),
)
],
),
),
Expanded(
child: ListView(
children: <Widget>[
ListTile(
leading: Icon(
Icons.person,
color: redOnBackground(context),
),
title: Text(l(context).name),
subtitle: Text(me.name),
trailing: Icon(Icons.edit),
onTap: () => Navigator.pushNamed(
context,
Routes.settingsProfileName,
arguments: BlocProvider.of<SettingsBloc>(context),
),
),
Expanded(
child: ListView(
children: <Widget>[
ListTile(
leading: Icon(
Icons.person,
color: redOnBackground(context),
),
title: Text(l(context).name),
subtitle: Text(me.name),
trailing: Icon(Icons.edit),
onTap: () => Navigator.pushNamed(
context,
Routes.settingsProfileName,
arguments: BlocProvider.of<SettingsBloc>(context),
),
),
ListTile(
leading: Icon(
Icons.alternate_email,
color: redOnBackground(context),
),
title: Text(l(context).username),
subtitle: Text(me.user.id.toString()),
)
],
),
ListTile(
leading: Icon(
Icons.alternate_email,
color: redOnBackground(context),
),
title: Text(l(context).username),
subtitle: Text(me.id.toString()),
)
],
),
)
],
),
)
],
),
);
},
),
);
}
......
import 'package:equatable/equatable.dart';
import 'package:pattle/src/section/main/models/chat_member.dart';
abstract class SettingsState {
final ChatMember me;
SettingsState(this.me);
abstract class SettingsState extends Equatable {
@override
List<Object> get props => [];
bool operator ==(other) {
return runtimeType == other.runtimeType &&
me.user.state == other.me.user.state;
}
@override
int get hashCode => runtimeType.hashCode + me.user.state.hashCode;
}
class SettingsInitialized extends SettingsState {}
class SettingsInitialized extends SettingsState {
@override
SettingsInitialized(ChatMember me) : super(me);
}
class UpdatingDisplayName extends SettingsState {}
class UpdatingDisplayName extends SettingsState {
@override
UpdatingDisplayName(ChatMember me) : super(me);
}
class DisplayNameUpdated extends SettingsState {}
class DisplayNameUpdated extends SettingsState {
@override
DisplayNameUpdated(ChatMember me) : super(me);
}
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