mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-09 02:36:31 +01:00
Indicate shared album
This commit is contained in:
parent
b9bf48c6ed
commit
64d7cc66b9
5 changed files with 41 additions and 10 deletions
|
@ -4,16 +4,22 @@ import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/entity/album.dart';
|
import 'package:nc_photos/entity/album.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/entity/file/data_source.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/event/event.dart';
|
||||||
import 'package:nc_photos/exception.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/throttler.dart';
|
||||||
import 'package:nc_photos/use_case/list_album.dart';
|
import 'package:nc_photos/use_case/list_album.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
class ListAlbumBlocItem {
|
class ListAlbumBlocItem {
|
||||||
ListAlbumBlocItem(this.album);
|
ListAlbumBlocItem(this.album, this.isSharedByMe, this.isSharedToMe);
|
||||||
|
|
||||||
final Album album;
|
final Album album;
|
||||||
|
final bool isSharedByMe;
|
||||||
|
final bool isSharedToMe;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ListAlbumBlocEvent {
|
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) {
|
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();
|
}).toList();
|
||||||
|
|
||||||
if (errors.isEmpty) {
|
if (errors.isEmpty) {
|
||||||
|
|
|
@ -627,6 +627,10 @@
|
||||||
"@deletePermanentlyConfirmationDialogContent": {
|
"@deletePermanentlyConfirmationDialogContent": {
|
||||||
"description": "Make sure the user wants to delete the items"
|
"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": "Changelog",
|
||||||
"@changelogTitle": {
|
"@changelogTitle": {
|
||||||
|
|
|
@ -11,7 +11,12 @@
|
||||||
"restoreFailureNotification",
|
"restoreFailureNotification",
|
||||||
"deletePermanentlyTooltip",
|
"deletePermanentlyTooltip",
|
||||||
"deletePermanentlyConfirmationDialogTitle",
|
"deletePermanentlyConfirmationDialogTitle",
|
||||||
"deletePermanentlyConfirmationDialogContent"
|
"deletePermanentlyConfirmationDialogContent",
|
||||||
|
"albumSharedLabel"
|
||||||
|
],
|
||||||
|
|
||||||
|
"es": [
|
||||||
|
"albumSharedLabel"
|
||||||
],
|
],
|
||||||
|
|
||||||
"fr": [
|
"fr": [
|
||||||
|
@ -26,6 +31,7 @@
|
||||||
"restoreFailureNotification",
|
"restoreFailureNotification",
|
||||||
"deletePermanentlyTooltip",
|
"deletePermanentlyTooltip",
|
||||||
"deletePermanentlyConfirmationDialogTitle",
|
"deletePermanentlyConfirmationDialogTitle",
|
||||||
"deletePermanentlyConfirmationDialogContent"
|
"deletePermanentlyConfirmationDialogContent",
|
||||||
|
"albumSharedLabel"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ class AlbumGridItemBuilder {
|
||||||
required this.account,
|
required this.account,
|
||||||
required this.album,
|
required this.album,
|
||||||
this.isSelected = false,
|
this.isSelected = false,
|
||||||
|
this.isShared = false,
|
||||||
this.onTap,
|
this.onTap,
|
||||||
this.onLongPress,
|
this.onLongPress,
|
||||||
});
|
});
|
||||||
|
@ -33,6 +34,9 @@ class AlbumGridItemBuilder {
|
||||||
subtitle2 = "+${provider.dirs.length - 1}";
|
subtitle2 = "+${provider.dirs.length - 1}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isShared) {
|
||||||
|
subtitle = "${L10n.of(context).albumSharedLabel} | $subtitle";
|
||||||
|
}
|
||||||
return AlbumGridItem(
|
return AlbumGridItem(
|
||||||
cover: _buildAlbumCover(context, album),
|
cover: _buildAlbumCover(context, album),
|
||||||
title: album.name,
|
title: album.name,
|
||||||
|
@ -89,6 +93,7 @@ class AlbumGridItemBuilder {
|
||||||
final Account account;
|
final Account account;
|
||||||
final Album album;
|
final Album album;
|
||||||
final bool isSelected;
|
final bool isSelected;
|
||||||
|
final bool isShared;
|
||||||
final VoidCallback? onTap;
|
final VoidCallback? onTap;
|
||||||
final VoidCallback? onLongPress;
|
final VoidCallback? onLongPress;
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,6 +207,7 @@ class _HomeAlbumsState extends State<HomeAlbums>
|
||||||
account: widget.account,
|
account: widget.account,
|
||||||
album: item.album,
|
album: item.album,
|
||||||
isSelected: _selectedItems.contains(item),
|
isSelected: _selectedItems.contains(item),
|
||||||
|
isShared: item.isSharedByMe || item.isSharedToMe,
|
||||||
onTap: () => _onItemTap(item),
|
onTap: () => _onItemTap(item),
|
||||||
onLongPress: _isSelectionMode ? null : () => _onItemLongPress(item),
|
onLongPress: _isSelectionMode ? null : () => _onItemLongPress(item),
|
||||||
).build(context);
|
).build(context);
|
||||||
|
@ -382,19 +383,20 @@ class _HomeAlbumsState extends State<HomeAlbums>
|
||||||
/// Transform an Album list to grid items
|
/// Transform an Album list to grid items
|
||||||
void _transformItems(List<ListAlbumBlocItem> items) {
|
void _transformItems(List<ListAlbumBlocItem> items) {
|
||||||
final sortedAlbums = items
|
final sortedAlbums = items
|
||||||
.map((e) => e.album)
|
.map((e) =>
|
||||||
.map((e) => Tuple2(e.provider.latestItemTime ?? e.lastUpdated, e))
|
Tuple2(e.album.provider.latestItemTime ?? e.album.lastUpdated, e))
|
||||||
.sorted((a, b) {
|
.sorted((a, b) {
|
||||||
// then sort in descending order
|
// then sort in descending order
|
||||||
final tmp = b.item1.compareTo(a.item1);
|
final tmp = b.item1.compareTo(a.item1);
|
||||||
if (tmp != 0) {
|
if (tmp != 0) {
|
||||||
return tmp;
|
return tmp;
|
||||||
} else {
|
} else {
|
||||||
return a.item2.name.compareTo(b.item2.name);
|
return a.item2.album.name.compareTo(b.item2.album.name);
|
||||||
}
|
}
|
||||||
}).map((e) => e.item2);
|
}).map((e) => e.item2);
|
||||||
_items.clear();
|
_items.clear();
|
||||||
_items.addAll(sortedAlbums.map((e) => _GridItem(e)));
|
_items.addAll(sortedAlbums
|
||||||
|
.map((e) => _GridItem(e.album, e.isSharedByMe, e.isSharedToMe)));
|
||||||
|
|
||||||
_transformSelectedItems();
|
_transformSelectedItems();
|
||||||
}
|
}
|
||||||
|
@ -445,9 +447,11 @@ class _HomeAlbumsState extends State<HomeAlbums>
|
||||||
}
|
}
|
||||||
|
|
||||||
class _GridItem {
|
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 {
|
class _NonAlbumGridItem extends StatelessWidget {
|
||||||
|
|
Loading…
Reference in a new issue