Update sharee fetching logic
This commit is contained in:
parent
40ebae5fa3
commit
c75bc2f784
4 changed files with 49 additions and 119 deletions
|
@ -116,7 +116,6 @@ class CollectionsDB {
|
|||
row[columnEncryptedPath],
|
||||
row[columnPathDecryptionNonce],
|
||||
int.parse(row[columnCreationTime]),
|
||||
null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class Collection {
|
||||
final int id;
|
||||
final int ownerID;
|
||||
|
@ -12,7 +10,6 @@ class Collection {
|
|||
final String encryptedPath;
|
||||
final String pathDecryptionNonce;
|
||||
final int creationTime;
|
||||
final List<String> sharees;
|
||||
|
||||
Collection(
|
||||
this.id,
|
||||
|
@ -24,14 +21,8 @@ class Collection {
|
|||
this.encryptedPath,
|
||||
this.pathDecryptionNonce,
|
||||
this.creationTime,
|
||||
this.sharees,
|
||||
);
|
||||
|
||||
static Collection emptyCollection() {
|
||||
return Collection(
|
||||
null, null, null, null, null, null, null, null, null, List<String>());
|
||||
}
|
||||
|
||||
Collection copyWith({
|
||||
int id,
|
||||
int ownerID,
|
||||
|
@ -54,7 +45,6 @@ class Collection {
|
|||
encryptedPath ?? this.encryptedPath,
|
||||
encryptedPath ?? this.pathDecryptionNonce,
|
||||
creationTime ?? this.creationTime,
|
||||
sharees ?? this.sharees,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -69,7 +59,6 @@ class Collection {
|
|||
'creationTime': creationTime,
|
||||
'encryptedPath': encryptedPath,
|
||||
'pathDecryptionNonce': pathDecryptionNonce,
|
||||
'sharees': sharees,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -86,7 +75,6 @@ class Collection {
|
|||
map['encryptedPath'],
|
||||
map['pathDecryptionNonce'],
|
||||
map['creationTime'],
|
||||
map['sharees'] == null ? null : List<String>.from(map['sharees']),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -97,7 +85,7 @@ class Collection {
|
|||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Collection(id: $id, ownerID: $ownerID, encryptedKey: $encryptedKey, keyDecryptionNonce: $keyDecryptionNonce, name: $name, type: $type, encryptedPath: $encryptedPath, pathDecryptionNonce: $pathDecryptionNonce, creationTime: $creationTime, sharees: $sharees)';
|
||||
return 'Collection(id: $id, ownerID: $ownerID, encryptedKey: $encryptedKey, keyDecryptionNonce: $keyDecryptionNonce, name: $name, type: $type, encryptedPath: $encryptedPath, pathDecryptionNonce: $pathDecryptionNonce, creationTime: $creationTime)';
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -113,8 +101,7 @@ class Collection {
|
|||
o.type == type &&
|
||||
o.encryptedPath == encryptedPath &&
|
||||
o.pathDecryptionNonce == pathDecryptionNonce &&
|
||||
o.creationTime == creationTime &&
|
||||
listEquals(o.sharees, sharees);
|
||||
o.creationTime == creationTime;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -127,8 +114,7 @@ class Collection {
|
|||
type.hashCode ^
|
||||
encryptedPath.hashCode ^
|
||||
pathDecryptionNonce.hashCode ^
|
||||
creationTime.hashCode ^
|
||||
sharees.hashCode;
|
||||
creationTime.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:photos/core/event_bus.dart';
|
|||
import 'package:photos/events/user_authenticated_event.dart';
|
||||
import 'package:photos/repositories/file_repository.dart';
|
||||
import 'package:photos/models/selected_files.dart';
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import 'package:photos/ui/email_entry_page.dart';
|
||||
import 'package:photos/ui/passphrase_entry_page.dart';
|
||||
import 'package:photos/ui/passphrase_reentry_page.dart';
|
||||
|
@ -142,7 +143,12 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ShareFolderWidget(widget.title, widget.path);
|
||||
return ShareFolderWidget(
|
||||
widget.title,
|
||||
widget.path,
|
||||
collection:
|
||||
CollectionsService.instance.getCollectionForPath(widget.path),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -16,10 +16,12 @@ 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,
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
|
@ -28,10 +30,15 @@ class ShareFolderWidget extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ShareFolderWidgetState extends State<ShareFolderWidget> {
|
||||
bool _showEntryField = false;
|
||||
String _email;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<Collection>(
|
||||
future: CollectionsService.instance.getFolder(widget.path),
|
||||
return FutureBuilder<List<String>>(
|
||||
future: widget.collection == null
|
||||
? List<String>()
|
||||
: CollectionsService.instance.getSharees(widget.collection.id),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return _getSharingDialog(snapshot.data);
|
||||
|
@ -44,46 +51,14 @@ class _ShareFolderWidgetState extends State<ShareFolderWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _getSharingDialog(Collection collection) {
|
||||
return AlertDialog(
|
||||
title: Text("Sharing"),
|
||||
content: SingleChildScrollView(
|
||||
child: ListBody(
|
||||
children: <Widget>[
|
||||
SharingWidget(collection),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SharingWidget extends StatefulWidget {
|
||||
final Collection collection;
|
||||
SharingWidget(this.collection, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SharingWidgetState createState() => _SharingWidgetState();
|
||||
}
|
||||
|
||||
class _SharingWidgetState extends State<SharingWidget> {
|
||||
bool _showEntryField = false;
|
||||
String _email;
|
||||
List<String> _emails;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_emails = widget.collection.sharees;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget _getSharingDialog(List<String> sharees) {
|
||||
log(sharees.toString());
|
||||
final children = List<Widget>();
|
||||
if (!_showEntryField && _emails.length == 0) {
|
||||
if (!_showEntryField &&
|
||||
(widget.collection == null || sharees.length == 0)) {
|
||||
children.add(Text("Click the + button to share this folder."));
|
||||
} else {
|
||||
for (final email in _emails) {
|
||||
for (final email in sharees) {
|
||||
children.add(EmailItemWidget(email));
|
||||
}
|
||||
}
|
||||
|
@ -133,11 +108,21 @@ class _SharingWidgetState extends State<SharingWidget> {
|
|||
),
|
||||
));
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: Column(
|
||||
children: children,
|
||||
));
|
||||
|
||||
return AlertDialog(
|
||||
title: Text("Sharing"),
|
||||
content: SingleChildScrollView(
|
||||
child: ListBody(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: Column(
|
||||
children: children,
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _addEmailToCollection(BuildContext context) async {
|
||||
|
@ -174,21 +159,18 @@ class _SharingWidgetState extends State<SharingWidget> {
|
|||
},
|
||||
);
|
||||
} else {
|
||||
_shareCollection(_email, publicKey);
|
||||
if (widget.collection == null) {
|
||||
log("Collection is null");
|
||||
// TODO: Create collection
|
||||
// TODO: Add files to collection
|
||||
}
|
||||
// TODO: Add email to collection
|
||||
setState(() {
|
||||
// sharees.add(email);
|
||||
_showEntryField = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _shareCollection(String email, String publicKey) {
|
||||
if (widget.collection.id == null) {
|
||||
// TODO: Create collection
|
||||
// TODO: Add files to collection
|
||||
}
|
||||
// TODO: Add email to collection
|
||||
setState(() {
|
||||
_emails.add(email);
|
||||
_showEntryField = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class EmailItemWidget extends StatelessWidget {
|
||||
|
@ -219,46 +201,3 @@ class EmailItemWidget extends StatelessWidget {
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
class SharingCheckboxWidget extends StatefulWidget {
|
||||
final Map<int, bool> sharingStatus;
|
||||
|
||||
const SharingCheckboxWidget(
|
||||
this.sharingStatus, {
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SharingCheckboxWidgetState createState() => _SharingCheckboxWidgetState();
|
||||
}
|
||||
|
||||
class _SharingCheckboxWidgetState extends State<SharingCheckboxWidget> {
|
||||
Map<int, bool> _sharingStatus;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_sharingStatus = widget.sharingStatus;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final checkboxes = List<Widget>();
|
||||
for (final user in _sharingStatus.keys) {
|
||||
checkboxes.add(Row(
|
||||
children: <Widget>[
|
||||
Checkbox(
|
||||
materialTapTargetSize: MaterialTapTargetSize.padded,
|
||||
value: _sharingStatus[user],
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_sharingStatus[user] = value;
|
||||
});
|
||||
}),
|
||||
Text(user.toString()),
|
||||
],
|
||||
));
|
||||
}
|
||||
return Column(children: checkboxes);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue