-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-616 List all image & video of Chat in Chat details
- Loading branch information
1 parent
e20a601
commit 808ba61
Showing
18 changed files
with
471 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
lib/domain/app_state/room/timeline_search_event_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
class TimelineSearchEventInitial extends Success { | ||
@override | ||
List<Object?> get props => []; | ||
} | ||
|
||
class TimelineSearchEventSuccess extends Success { | ||
final List<Event> events; | ||
|
||
const TimelineSearchEventSuccess({required this.events}); | ||
|
||
@override | ||
List<Object?> get props => [events]; | ||
} | ||
|
||
class TimelineSearchEventFailure extends Failure { | ||
final dynamic exception; | ||
|
||
const TimelineSearchEventFailure({required this.exception}); | ||
|
||
@override | ||
List<Object?> get props => [exception]; | ||
} | ||
|
||
extension TimelineSearchEventSuccessExtension on TimelineSearchEventSuccess { | ||
TimelineSearchEventSuccess addMore(TimelineSearchEventSuccess other) { | ||
return TimelineSearchEventSuccess( | ||
events: events + other.events, | ||
); | ||
} | ||
} | ||
|
||
extension TimelineSearchEventEitherExtension on Either { | ||
TimelineSearchEventSuccess? getSuccessOrNull() => fold( | ||
(failure) => null, | ||
(success) => success is TimelineSearchEventSuccess ? success : null, | ||
); | ||
} |
35 changes: 35 additions & 0 deletions
35
lib/domain/usecase/room/timeline_search_event_interactor.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/domain/app_state/room/timeline_search_event_state.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
class TimelineSearchEventInteractor { | ||
Stream<Either<Failure, Success>> execute({ | ||
required Timeline timeline, | ||
required bool Function(Event) searchFunc, | ||
required int requestHistoryCount, | ||
required int maxHistoryRequests, | ||
required int? limit, | ||
String? sinceEventId, | ||
}) async* { | ||
try { | ||
yield* timeline | ||
.searchEvent( | ||
searchFunc: searchFunc, | ||
requestHistoryCount: requestHistoryCount, | ||
maxHistoryRequests: maxHistoryRequests, | ||
limit: limit, | ||
sinceEventId: sinceEventId, | ||
) | ||
.map((events) { | ||
Logs().v( | ||
'TimelineSearchEventInteractor::events ${events.length} ${events.map((event) => event.eventId)}', | ||
); | ||
return Right(TimelineSearchEventSuccess(events: events)); | ||
}); | ||
} catch (e) { | ||
yield Left(TimelineSearchEventFailure(exception: e)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
lib/pages/chat_details/chat_details_page_view/links/chat_details_links_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'package:fluffychat/domain/app_state/room/timeline_search_event_state.dart'; | ||
import 'package:fluffychat/pages/chat_details/chat_details_page_view/links/chat_details_links_style.dart'; | ||
import 'package:fluffychat/utils/string_extension.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
import 'package:fluffychat/pages/chat_details/chat_details_page_view/same_type_events_list_builder.dart'; | ||
import 'package:fluffychat/pages/chat_details/chat_details_page_view/same_type_events_list_controller.dart'; | ||
|
||
class ChatDetailsLinksPage extends StatelessWidget { | ||
final SameTypeEventsListController eventsListController; | ||
final Future<Timeline> Function() getTimeline; | ||
|
||
const ChatDetailsLinksPage({ | ||
Key? key, | ||
required this.eventsListController, | ||
required this.getTimeline, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SameTypeEventsListBuilder( | ||
controller: eventsListController, | ||
getTimeline: getTimeline, | ||
builder: (context, eventsState) { | ||
final events = eventsState.getSuccessOrNull()?.events ?? []; | ||
return ListView.separated( | ||
itemCount: events.length, | ||
itemBuilder: (context, index) { | ||
final body = events[index].body; | ||
final link = body.getFirstValidUrl() ?? ''; | ||
return ListTile( | ||
leading: Container( | ||
width: ChatDetailsLinksStyle.avatarSize, | ||
height: ChatDetailsLinksStyle.avatarSize, | ||
alignment: Alignment.center, | ||
decoration: ChatDetailsLinksStyle.avatarDecoration(context), | ||
child: Text( | ||
link.getShortcutNameForAvatar(), | ||
style: ChatDetailsLinksStyle.avatarTextStyle(context), | ||
), | ||
), | ||
title: Text(link), | ||
subtitle: Text( | ||
link, | ||
style: ChatDetailsLinksStyle.subtitleTextStyle(context), | ||
), | ||
); | ||
}, | ||
separatorBuilder: (context, index) => const Divider(), | ||
); | ||
}, | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
lib/pages/chat_details/chat_details_page_view/links/chat_details_links_style.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ChatDetailsLinksStyle { | ||
static const double avatarSize = 56; | ||
static BoxDecoration avatarDecoration(BuildContext context) => BoxDecoration( | ||
color: Theme.of(context).colorScheme.secondary, | ||
borderRadius: BorderRadius.circular(16), | ||
); | ||
static TextStyle? avatarTextStyle(BuildContext context) => | ||
Theme.of(context).textTheme.headlineLarge?.copyWith( | ||
color: Theme.of(context).colorScheme.onSecondary, | ||
); | ||
static TextStyle? subtitleTextStyle(BuildContext context) => | ||
Theme.of(context).textTheme.bodyMedium?.copyWith( | ||
color: Theme.of(context).colorScheme.secondary, | ||
); | ||
} |
77 changes: 77 additions & 0 deletions
77
lib/pages/chat_details/chat_details_page_view/media/chat_details_media_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import 'package:fluffychat/config/app_config.dart'; | ||
import 'package:fluffychat/domain/app_state/room/timeline_search_event_state.dart'; | ||
import 'package:fluffychat/pages/chat_details/chat_details_page_view/media/chat_details_media_style.dart'; | ||
import 'package:fluffychat/pages/chat_details/chat_details_page_view/same_type_events_list_builder.dart'; | ||
import 'package:fluffychat/pages/chat_details/chat_details_page_view/same_type_events_list_controller.dart'; | ||
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; | ||
import 'package:fluffychat/widgets/mxc_image.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_blurhash/flutter_blurhash.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
class ChatDetailsMediaPage extends StatelessWidget { | ||
final SameTypeEventsListController eventsListController; | ||
final Future<Timeline> Function() getTimeline; | ||
final MxcImageCacheMap cacheMap; | ||
const ChatDetailsMediaPage({ | ||
Key? key, | ||
required this.eventsListController, | ||
required this.getTimeline, | ||
required this.cacheMap, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SameTypeEventsListBuilder( | ||
controller: eventsListController, | ||
getTimeline: getTimeline, | ||
builder: (context, eventsState) { | ||
final events = eventsState.getSuccessOrNull()?.events ?? []; | ||
return CustomScrollView( | ||
slivers: [ | ||
SliverGrid.builder( | ||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( | ||
crossAxisCount: 3, | ||
), | ||
itemCount: events.length, | ||
itemBuilder: (context, index) => Stack( | ||
fit: StackFit.expand, | ||
children: [ | ||
MxcImage( | ||
event: events[index], | ||
isThumbnail: true, | ||
fit: BoxFit.cover, | ||
onTapPreview: () {}, | ||
isPreview: true, | ||
placeholder: (context) => BlurHash( | ||
hash: events[index].blurHash ?? | ||
AppConfig.defaultImageBlurHash, | ||
), | ||
cacheKey: events[index].eventId, | ||
cacheMap: cacheMap, | ||
), | ||
if (events[index].messageType == MessageTypes.Video) | ||
Positioned( | ||
bottom: 10, | ||
right: 10, | ||
child: Container( | ||
padding: ChatDetailsMediaStyle.durationPadding, | ||
decoration: ChatDetailsMediaStyle.durationBoxDecoration( | ||
context, | ||
), | ||
child: Text( | ||
"00:00", | ||
style: | ||
ChatDetailsMediaStyle.durationTextStyle(context), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
) | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
lib/pages/chat_details/chat_details_page_view/media/chat_details_media_style.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ChatDetailsMediaStyle { | ||
static const durationPadding = EdgeInsets.symmetric( | ||
horizontal: 4, | ||
vertical: 2, | ||
); | ||
|
||
static Decoration durationBoxDecoration(BuildContext context) => | ||
ShapeDecoration( | ||
color: Theme.of(context).colorScheme.onBackground.withOpacity(0.5), | ||
shape: const StadiumBorder(), | ||
); | ||
|
||
static TextStyle? durationTextStyle(BuildContext context) => | ||
Theme.of(context).textTheme.bodySmall?.copyWith( | ||
color: Theme.of(context).colorScheme.onPrimary, | ||
); | ||
} |
Oops, something went wrong.