mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-27 15:07:45 +00:00
feat(mobile): offer the same album sorting options on mobile as on web (#3804)
* Add translations for new album sort options * Support additional album sort options like on web * Update generated code * Fix lint --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
f3b17d8f73
commit
e57c926676
5 changed files with 59 additions and 1 deletions
|
|
@ -173,6 +173,8 @@
|
||||||
"library_page_sharing": "Sharing",
|
"library_page_sharing": "Sharing",
|
||||||
"library_page_sort_created": "Most recently created",
|
"library_page_sort_created": "Most recently created",
|
||||||
"library_page_sort_title": "Album title",
|
"library_page_sort_title": "Album title",
|
||||||
|
"library_page_sort_most_recent_photo": "Most recent photo",
|
||||||
|
"library_page_sort_last_modified": "Last modified",
|
||||||
"login_disabled": "Login has been disabled",
|
"login_disabled": "Login has been disabled",
|
||||||
"login_form_api_exception": "API exception. Please check the server URL and try again.",
|
"login_form_api_exception": "API exception. Please check the server URL and try again.",
|
||||||
"login_form_handshake_exception": "There was an Handshake Exception with the server. Enable self-signed certificate support in the settings if you are using a self-signed certificate.",
|
"login_form_handshake_exception": "There was an Handshake Exception with the server. Enable self-signed certificate support in the settings if you are using a self-signed certificate.",
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ class LibraryPage extends HookConsumerWidget {
|
||||||
useState(settings.getSetting(AppSettingsEnum.selectedAlbumSortOrder));
|
useState(settings.getSetting(AppSettingsEnum.selectedAlbumSortOrder));
|
||||||
|
|
||||||
List<Album> sortedAlbums() {
|
List<Album> sortedAlbums() {
|
||||||
|
// Created.
|
||||||
if (selectedAlbumSortOrder.value == 0) {
|
if (selectedAlbumSortOrder.value == 0) {
|
||||||
return albums
|
return albums
|
||||||
.where((a) => a.isRemote)
|
.where((a) => a.isRemote)
|
||||||
|
|
@ -54,6 +55,34 @@ class LibraryPage extends HookConsumerWidget {
|
||||||
.reversed
|
.reversed
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
// Album title.
|
||||||
|
if (selectedAlbumSortOrder.value == 1) {
|
||||||
|
return albums.where((a) => a.isRemote).sortedBy((album) => album.name);
|
||||||
|
}
|
||||||
|
// Most recent photo, if unset (e.g. empty album, use modifiedAt / updatedAt).
|
||||||
|
if (selectedAlbumSortOrder.value == 2) {
|
||||||
|
return albums
|
||||||
|
.where((a) => a.isRemote)
|
||||||
|
.sorted(
|
||||||
|
(a, b) => a.lastModifiedAssetTimestamp != null &&
|
||||||
|
b.lastModifiedAssetTimestamp != null
|
||||||
|
? a.lastModifiedAssetTimestamp!
|
||||||
|
.compareTo(b.lastModifiedAssetTimestamp!)
|
||||||
|
: a.modifiedAt.compareTo(b.modifiedAt),
|
||||||
|
)
|
||||||
|
.reversed
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
// Last modified.
|
||||||
|
if (selectedAlbumSortOrder.value == 3) {
|
||||||
|
return albums
|
||||||
|
.where((a) => a.isRemote)
|
||||||
|
.sortedBy((album) => album.modifiedAt)
|
||||||
|
.reversed
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: Album title.
|
||||||
return albums.where((a) => a.isRemote).sortedBy((album) => album.name);
|
return albums.where((a) => a.isRemote).sortedBy((album) => album.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,6 +90,8 @@ class LibraryPage extends HookConsumerWidget {
|
||||||
final options = [
|
final options = [
|
||||||
"library_page_sort_created".tr(),
|
"library_page_sort_created".tr(),
|
||||||
"library_page_sort_title".tr(),
|
"library_page_sort_title".tr(),
|
||||||
|
"library_page_sort_most_recent_photo".tr(),
|
||||||
|
"library_page_sort_last_modified".tr(),
|
||||||
];
|
];
|
||||||
|
|
||||||
return PopupMenuButton(
|
return PopupMenuButton(
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ class Album {
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.createdAt,
|
required this.createdAt,
|
||||||
required this.modifiedAt,
|
required this.modifiedAt,
|
||||||
|
this.lastModifiedAssetTimestamp,
|
||||||
required this.shared,
|
required this.shared,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -29,6 +30,7 @@ class Album {
|
||||||
String name;
|
String name;
|
||||||
DateTime createdAt;
|
DateTime createdAt;
|
||||||
DateTime modifiedAt;
|
DateTime modifiedAt;
|
||||||
|
DateTime? lastModifiedAssetTimestamp;
|
||||||
bool shared;
|
bool shared;
|
||||||
final IsarLink<User> owner = IsarLink<User>();
|
final IsarLink<User> owner = IsarLink<User>();
|
||||||
final IsarLink<Asset> thumbnail = IsarLink<Asset>();
|
final IsarLink<Asset> thumbnail = IsarLink<Asset>();
|
||||||
|
|
@ -83,12 +85,21 @@ class Album {
|
||||||
@override
|
@override
|
||||||
bool operator ==(other) {
|
bool operator ==(other) {
|
||||||
if (other is! Album) return false;
|
if (other is! Album) return false;
|
||||||
|
|
||||||
|
final lastModifiedAssetTimestampIsSetAndEqual =
|
||||||
|
lastModifiedAssetTimestamp != null &&
|
||||||
|
other.lastModifiedAssetTimestamp != null
|
||||||
|
? lastModifiedAssetTimestamp!
|
||||||
|
.isAtSameMomentAs(other.lastModifiedAssetTimestamp!)
|
||||||
|
: true;
|
||||||
|
|
||||||
return id == other.id &&
|
return id == other.id &&
|
||||||
remoteId == other.remoteId &&
|
remoteId == other.remoteId &&
|
||||||
localId == other.localId &&
|
localId == other.localId &&
|
||||||
name == other.name &&
|
name == other.name &&
|
||||||
createdAt.isAtSameMomentAs(other.createdAt) &&
|
createdAt.isAtSameMomentAs(other.createdAt) &&
|
||||||
modifiedAt.isAtSameMomentAs(other.modifiedAt) &&
|
modifiedAt.isAtSameMomentAs(other.modifiedAt) &&
|
||||||
|
lastModifiedAssetTimestampIsSetAndEqual &&
|
||||||
shared == other.shared &&
|
shared == other.shared &&
|
||||||
owner.value == other.owner.value &&
|
owner.value == other.owner.value &&
|
||||||
thumbnail.value == other.thumbnail.value &&
|
thumbnail.value == other.thumbnail.value &&
|
||||||
|
|
@ -105,6 +116,7 @@ class Album {
|
||||||
name.hashCode ^
|
name.hashCode ^
|
||||||
createdAt.hashCode ^
|
createdAt.hashCode ^
|
||||||
modifiedAt.hashCode ^
|
modifiedAt.hashCode ^
|
||||||
|
lastModifiedAssetTimestamp.hashCode ^
|
||||||
shared.hashCode ^
|
shared.hashCode ^
|
||||||
owner.value.hashCode ^
|
owner.value.hashCode ^
|
||||||
thumbnail.value.hashCode ^
|
thumbnail.value.hashCode ^
|
||||||
|
|
@ -130,6 +142,7 @@ class Album {
|
||||||
name: dto.albumName,
|
name: dto.albumName,
|
||||||
createdAt: dto.createdAt,
|
createdAt: dto.createdAt,
|
||||||
modifiedAt: dto.updatedAt,
|
modifiedAt: dto.updatedAt,
|
||||||
|
lastModifiedAssetTimestamp: dto.lastModifiedAssetTimestamp,
|
||||||
shared: dto.shared,
|
shared: dto.shared,
|
||||||
);
|
);
|
||||||
a.owner.value = await db.users.getById(dto.ownerId);
|
a.owner.value = await db.users.getById(dto.ownerId);
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -282,6 +282,9 @@ class SyncService {
|
||||||
if (!_hasAlbumResponseDtoChanged(dto, album)) {
|
if (!_hasAlbumResponseDtoChanged(dto, album)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// loadDetails (/api/album/:id) will not include lastModifiedAssetTimestamp,
|
||||||
|
// i.e. it will always be null. Save it here.
|
||||||
|
final originalDto = dto;
|
||||||
dto = await loadDetails(dto);
|
dto = await loadDetails(dto);
|
||||||
if (dto.assetCount != dto.assets.length) {
|
if (dto.assetCount != dto.assets.length) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -321,6 +324,7 @@ class SyncService {
|
||||||
album.name = dto.albumName;
|
album.name = dto.albumName;
|
||||||
album.shared = dto.shared;
|
album.shared = dto.shared;
|
||||||
album.modifiedAt = dto.updatedAt;
|
album.modifiedAt = dto.updatedAt;
|
||||||
|
album.lastModifiedAssetTimestamp = originalDto.lastModifiedAssetTimestamp;
|
||||||
if (album.thumbnail.value?.remoteId != dto.albumThumbnailAssetId) {
|
if (album.thumbnail.value?.remoteId != dto.albumThumbnailAssetId) {
|
||||||
album.thumbnail.value = await _db.assets
|
album.thumbnail.value = await _db.assets
|
||||||
.where()
|
.where()
|
||||||
|
|
@ -808,5 +812,13 @@ bool _hasAlbumResponseDtoChanged(AlbumResponseDto dto, Album a) {
|
||||||
dto.albumThumbnailAssetId != a.thumbnail.value?.remoteId ||
|
dto.albumThumbnailAssetId != a.thumbnail.value?.remoteId ||
|
||||||
dto.shared != a.shared ||
|
dto.shared != a.shared ||
|
||||||
dto.sharedUsers.length != a.sharedUsers.length ||
|
dto.sharedUsers.length != a.sharedUsers.length ||
|
||||||
!dto.updatedAt.isAtSameMomentAs(a.modifiedAt);
|
!dto.updatedAt.isAtSameMomentAs(a.modifiedAt) ||
|
||||||
|
(dto.lastModifiedAssetTimestamp == null &&
|
||||||
|
a.lastModifiedAssetTimestamp != null) ||
|
||||||
|
(dto.lastModifiedAssetTimestamp != null &&
|
||||||
|
a.lastModifiedAssetTimestamp == null) ||
|
||||||
|
(dto.lastModifiedAssetTimestamp != null &&
|
||||||
|
a.lastModifiedAssetTimestamp != null &&
|
||||||
|
!dto.lastModifiedAssetTimestamp!
|
||||||
|
.isAtSameMomentAs(a.lastModifiedAssetTimestamp!));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue