-
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-615 List all link of Chat in Chat details only mobile
- Loading branch information
1 parent
4e1db2c
commit 01130f2
Showing
6 changed files
with
203 additions
and
75 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
lib/pages/chat_details/chat_details_page_view/links/chat_details_links_item.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,125 @@ | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/domain/app_state/preview_url/get_preview_url_success.dart'; | ||
import 'package:fluffychat/pages/chat_details/chat_details_page_view/links/chat_details_links_style.dart'; | ||
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; | ||
import 'package:fluffychat/utils/string_extension.dart'; | ||
import 'package:fluffychat/utils/url_launcher.dart'; | ||
import 'package:fluffychat/widgets/mixins/get_preview_url_mixin.dart'; | ||
import 'package:fluffychat/widgets/mxc_image.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
class ChatDetailsLinkItem extends StatefulWidget { | ||
const ChatDetailsLinkItem({ | ||
super.key, | ||
required this.event, | ||
}); | ||
|
||
final Event event; | ||
|
||
@override | ||
State<ChatDetailsLinkItem> createState() => _ChatDetailsLinkItemState(); | ||
} | ||
|
||
class _ChatDetailsLinkItemState extends State<ChatDetailsLinkItem> | ||
with GetPreviewUrlMixin { | ||
String get _link => widget.event.firstValidUrl ?? ''; | ||
|
||
Uri get _uri { | ||
return Uri.tryParse(_link) ?? Uri(); | ||
} | ||
|
||
@override | ||
String debugLabel = 'ChatDetailsLinkItem'; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
getPreviewUrl(uri: _uri); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ValueListenableBuilder( | ||
valueListenable: getPreviewUrlStateNotifier, | ||
builder: (context, previewUrlState, child) { | ||
final urlPreview = previewUrlState | ||
.getSuccessOrNull<GetPreviewUrlSuccess>() | ||
?.urlPreview; | ||
return InkWell( | ||
onTap: () => UrlLauncher(context, _link).launchUrl(), | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric( | ||
horizontal: ChatDetailsLinksStyle.margin, | ||
), | ||
child: Row( | ||
children: [ | ||
Container( | ||
width: ChatDetailsLinksStyle.avatarSize, | ||
height: ChatDetailsLinksStyle.avatarSize, | ||
alignment: Alignment.center, | ||
decoration: ChatDetailsLinksStyle.avatarDecoration(context), | ||
child: urlPreview?.imageUri != null | ||
? MxcImage( | ||
uri: urlPreview!.imageUri, | ||
isThumbnail: false, | ||
fit: BoxFit.cover, | ||
width: ChatDetailsLinksStyle.avatarSize, | ||
height: ChatDetailsLinksStyle.avatarSize, | ||
placeholder: (_) => child!, | ||
) | ||
: child!, | ||
), | ||
const SizedBox( | ||
width: ChatDetailsLinksStyle.margin, | ||
), | ||
Expanded( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text( | ||
urlPreview?.title ?? _link, | ||
maxLines: 2, | ||
style: ChatDetailsLinksStyle.titleTextStyle(context), | ||
), | ||
if (urlPreview?.description != null) | ||
Text( | ||
urlPreview!.description!, | ||
maxLines: 2, | ||
style: ChatDetailsLinksStyle.descriptionTextStyle( | ||
context, | ||
), | ||
), | ||
Text( | ||
_link, | ||
maxLines: 2, | ||
style: ChatDetailsLinksStyle.linkTextStyle(context), | ||
), | ||
], | ||
), | ||
) | ||
], | ||
), | ||
), | ||
); | ||
}, | ||
child: _AvatarPlaceholder(uri: _uri), | ||
); | ||
} | ||
} | ||
|
||
class _AvatarPlaceholder extends StatelessWidget { | ||
const _AvatarPlaceholder({ | ||
required this.uri, | ||
}); | ||
|
||
final Uri uri; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Text( | ||
uri.host.getShortcutNameForAvatar(), | ||
style: ChatDetailsLinksStyle.avatarTextStyle(context), | ||
); | ||
} | ||
} |
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
10 changes: 9 additions & 1 deletion
10
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fluffychat/app_state/failure.dart'; | ||
import 'package:fluffychat/app_state/success.dart'; | ||
import 'package:fluffychat/di/global/get_it_initializer.dart'; | ||
import 'package:fluffychat/domain/app_state/preview_url/get_preview_url_success.dart'; | ||
import 'package:fluffychat/domain/usecase/preview_url/get_preview_url_interactor.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
|
||
mixin GetPreviewUrlMixin { | ||
static const int _defaultPreferredPreviewTimeInMilliseconds = 2000; | ||
|
||
final GetPreviewURLInteractor _getPreviewURLInteractor = | ||
getIt.get<GetPreviewURLInteractor>(); | ||
|
||
final getPreviewUrlStateNotifier = | ||
ValueNotifier<Either<Failure, Success>>(Right(GetPreviewUrlInitial())); | ||
|
||
abstract String debugLabel; | ||
|
||
void getPreviewUrl({ | ||
required Uri uri, | ||
int preferredPreviewTime = _defaultPreferredPreviewTimeInMilliseconds, | ||
}) { | ||
_getPreviewURLInteractor | ||
.execute( | ||
uri: uri, | ||
preferredPreviewTime: preferredPreviewTime, | ||
) | ||
.listen( | ||
_handleGetPreviewUrlOnData, | ||
onError: _handleGetPreviewUrlOnError, | ||
onDone: _handleGetPreviewUrlOnDone, | ||
); | ||
} | ||
|
||
void _handleGetPreviewUrlOnData(Either<Failure, Success> event) { | ||
Logs().d('$debugLabel::_handleGetPreviewUrlOnData()'); | ||
getPreviewUrlStateNotifier.value = event; | ||
} | ||
|
||
void _handleGetPreviewUrlOnDone() { | ||
Logs().d( | ||
'$debugLabel::_handleGetPreviewUrlOnDone() - done', | ||
); | ||
} | ||
|
||
void _handleGetPreviewUrlOnError( | ||
dynamic error, | ||
StackTrace? stackTrace, | ||
) { | ||
Logs().e( | ||
'$debugLabel::_handleGetPreviewUrlOnError() - error: $error | stackTrace: $stackTrace', | ||
); | ||
} | ||
} |
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