Commit 86adc65f authored by Wilko Manger's avatar Wilko Manger

Remove need for typing span util

parent cad238c6
......@@ -27,6 +27,7 @@ import 'package:pattle/src/app.dart';
import 'package:pattle/src/resources/localizations.dart';
import 'package:pattle/src/resources/theme.dart';
import 'package:pattle/src/section/main/chats/models/chat.dart';
import 'package:pattle/src/section/main/chats/widgets/typing_content.dart';
import 'package:pattle/src/section/main/widgets/chat_name.dart';
import 'package:pattle/src/section/main/widgets/error.dart';
import 'package:pattle/src/section/main/widgets/title_with_sub.dart';
......@@ -36,7 +37,6 @@ import '../../../util/color.dart';
import '../../../util/url.dart';
import 'bloc.dart';
import 'util/typing_span.dart';
import 'widgets/bubble/message.dart';
import 'widgets/bubble/state.dart';
import 'widgets/date_header.dart';
......@@ -113,11 +113,7 @@ class _ChatPageState extends State<ChatPage> {
_room.isSomeoneElseTyping && !_room.typingUsers.any((u) => u == null)
? TitleWithSub(
title: ChatName(chat: widget.chat),
subtitle: RichText(
text: TextSpan(
children: typingSpan(context, _room),
),
),
subtitle: TypingContent(chat: widget.chat),
)
: ChatName(chat: widget.chat);
......
// 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 'package:flutter/widgets.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/resources/localizations.dart';
// TODO: Use Widget and ChatMember
List<TextSpan> typingSpan(BuildContext context, Room room) {
if (room.isDirect) {
return l(context).typing;
}
if (room.typingUsers.length == 1) {
return l(context).isTyping(
TextSpan(
text: room.typingUsers.first.name,
),
);
}
if (room.typingUsers.length == 2) {
return l(context).areTyping(
TextSpan(
text: room.typingUsers.first.name,
),
TextSpan(
text: room.typingUsers[1].name,
),
);
}
return l(context).andMoreAreTyping(
TextSpan(
text: room.typingUsers.first.name,
),
TextSpan(
text: room.typingUsers[1].name,
),
);
}
......@@ -30,7 +30,7 @@ import '../../../../../matrix.dart';
import 'content/image.dart';
import 'content/redacted.dart';
import 'content/text.dart';
import 'content/typing.dart';
import '../typing_content.dart';
import 'content/unsupported.dart';
class Subtitle extends StatelessWidget {
......@@ -45,7 +45,7 @@ class Subtitle extends StatelessWidget {
// TODO: typingUsers should not contain nulls
if (chat.room.isSomeoneElseTyping &&
!chat.room.typingUsers.any((u) => u == null)) {
content = TypingSubtitleContent();
content = TypingContent(chat: chat);
} else {
final event = chat.latestMessage?.event;
if (event == null) {
......
......@@ -16,16 +16,52 @@
// along with Pattle. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/resources/localizations.dart';
import 'package:pattle/src/resources/theme.dart';
import 'package:pattle/src/section/main/chat/util/typing_span.dart';
import 'package:pattle/src/section/main/chats/models/chat.dart';
import '../subtitle.dart';
class TypingContent extends StatelessWidget {
final Chat chat;
const TypingContent({Key key, @required this.chat}) : super(key: key);
List<TextSpan> _span(BuildContext context, Room room) {
if (room.isDirect) {
return l(context).typing;
}
if (room.typingUsers.length == 1) {
return l(context).isTyping(
TextSpan(
text: room.typingUsers.first.name,
),
);
}
if (room.typingUsers.length == 2) {
return l(context).areTyping(
TextSpan(
text: room.typingUsers.first.name,
),
TextSpan(
text: room.typingUsers[1].name,
),
);
}
return l(context).andMoreAreTyping(
TextSpan(
text: room.typingUsers.first.name,
),
TextSpan(
text: room.typingUsers[1].name,
),
);
}
class TypingSubtitleContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
final room = Subtitle.of(context).chat.room;
return RichText(
maxLines: 1,
overflow: TextOverflow.ellipsis,
......@@ -34,7 +70,7 @@ class TypingSubtitleContent extends StatelessWidget {
color: redOnBackground(context),
fontWeight: FontWeight.bold,
),
children: typingSpan(context, room),
children: _span(context, chat.room),
),
);
}
......
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