Update sharing interaction
This commit is contained in:
parent
6e02cae865
commit
ab30c18b6e
5 changed files with 37 additions and 37 deletions
|
@ -37,6 +37,7 @@ class _CollectionPageState extends State<CollectionPage> {
|
|||
GalleryAppBarType.collection,
|
||||
widget.collection.name,
|
||||
_selectedFiles,
|
||||
collection: widget.collection,
|
||||
),
|
||||
body: gallery,
|
||||
);
|
||||
|
|
|
@ -31,7 +31,7 @@ class _DeviceFolderPageState extends State<DeviceFolderPage> {
|
|||
GalleryAppBarType.local_folder,
|
||||
widget.folder.name,
|
||||
_selectedFiles,
|
||||
widget.folder.thumbnail.deviceFolder,
|
||||
path: widget.folder.thumbnail.deviceFolder,
|
||||
),
|
||||
body: gallery,
|
||||
);
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:page_transition/page_transition.dart';
|
|||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/core/event_bus.dart';
|
||||
import 'package:photos/events/user_authenticated_event.dart';
|
||||
import 'package:photos/models/collection.dart';
|
||||
import 'package:photos/models/selected_files.dart';
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import 'package:photos/ui/create_collection_page.dart';
|
||||
|
@ -31,13 +32,15 @@ class GalleryAppBarWidget extends StatefulWidget
|
|||
final String title;
|
||||
final SelectedFiles selectedFiles;
|
||||
final String path;
|
||||
final Collection collection;
|
||||
|
||||
GalleryAppBarWidget(
|
||||
this.type,
|
||||
this.title,
|
||||
this.selectedFiles, [
|
||||
this.selectedFiles, {
|
||||
this.path,
|
||||
]);
|
||||
this.collection,
|
||||
});
|
||||
|
||||
@override
|
||||
_GalleryAppBarWidgetState createState() => _GalleryAppBarWidgetState();
|
||||
|
@ -103,9 +106,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
);
|
||||
},
|
||||
));
|
||||
} else if (widget.type == GalleryAppBarType.local_folder) {
|
||||
} else if (widget.type == GalleryAppBarType.local_folder ||
|
||||
widget.type == GalleryAppBarType.collection) {
|
||||
actions.add(IconButton(
|
||||
icon: Icon(Icons.share),
|
||||
icon: Icon(Icons.person_add),
|
||||
onPressed: () {
|
||||
_showShareCollectionDialog();
|
||||
},
|
||||
|
@ -142,15 +146,27 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
}
|
||||
|
||||
Future<void> _showShareCollectionDialog() async {
|
||||
var collection = widget.collection;
|
||||
if (collection == null) {
|
||||
if (widget.type == GalleryAppBarType.local_folder) {
|
||||
collection =
|
||||
CollectionsService.instance.getCollectionForPath(widget.path);
|
||||
if (collection == null) {
|
||||
final dialog = createProgressDialog(context, "Please wait...");
|
||||
await dialog.show();
|
||||
collection =
|
||||
await CollectionsService.instance.getOrCreateForPath(widget.path);
|
||||
await dialog.hide();
|
||||
}
|
||||
} else {
|
||||
throw Exception(
|
||||
"Cannot create a collection of type" + widget.type.toString());
|
||||
}
|
||||
}
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ShareFolderWidget(
|
||||
widget.title,
|
||||
widget.path,
|
||||
collection:
|
||||
CollectionsService.instance.getCollectionForPath(widget.path),
|
||||
);
|
||||
return ShareFolderWidget(collection);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -79,7 +79,6 @@ class _HomeWidgetState extends State<HomeWidget> {
|
|||
GalleryAppBarType.homepage,
|
||||
widget.title,
|
||||
_selectedFiles,
|
||||
"/",
|
||||
),
|
||||
bottomNavigationBar: _buildBottomNavigationBar(),
|
||||
body: IndexedStack(
|
||||
|
|
|
@ -7,7 +7,6 @@ import 'package:photos/db/public_keys_db.dart';
|
|||
import 'package:photos/models/collection.dart';
|
||||
import 'package:photos/models/public_key.dart';
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import 'package:photos/services/sync_service.dart';
|
||||
import 'package:photos/services/user_service.dart';
|
||||
import 'package:photos/ui/common_elements.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
|
@ -17,14 +16,10 @@ import 'package:photos/utils/share_util.dart';
|
|||
import 'package:photos/utils/toast_util.dart';
|
||||
|
||||
class ShareFolderWidget extends StatefulWidget {
|
||||
final String title;
|
||||
final String path;
|
||||
final Collection collection;
|
||||
|
||||
const ShareFolderWidget(
|
||||
this.title,
|
||||
this.path, {
|
||||
this.collection,
|
||||
this.collection, {
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
|
@ -41,7 +36,7 @@ class _ShareFolderWidgetState extends State<ShareFolderWidget> {
|
|||
: CollectionsService.instance.getSharees(widget.collection.id),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return SharingDialog(widget.collection, snapshot.data, widget.path);
|
||||
return SharingDialog(widget.collection, snapshot.data);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text(snapshot.error.toString());
|
||||
} else {
|
||||
|
@ -55,10 +50,8 @@ class _ShareFolderWidgetState extends State<ShareFolderWidget> {
|
|||
class SharingDialog extends StatefulWidget {
|
||||
final Collection collection;
|
||||
final List<String> sharees;
|
||||
final String path;
|
||||
|
||||
SharingDialog(this.collection, this.sharees, this.path, {Key key})
|
||||
: super(key: key);
|
||||
SharingDialog(this.collection, this.sharees, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SharingDialogState createState() => _SharingDialogState();
|
||||
|
@ -170,13 +163,13 @@ class _SharingDialogState extends State<SharingDialog> {
|
|||
"Please enter a valid email address.");
|
||||
return;
|
||||
} else if (email == Configuration.instance.getEmail()) {
|
||||
showErrorDialog(
|
||||
context, "Oops", "You cannot share the album with yourself.");
|
||||
showErrorDialog(context, "Oops", "You cannot share with yourself.");
|
||||
return;
|
||||
}
|
||||
if (publicKey == null) {
|
||||
final dialog = createProgressDialog(context, "Searching for user...");
|
||||
await dialog.show();
|
||||
|
||||
publicKey = await UserService.instance.getPublicKey(email);
|
||||
await dialog.hide();
|
||||
}
|
||||
|
@ -192,7 +185,7 @@ class _SharingDialogState extends State<SharingDialog> {
|
|||
child: Text("Invite"),
|
||||
onPressed: () {
|
||||
shareText(
|
||||
"Hey, I've got some really nice photos to share. Please install ente.io so that I can share them privately.");
|
||||
"Hey, I have some really nice photos to share. Please install ente.io so that I can share them privately.");
|
||||
},
|
||||
),
|
||||
],
|
||||
|
@ -206,20 +199,11 @@ class _SharingDialogState extends State<SharingDialog> {
|
|||
} else {
|
||||
final dialog = createProgressDialog(context, "Sharing...");
|
||||
await dialog.show();
|
||||
var collectionID;
|
||||
if (widget.collection != null) {
|
||||
collectionID = widget.collection.id;
|
||||
} else {
|
||||
collectionID =
|
||||
(await CollectionsService.instance.getOrCreateForPath(widget.path))
|
||||
.id;
|
||||
await Configuration.instance.addPathToFoldersToBeBackedUp(widget.path);
|
||||
SyncService.instance.sync();
|
||||
}
|
||||
try {
|
||||
await CollectionsService.instance.share(collectionID, email, publicKey);
|
||||
await CollectionsService.instance
|
||||
.share(widget.collection.id, email, publicKey);
|
||||
await dialog.hide();
|
||||
showToast("Folder shared successfully!");
|
||||
showToast("Shared successfully!");
|
||||
setState(() {
|
||||
_sharees.add(email);
|
||||
_showEntryField = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue