Indicate shared album

This commit is contained in:
Ming Ming 2021-08-13 18:45:26 +08:00
parent b9bf48c6ed
commit 64d7cc66b9
5 changed files with 41 additions and 10 deletions

View file

@ -4,16 +4,22 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file/data_source.dart';
import 'package:nc_photos/entity/share.dart';
import 'package:nc_photos/entity/share/data_source.dart';
import 'package:nc_photos/event/event.dart';
import 'package:nc_photos/exception.dart';
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
import 'package:nc_photos/string_extension.dart';
import 'package:nc_photos/throttler.dart';
import 'package:nc_photos/use_case/list_album.dart';
import 'package:tuple/tuple.dart';
class ListAlbumBlocItem {
ListAlbumBlocItem(this.album);
ListAlbumBlocItem(this.album, this.isSharedByMe, this.isSharedToMe);
final Album album;
final bool isSharedByMe;
final bool isSharedToMe;
}
abstract class ListAlbumBlocEvent {
@ -224,8 +230,14 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
}
}
final shareRepo = ShareRepo(ShareRemoteDataSource());
final shares = await shareRepo.listDir(ev.account,
File(path: remote_storage_util.getRemoteAlbumsDir(ev.account)));
final items = albums.map((e) {
return ListAlbumBlocItem(e);
final isSharedByMe = shares.any((element) =>
element.path.trimAny("/") == e.albumFile!.strippedPath);
final isSharedToMe = e.albumFile!.ownerId != ev.account.username;
return ListAlbumBlocItem(e, isSharedByMe, isSharedToMe);
}).toList();
if (errors.isEmpty) {

View file

@ -627,6 +627,10 @@
"@deletePermanentlyConfirmationDialogContent": {
"description": "Make sure the user wants to delete the items"
},
"albumSharedLabel": "Shared",
"@albumSharedLabel": {
"description": "A small label placed next to a shared album"
},
"changelogTitle": "Changelog",
"@changelogTitle": {

View file

@ -11,7 +11,12 @@
"restoreFailureNotification",
"deletePermanentlyTooltip",
"deletePermanentlyConfirmationDialogTitle",
"deletePermanentlyConfirmationDialogContent"
"deletePermanentlyConfirmationDialogContent",
"albumSharedLabel"
],
"es": [
"albumSharedLabel"
],
"fr": [
@ -26,6 +31,7 @@
"restoreFailureNotification",
"deletePermanentlyTooltip",
"deletePermanentlyConfirmationDialogTitle",
"deletePermanentlyConfirmationDialogContent"
"deletePermanentlyConfirmationDialogContent",
"albumSharedLabel"
]
}

View file

@ -16,6 +16,7 @@ class AlbumGridItemBuilder {
required this.account,
required this.album,
this.isSelected = false,
this.isShared = false,
this.onTap,
this.onLongPress,
});
@ -33,6 +34,9 @@ class AlbumGridItemBuilder {
subtitle2 = "+${provider.dirs.length - 1}";
}
}
if (isShared) {
subtitle = "${L10n.of(context).albumSharedLabel} | $subtitle";
}
return AlbumGridItem(
cover: _buildAlbumCover(context, album),
title: album.name,
@ -89,6 +93,7 @@ class AlbumGridItemBuilder {
final Account account;
final Album album;
final bool isSelected;
final bool isShared;
final VoidCallback? onTap;
final VoidCallback? onLongPress;
}

View file

@ -207,6 +207,7 @@ class _HomeAlbumsState extends State<HomeAlbums>
account: widget.account,
album: item.album,
isSelected: _selectedItems.contains(item),
isShared: item.isSharedByMe || item.isSharedToMe,
onTap: () => _onItemTap(item),
onLongPress: _isSelectionMode ? null : () => _onItemLongPress(item),
).build(context);
@ -382,19 +383,20 @@ class _HomeAlbumsState extends State<HomeAlbums>
/// Transform an Album list to grid items
void _transformItems(List<ListAlbumBlocItem> items) {
final sortedAlbums = items
.map((e) => e.album)
.map((e) => Tuple2(e.provider.latestItemTime ?? e.lastUpdated, e))
.map((e) =>
Tuple2(e.album.provider.latestItemTime ?? e.album.lastUpdated, e))
.sorted((a, b) {
// then sort in descending order
final tmp = b.item1.compareTo(a.item1);
if (tmp != 0) {
return tmp;
} else {
return a.item2.name.compareTo(b.item2.name);
return a.item2.album.name.compareTo(b.item2.album.name);
}
}).map((e) => e.item2);
_items.clear();
_items.addAll(sortedAlbums.map((e) => _GridItem(e)));
_items.addAll(sortedAlbums
.map((e) => _GridItem(e.album, e.isSharedByMe, e.isSharedToMe)));
_transformSelectedItems();
}
@ -445,9 +447,11 @@ class _HomeAlbumsState extends State<HomeAlbums>
}
class _GridItem {
_GridItem(this.album);
_GridItem(this.album, this.isSharedByMe, this.isSharedToMe);
Album album;
final Album album;
final bool isSharedByMe;
final bool isSharedToMe;
}
class _NonAlbumGridItem extends StatelessWidget {