Commit 3ec01db6 authored by Wilko Manger's avatar Wilko Manger

Show chat avatars

parent 250b1617
Pipeline #321 passed with stages
in 2 minutes and 14 seconds
......@@ -23,7 +23,12 @@ final inj = Injector();
Homeserver getHomeserver() => inj.getDependency<Homeserver>();
void registerHomeserver(Uri uri) {
void registerHomeserver(Homeserver homeserver) {
inj.registerSingleton<Homeserver>((_)
=> homeserver, override: true);
}
void registerHomeserverWith(Uri uri) {
inj.registerSingleton<Homeserver>((_)
=> Homeserver(
uri
......@@ -44,4 +49,5 @@ LocalUser getLocalUser() => inj.getDependency<LocalUser>();
void registerLocalUser(LocalUser user) {
inj.registerSingleton<LocalUser>((_) => user, override: true);
registerHomeserver(user.homeserver);
}
\ No newline at end of file
......@@ -15,6 +15,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with Pattle. If not, see <https://www.gnu.org/licenses/>.
import 'dart:typed_data';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:meta/meta.dart';
......@@ -28,9 +30,12 @@ class ChatOverview {
final RoomEvent latestEvent;
final Uri avatarUrl;
ChatOverview({@required this.id,
String name,
@required this.latestEvent}) {
@required this.latestEvent,
this.avatarUrl}) {
_name = name ?? id.toString();
}
}
\ No newline at end of file
......@@ -40,13 +40,13 @@ class ChatOverviewBloc {
.lastWhere((event) => true, orElse: () => null);
var chat = ChatOverview(
id: room.id,
name: room.name,
latestEvent: latestEvent
id: room.id,
name: room.name,
latestEvent: latestEvent,
avatarUrl: room.avatarUrl
);
chats.add(chat);
print(chats.length);
}
chats.sort((a, b) {
......@@ -65,7 +65,7 @@ class ChatOverviewBloc {
Future<void> startSync() async {
// Load from store before sync
loadChats();
await loadChats();
Observable(_user.sync())
.listen((success) async {
......
......@@ -22,6 +22,8 @@ import 'package:pattle/src/model/chat_overview.dart';
import 'package:pattle/src/ui/chat/chat_overview_bloc.dart';
import 'package:pattle/src/ui/resources/localizations.dart';
import 'package:pattle/src/ui/util/date_format.dart';
import 'package:pattle/src/ui/util/matrix_image.dart';
import 'package:transparent_image/transparent_image.dart';
class ChatOverviewPageState extends State<ChatOverviewPage> {
......@@ -63,7 +65,10 @@ class ChatOverviewPageState extends State<ChatOverviewPage> {
case ConnectionState.done:
var chats = snapshot.data;
return ListView.separated(
separatorBuilder: (context, index) => Divider(height: 1),
separatorBuilder: (context, index) => Divider(
height: 1,
indent: 64,
),
itemCount: chats.length,
itemBuilder: (context, index) {
var chat = chats[index];
......@@ -88,13 +93,43 @@ class ChatOverviewPageState extends State<ChatOverviewPage> {
var time = formatAsListItem(context, chat.latestEvent?.time);
// Avatar
var avatar;
if (chat.avatarUrl != null) {
avatar = Container(
width: 48,
height: 48,
child: ClipOval(
child: FadeInImage(
fit: BoxFit.fill,
placeholder: MemoryImage(kTransparentImage),
image: MatrixImage(chat.avatarUrl)
)
),
);
} else {
avatar = CircleAvatar(
radius: 24,
child: Text(chat.name[0],
style: Theme.of(context).textTheme.display1.copyWith(
color: Colors.white,
fontSize: 22
)
)
);
}
return ListTile(
title: Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: <Widget>[
Expanded(
child: Text(chat.name),
child: Text(chat.name,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
Text(
time,
......@@ -107,9 +142,11 @@ class ChatOverviewPageState extends State<ChatOverviewPage> {
),
dense: false,
onTap: () { },
leading: avatar,
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
subtitle: Text(subtitle,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
);
}
......
......@@ -24,7 +24,7 @@ final bloc = StartBloc();
class StartBloc {
StartBloc() {
di.registerHomeserver(Uri.parse("https://matrix.org"));
di.registerHomeserverWith(Uri.parse("https://matrix.org"));
}
final _homeserverChangedSubj = BehaviorSubject<bool>();
......@@ -35,7 +35,7 @@ class StartBloc {
Username _username;
void _setHomeserver(Uri uri) {
di.registerHomeserver(uri);
di.registerHomeserverWith(uri);
_homeserverChangedSubj.add(true);
}
......
// Copyright (C) 2019 wilko
//
// This file is part of Pattle.
//
// Pattle is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pattle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Pattle. If not, see <https://www.gnu.org/licenses/>.
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:pattle/src/di.dart' as di;
class MatrixImage extends ImageProvider<MatrixImage> {
/// Matrix URI pointing to the image.
final Uri uri;
final double scale;
const MatrixImage(this.uri, { this.scale = 1.0 });
Future<Codec> _load(MatrixImage key) async {
final bytes = await di.getHomeserver().download(key.uri);
return PaintingBinding.instance.instantiateImageCodec(bytes);
}
@override
ImageStreamCompleter load(MatrixImage key) {
return MultiFrameImageStreamCompleter(
codec: _load(key),
scale: key.scale
);
}
@override
Future<MatrixImage> obtainKey(ImageConfiguration configuration) {
return SynchronousFuture<MatrixImage>(this);
}
@override
bool operator ==(dynamic other) {
if (other.runtimeType != runtimeType)
return false;
final MatrixImage typedOther = other;
return uri == typedOther.uri
&& scale == typedOther.scale;
}
@override
int get hashCode => hashValues(uri, scale);
}
\ No newline at end of file
......@@ -64,7 +64,7 @@ packages:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.0+1"
version: "0.12.0+2"
http_parser:
dependency: transitive
description:
......@@ -120,14 +120,14 @@ packages:
name: matrix_sdk
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.7"
matrix_sdk_sqflite:
dependency: "direct main"
description:
name: matrix_sdk_sqflite
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
version: "0.1.5"
meta:
dependency: transitive
description:
......@@ -231,6 +231,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.4"
transparent_image:
dependency: "direct main"
description:
name: transparent_image
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
typed_data:
dependency: transitive
description:
......
......@@ -12,11 +12,13 @@ dependencies:
injector: ^1.0.6
matrix_sdk: ^0.1.4
matrix_sdk_sqflite: ^0.1.2
matrix_sdk: ^0.1.7
matrix_sdk_sqflite: ^0.1.5
rxdart: ^0.21.0
transparent_image: ^1.0.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
......
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