Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add sharing functionality to CollectionPage

AmanRajSinghMouryae393b92a3d71
diff --git a/mobile/apps/locker/lib/ui/pages/collection_page.dart b/mobile/apps/locker/lib/ui/pages/collection_page.dart
index 4185890b45..479aaac2e6 100644
--- a/mobile/apps/locker/lib/ui/pages/collection_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/collection_page.dart
@@ -1,16 +1,22 @@
+import "dart:async";
+
import 'package:ente_events/event_bus.dart';
import 'package:ente_ui/theme/ente_theme.dart';
+import "package:ente_utils/navigation_util.dart";
import 'package:flutter/material.dart';
import 'package:locker/events/collections_updated_event.dart';
import 'package:locker/l10n/l10n.dart';
import 'package:locker/services/collections/collections_service.dart';
import 'package:locker/services/collections/models/collection.dart';
+import "package:locker/services/configuration.dart";
import 'package:locker/services/files/sync/models/file.dart';
import 'package:locker/ui/components/item_list_view.dart';
import 'package:locker/ui/components/search_result_view.dart';
import 'package:locker/ui/mixins/search_mixin.dart';
import 'package:locker/ui/pages/home_page.dart';
import 'package:locker/ui/pages/uploader_page.dart';
+import "package:locker/ui/sharing/manage_links_widget.dart";
+import "package:locker/ui/sharing/share_collection_page.dart";
import 'package:locker/utils/collection_actions.dart';
class CollectionPage extends UploaderPage {
@@ -30,6 +36,7 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
late Collection _collection;
List<EnteFile> _files = [];
List<EnteFile> _filteredFiles = [];
+ bool isQuickLink = false;
@override
void onFileUploadComplete() {
@@ -51,7 +58,9 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
@override
void onSearchResultsChanged(
- List<Collection> collections, List<EnteFile> files,) {
+ List<Collection> collections,
+ List<EnteFile> files,
+ ) {
setState(() {
_filteredFiles = files;
});
@@ -112,6 +121,19 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
);
}
+ Future<void> _shareCollection() async {
+ if (Configuration.instance.getUserID() == widget.collection.owner.id) {
+ unawaited(
+ routeToPage(
+ context,
+ (isQuickLink && (widget.collection.hasLink))
+ ? ManageSharedLinkWidget(collection: widget.collection)
+ : ShareCollectionPage(collection: widget.collection),
+ ),
+ );
+ }
+ }
+
@override
Widget build(BuildContext context) {
return KeyboardListener(
@@ -139,6 +161,14 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
actions: [
buildSearchAction(),
...buildSearchActions(),
+ IconButton(
+ icon: Icon(
+ Icons.adaptive.share,
+ ),
+ onPressed: () async {
+ await _shareCollection();
+ },
+ ),
_buildMenuButton(),
],
);
diff --git a/mobile/apps/locker/lib/utils/collection_actions.dart b/mobile/apps/locker/lib/utils/collection_actions.dart
index 90bdc76473..e83ebeec63 100644
--- a/mobile/apps/locker/lib/utils/collection_actions.dart
+++ b/mobile/apps/locker/lib/utils/collection_actions.dart
@@ -1,8 +1,11 @@
+import "package:ente_ui/components/action_sheet_widget.dart";
import 'package:ente_ui/components/buttons/button_widget.dart';
import 'package:ente_ui/components/buttons/models/button_type.dart';
import 'package:ente_ui/utils/dialog_util.dart';
import 'package:flutter/material.dart';
+import "package:locker/core/errors.dart";
import 'package:locker/l10n/l10n.dart';
+import "package:locker/services/collections/collections_api_client.dart";
import 'package:locker/services/collections/collections_service.dart';
import 'package:locker/services/collections/models/collection.dart';
import 'package:locker/utils/snack_bar_utils.dart';
@@ -157,4 +160,118 @@ class CollectionActions {
);
}
}
+
+ static Future<bool> enableUrl(
+ BuildContext context,
+ Collection collection, {
+ bool enableCollect = false,
+ }) async {
+ try {
+ await CollectionApiClient.instance.createShareUrl(
+ collection,
+ enableCollect: enableCollect,
+ );
+ return true;
+ } catch (e) {
+ if (e is SharingNotPermittedForFreeAccountsError) {
+ await _showUnSupportedAlert(context);
+ } else {
+ _logger.severe("Failed to update shareUrl collection", e);
+ await showGenericErrorDialog(context: context, error: e);
+ }
+ return false;
+ }
+ }
+
+ static Future<bool> disableUrl(
+ BuildContext context,
+ Collection collection,
+ ) async {
+ final actionResult = await showActionSheet(
+ context: context,
+ buttons: [
+ ButtonWidget(
+ buttonType: ButtonType.critical,
+ isInAlert: true,
+ shouldStickToDarkTheme: true,
+ buttonAction: ButtonAction.first,
+ shouldSurfaceExecutionStates: true,
+ labelText: "Yes, remove",
+ onTap: () async {
+ await CollectionApiClient.instance.disableShareUrl(collection);
+ },
+ ),
+ ButtonWidget(
+ buttonType: ButtonType.secondary,
+ buttonAction: ButtonAction.cancel,
+ isInAlert: true,
+ shouldStickToDarkTheme: true,
+ labelText: context.l10n.cancel,
+ ),
+ ],
+ title: "Remove public link",
+ body:
+ "This will remove the public link for accessing \"${collection.name}\".",
+ );
+ if (actionResult?.action != null) {
+ if (actionResult!.action == ButtonAction.error) {
+ await showGenericErrorDialog(
+ context: context,
+ error: actionResult.exception,
+ );
+ }
+ return actionResult.action == ButtonAction.first;
+ } else {
+ return false;
+ }
+ }
+
+ static Future<void> _showUnSupportedAlert(BuildContext context) async {
+ final AlertDialog alert = AlertDialog(
+ title: const Text("Sorry"),
+ content: const Text(
+ "You need an active paid subscription to enable sharing.",
+ ),
+ actions: [
+ ButtonWidget(
+ buttonType: ButtonType.primary,
+ isInAlert: true,
+ shouldStickToDarkTheme: false,
+ buttonAction: ButtonAction.first,
+ shouldSurfaceExecutionStates: true,
+ labelText: "Subscribe",
+ onTap: () async {
+ // TODO: If we are having subscriptions for locker
+ // Navigator.of(context).push(
+ // MaterialPageRoute(
+ // builder: (BuildContext context) {
+ // return getSubscriptionPage();
+ // },
+ // ),
+ // ).ignore();
+ Navigator.of(context).pop();
+ },
+ ),
+ Padding(
+ padding: const EdgeInsets.only(top: 8.0),
+ child: ButtonWidget(
+ buttonType: ButtonType.secondary,
+ buttonAction: ButtonAction.cancel,
+ isInAlert: true,
+ shouldStickToDarkTheme: false,
+ labelText: context.l10n.ok,
+ ),
+ ),
+ ],
+ );
+
+ return showDialog(
+ useRootNavigator: false,
+ context: context,
+ builder: (BuildContext context) {
+ return alert;
+ },
+ barrierDismissible: true,
+ );
+ }
}