-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-403: add share screen and share intent
- Loading branch information
1 parent
d072481
commit 7822458
Showing
8 changed files
with
188 additions
and
37 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
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,66 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:fluffychat/di/global/get_it_initializer.dart'; | ||
import 'package:fluffychat/domain/usecase/send_file_interactor.dart'; | ||
import 'package:fluffychat/pages/share/share_view.dart'; | ||
import 'package:fluffychat/presentation/mixins/send_files_mixin.dart'; | ||
import 'package:fluffychat/widgets/matrix.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
import 'package:scroll_to_index/scroll_to_index.dart'; | ||
|
||
class Share extends StatefulWidget { | ||
const Share({super.key}); | ||
|
||
@override | ||
State<Share> createState() => ShareController(); | ||
} | ||
|
||
class ShareController extends State<Share> with SendFilesMixin { | ||
final sendFileInteractor = getIt.get<SendFileInteractor>(); | ||
|
||
final isShowRecentlyChatsNotifier = ValueNotifier(true); | ||
|
||
final AutoScrollController recentChatScrollController = | ||
AutoScrollController(); | ||
|
||
final selectedRoomsNotifier = ValueNotifier(<String>[]); | ||
|
||
void onSelectChat(String id) { | ||
if (selectedRoomsNotifier.value.contains(id)) { | ||
selectedRoomsNotifier.value.remove(id); | ||
} else { | ||
selectedRoomsNotifier.value.add(id); | ||
} | ||
selectedRoomsNotifier.value = selectedRoomsNotifier.value.sorted( | ||
(current, next) => current.compareTo(next), | ||
); | ||
} | ||
|
||
void toggleRecentlyChats() { | ||
isShowRecentlyChatsNotifier.value = !isShowRecentlyChatsNotifier.value; | ||
} | ||
|
||
void shareTo(String roomId) async { | ||
final room = Room( | ||
id: selectedRoomsNotifier.value.first, | ||
client: Matrix.of(context).client, | ||
); | ||
final shareContent = Matrix.of(context).shareContent; | ||
if (shareContent != null) { | ||
final shareFile = shareContent.tryGet<MatrixFile>('file'); | ||
if (shareContent.tryGet<String>('msgtype') == 'chat.fluffy.shared_file') { | ||
context.go('/rooms/${room.id}', extra: shareFile); | ||
} else { | ||
room.sendEvent(shareContent); | ||
context.go('/rooms/${room.id}'); | ||
} | ||
Matrix.of(context).shareContent = null; | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ShareView(this); | ||
} | ||
} |
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,80 @@ | ||
import 'package:fluffychat/pages/forward/recent_chat_list.dart'; | ||
import 'package:fluffychat/pages/forward/recent_chat_title.dart'; | ||
import 'package:fluffychat/pages/share/share.dart'; | ||
import 'package:fluffychat/widgets/matrix.dart'; | ||
import 'package:fluffychat/widgets/twake_components/twake_fab.dart'; | ||
import 'package:fluffychat/widgets/twake_components/twake_icon_button.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/l10n.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
class ShareView extends StatelessWidget { | ||
const ShareView(this.controller, {super.key}); | ||
|
||
final ShareController controller; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
centerTitle: true, | ||
title: Text( | ||
L10n.of(context)!.share, | ||
style: Theme.of(context).textTheme.headlineLarge, | ||
), | ||
leading: TwakeIconButton( | ||
tooltip: L10n.of(context)!.cancel, | ||
icon: Icons.close, | ||
onPressed: () => context.pop(), | ||
), | ||
), | ||
body: Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 16.0), | ||
child: SingleChildScrollView( | ||
child: Column( | ||
children: [ | ||
RecentChatsTitle( | ||
isShowRecentlyChats: | ||
controller.isShowRecentlyChatsNotifier.value, | ||
toggleRecentChat: controller.toggleRecentlyChats, | ||
), | ||
ValueListenableBuilder<bool>( | ||
valueListenable: controller.isShowRecentlyChatsNotifier, | ||
builder: (context, isShowRecentlyChat, child) { | ||
if (isShowRecentlyChat) { | ||
return RecentChatList( | ||
rooms: Matrix.of(context).client.rooms, | ||
selectedEventsNotifier: controller.selectedRoomsNotifier, | ||
onSelectedChat: (roomId) => | ||
controller.onSelectChat(roomId), | ||
recentChatScrollController: | ||
controller.recentChatScrollController, | ||
); | ||
} | ||
|
||
return const SizedBox.shrink(); | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat, | ||
floatingActionButton: ValueListenableBuilder<List<String>>( | ||
valueListenable: controller.selectedRoomsNotifier, | ||
builder: ((context, selectedChats, child) { | ||
if (selectedChats.length != 1) { | ||
return const SizedBox.shrink(); | ||
} | ||
return TwakeFloatingActionButton( | ||
icon: Icons.send, | ||
size: 18.0, | ||
onTap: () => controller.shareTo( | ||
controller.selectedRoomsNotifier.value.first, | ||
), | ||
); | ||
}), | ||
), | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -1933,10 +1933,11 @@ packages: | |
receive_sharing_intent: | ||
dependency: "direct main" | ||
description: | ||
name: receive_sharing_intent | ||
sha256: "912bebb551bce75a14098891fd750305b30d53eba0d61cc70cd9973be9866e8d" | ||
url: "https://pub.dev" | ||
source: hosted | ||
path: "." | ||
ref: "receive-.txt-v2" | ||
resolved-ref: "7ac2cccb3e1ac4bddce7e287adcb69726f368b89" | ||
url: "[email protected]:krabbenprgr/receive_sharing_intent.git" | ||
source: git | ||
version: "1.4.5" | ||
record: | ||
dependency: "direct main" | ||
|
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 |
---|---|---|
|
@@ -77,7 +77,10 @@ dependencies: | |
punycode: ^1.0.0 | ||
qr_code_scanner: ^1.0.0 | ||
qr_flutter: ^4.0.0 | ||
receive_sharing_intent: ^1.4.5 | ||
receive_sharing_intent: | ||
git: | ||
url: [email protected]:krabbenprgr/receive_sharing_intent.git | ||
ref: receive-.txt-v2 | ||
record: ^4.4.4 | ||
scroll_to_index: ^3.0.1 | ||
share_plus: ^4.0.10+1 | ||
|