add_partipant_page.dart 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import 'package:flutter/material.dart';
  2. import 'package:photos/core/configuration.dart';
  3. import 'package:photos/models/collection.dart';
  4. import 'package:photos/services/collections_service.dart';
  5. import 'package:photos/services/update_service.dart';
  6. import 'package:photos/theme/ente_theme.dart';
  7. import 'package:photos/ui/common/gradient_button.dart';
  8. import 'package:photos/ui/components/captioned_text_widget.dart';
  9. import 'package:photos/ui/components/divider_widget.dart';
  10. import 'package:photos/ui/components/menu_item_widget.dart';
  11. import 'package:photos/ui/components/menu_section_description_widget.dart';
  12. import 'package:photos/ui/components/menu_section_title.dart';
  13. import 'package:photos/ui/sharing/user_avator_widget.dart';
  14. import 'package:photos/utils/toast_util.dart';
  15. class AddParticipantPage extends StatefulWidget {
  16. final Collection collection;
  17. const AddParticipantPage(this.collection, {super.key});
  18. @override
  19. State<StatefulWidget> createState() => _AddParticipantPage();
  20. }
  21. class _AddParticipantPage extends State<AddParticipantPage> {
  22. late bool selectAsViewer;
  23. String selectedEmail = '';
  24. bool hideListOfEmails = false;
  25. @override
  26. void initState() {
  27. selectAsViewer = true;
  28. super.initState();
  29. }
  30. Widget build(BuildContext context) {
  31. final enteColorScheme = getEnteColorScheme(context);
  32. final enteTextTheme = getEnteTextTheme(context);
  33. final int ownerID = Configuration.instance.getUserID()!;
  34. final Set<int> existingUserIDs = {};
  35. for (final User? u in widget.collection?.sharees ?? []) {
  36. if (u != null && u.id != null) {
  37. existingUserIDs.add(u.id!);
  38. }
  39. }
  40. final List<String> emails = [];
  41. for (final c in CollectionsService.instance.getActiveCollections()) {
  42. if (c.owner?.id == ownerID) {
  43. c.sharees?.forEach(
  44. (e) => {
  45. if (existingUserIDs.contains(1))
  46. {
  47. emails.add(e!.email),
  48. }
  49. },
  50. );
  51. } else {
  52. emails.add(c.owner!.email);
  53. }
  54. }
  55. final List<String> finalList = emails.toSet().toList();
  56. hideListOfEmails = finalList.isEmpty;
  57. finalList.sort();
  58. return Scaffold(
  59. appBar: AppBar(
  60. title: const Text("Add people"),
  61. ),
  62. body: Container(
  63. color: enteColorScheme.backgroundElevated,
  64. child: Padding(
  65. padding: const EdgeInsets.symmetric(horizontal: 16.0),
  66. child: Column(
  67. mainAxisAlignment: MainAxisAlignment.start,
  68. crossAxisAlignment: CrossAxisAlignment.start,
  69. children: [
  70. const SizedBox(height: 12),
  71. Text(
  72. "Add a new email",
  73. style: enteTextTheme.body,
  74. ),
  75. hideListOfEmails
  76. ? const Expanded(child: SizedBox())
  77. : Expanded(
  78. child: Column(
  79. children: [
  80. const SizedBox(height: 24),
  81. const MenuSectionTitle(
  82. title: "or pick an existing one",
  83. ),
  84. Expanded(
  85. child: ListView.builder(
  86. itemBuilder: (context, index) {
  87. final currentEmail = finalList[index];
  88. return Column(
  89. children: [
  90. MenuItemWidget(
  91. captionedTextWidget: CaptionedTextWidget(
  92. title: finalList[index],
  93. ),
  94. leadingIconSize: 24.0,
  95. leadingIconWidget: UserAvatarWidget(
  96. User(
  97. id: currentEmail.hashCode,
  98. email: currentEmail,
  99. ),
  100. type: AvatarType.mini,
  101. ),
  102. menuItemColor:
  103. getEnteColorScheme(context).fillFaint,
  104. pressedColor:
  105. getEnteColorScheme(context).fillFaint,
  106. trailingIcon:
  107. (selectedEmail == finalList[index])
  108. ? Icons.check
  109. : null,
  110. onTap: () async {
  111. if (selectedEmail == finalList[index]) {
  112. selectedEmail = '';
  113. } else {
  114. selectedEmail = finalList[index];
  115. }
  116. setState(() => {});
  117. // showShortToast(context, "yet to implement");
  118. },
  119. isTopBorderRadiusRemoved: index > 0,
  120. isBottomBorderRadiusRemoved:
  121. index < (finalList.length - 1),
  122. ),
  123. (index == (finalList.length - 1))
  124. ? const SizedBox.shrink()
  125. : DividerWidget(
  126. dividerType: DividerType.menu,
  127. bgColor: getEnteColorScheme(context)
  128. .blurStrokeFaint,
  129. ),
  130. ],
  131. );
  132. },
  133. itemCount: finalList.length,
  134. // physics: const ClampingScrollPhysics(),
  135. ),
  136. ),
  137. ],
  138. ),
  139. ),
  140. const DividerWidget(
  141. dividerType: DividerType.solid,
  142. ),
  143. SafeArea(
  144. child: Padding(
  145. padding: const EdgeInsets.only(top: 8, bottom: 8),
  146. child: Column(
  147. crossAxisAlignment: CrossAxisAlignment.start,
  148. children: [
  149. const MenuSectionTitle(title: "Add as"),
  150. MenuItemWidget(
  151. captionedTextWidget: const CaptionedTextWidget(
  152. title: "Collaborator",
  153. ),
  154. leadingIcon: Icons.edit,
  155. menuItemColor: getEnteColorScheme(context).fillFaint,
  156. pressedColor: getEnteColorScheme(context).fillFaint,
  157. trailingIcon: !selectAsViewer ? Icons.check : null,
  158. onTap: () async {
  159. showShortToast(context, "coming soon!");
  160. setState(() => {selectAsViewer = false});
  161. },
  162. isBottomBorderRadiusRemoved: true,
  163. ),
  164. DividerWidget(
  165. dividerType: DividerType.menu,
  166. bgColor: getEnteColorScheme(context).blurStrokeFaint,
  167. ),
  168. MenuItemWidget(
  169. captionedTextWidget: const CaptionedTextWidget(
  170. title: " Viewer",
  171. ),
  172. leadingIcon: Icons.photo,
  173. menuItemColor: getEnteColorScheme(context).fillFaint,
  174. pressedColor: getEnteColorScheme(context).fillFaint,
  175. trailingIcon: selectAsViewer ? Icons.check : null,
  176. onTap: () async {
  177. setState(() => {selectAsViewer = true});
  178. // showShortToast(context, "yet to implement");
  179. },
  180. isTopBorderRadiusRemoved: true,
  181. ),
  182. const MenuSectionDescriptionWidget(
  183. content:
  184. "Collaborators can add photos and videos to the shared album.",
  185. ),
  186. const SizedBox(height: 12),
  187. SizedBox(
  188. width: double.infinity,
  189. child: GradientButton(
  190. onTap: selectedEmail == ''
  191. ? null
  192. : () async {
  193. await UpdateService.instance.hideChangeLog();
  194. Navigator.of(context).pop();
  195. },
  196. text: selectAsViewer
  197. ? "Add viewer"
  198. : "Add collaborator",
  199. ),
  200. ),
  201. const SizedBox(height: 8),
  202. ],
  203. ),
  204. ),
  205. ),
  206. ],
  207. ),
  208. ),
  209. ),
  210. );
  211. }
  212. }