Render action bar conditionally for collaborators
This commit is contained in:
parent
e0f6db707c
commit
044878e336
|
@ -9,11 +9,14 @@ class ActionBarWidget extends StatefulWidget {
|
|||
final List<Widget> iconButtons;
|
||||
final SelectedFiles? selectedFiles;
|
||||
final GalleryType galleryType;
|
||||
final bool isCollaborator;
|
||||
|
||||
const ActionBarWidget({
|
||||
required this.iconButtons,
|
||||
required this.galleryType,
|
||||
this.text,
|
||||
this.selectedFiles,
|
||||
this.isCollaborator = false,
|
||||
super.key,
|
||||
});
|
||||
|
||||
|
@ -74,13 +77,21 @@ class _ActionBarWidgetState extends State<ActionBarWidget> {
|
|||
? ValueListenableBuilder(
|
||||
valueListenable: _selectedFilesNotifier,
|
||||
builder: (context, value, child) {
|
||||
if (widget.isCollaborator) {
|
||||
return Text(
|
||||
"${_selectedFilesNotifier.value} selected" +
|
||||
(_selectedOwnedFilesNotifier.value !=
|
||||
_selectedFilesNotifier.value
|
||||
? " (${_selectedOwnedFilesNotifier.value} "
|
||||
"yours) "
|
||||
: ""),
|
||||
style: textTheme.body.copyWith(
|
||||
color: colorScheme.blurTextBase,
|
||||
),
|
||||
);
|
||||
}
|
||||
return Text(
|
||||
"${_selectedFilesNotifier.value} selected" +
|
||||
(_selectedOwnedFilesNotifier.value !=
|
||||
_selectedFilesNotifier.value
|
||||
? " (${_selectedOwnedFilesNotifier.value} "
|
||||
"yours) "
|
||||
: ""),
|
||||
"${_selectedFilesNotifier.value} selected",
|
||||
style: textTheme.body.copyWith(
|
||||
color: colorScheme.blurTextBase,
|
||||
),
|
||||
|
|
|
@ -18,6 +18,7 @@ class BottomActionBarWidget extends StatelessWidget {
|
|||
final VoidCallback? onCancel;
|
||||
final bool hasSmallerBottomPadding;
|
||||
final GalleryType type;
|
||||
final bool isCollaborator;
|
||||
|
||||
BottomActionBarWidget({
|
||||
required this.expandedMenu,
|
||||
|
@ -27,6 +28,7 @@ class BottomActionBarWidget extends StatelessWidget {
|
|||
this.text,
|
||||
this.iconButtons,
|
||||
this.onCancel,
|
||||
this.isCollaborator = false,
|
||||
super.key,
|
||||
});
|
||||
|
||||
|
@ -68,6 +70,7 @@ class BottomActionBarWidget extends StatelessWidget {
|
|||
galleryType: type,
|
||||
text: text,
|
||||
iconButtons: _iconButtons(context),
|
||||
isCollaborator: isCollaborator,
|
||||
),
|
||||
),
|
||||
expanded: expandedMenu,
|
||||
|
|
|
@ -24,6 +24,7 @@ class FileSelectionActionWidget extends StatefulWidget {
|
|||
final Collection? collection;
|
||||
final DeviceCollection? deviceCollection;
|
||||
final SelectedFiles selectedFiles;
|
||||
final bool isCollaborator;
|
||||
|
||||
const FileSelectionActionWidget(
|
||||
this.type,
|
||||
|
@ -31,6 +32,7 @@ class FileSelectionActionWidget extends StatefulWidget {
|
|||
Key? key,
|
||||
this.collection,
|
||||
this.deviceCollection,
|
||||
this.isCollaborator = false,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
|
@ -98,7 +100,7 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
if (widget.type.showRemoveFromAlbum()) {
|
||||
if (widget.isCollaborator && widget.type.showRemoveFromAlbum()) {
|
||||
firstList.add(
|
||||
BlurMenuItemWidget(
|
||||
leadingIcon: Icons.remove_outlined,
|
||||
|
@ -183,10 +185,13 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
|
|||
|
||||
if (firstList.isNotEmpty) {
|
||||
items.add(firstList);
|
||||
return ExpandedMenuWidget(
|
||||
items: items,
|
||||
);
|
||||
} else {
|
||||
// TODO: Return "Select All" here
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return ExpandedMenuWidget(
|
||||
items: items,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _moveFiles() async {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/core/configuration.dart';
|
||||
import 'package:photos/models/collection.dart';
|
||||
import 'package:photos/models/device_collection.dart';
|
||||
import 'package:photos/models/gallery_type.dart';
|
||||
|
@ -65,6 +66,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
|
|||
selectedFiles: widget.selectedFiles,
|
||||
hasSmallerBottomPadding: true,
|
||||
type: widget.galleryType,
|
||||
isCollaborator: _isCollaborator(),
|
||||
expandedMenu: FileSelectionActionWidget(
|
||||
widget.galleryType,
|
||||
widget.selectedFiles,
|
||||
|
@ -106,4 +108,20 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
|
|||
? _bottomPosition.value = 0.0
|
||||
: _bottomPosition.value = -150.0;
|
||||
}
|
||||
|
||||
bool _isCollaborator() {
|
||||
if (widget.collection == null) {
|
||||
return false;
|
||||
}
|
||||
if (widget.galleryType == GalleryType.ownedCollection) {
|
||||
return false;
|
||||
}
|
||||
final userID = Configuration.instance.getUserID();
|
||||
for (final user in widget.collection!.getSharees()) {
|
||||
if (user.id == userID) {
|
||||
return user.isCollaborator;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue