fix(mobile): handle readonly and offline assets (#5565)

* feat: add isReadOnly and isOffline fields to Asset collection

* refactor: move asset iterable filters to extension

* hide asset actions based on offline and readOnly fields

* pr changes

* chore: doc comments

---------

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
shenlong 2024-01-06 03:02:16 +00:00 committed by GitHub
parent 56cde0438c
commit a233e176e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 333 additions and 105 deletions

View file

@ -32,6 +32,8 @@ class Asset {
isFavorite = remote.isFavorite,
isArchived = remote.isArchived,
isTrashed = remote.isTrashed,
isReadOnly = remote.isReadOnly,
isOffline = remote.isOffline,
stackParentId = remote.stackParentId,
stackCount = remote.stackCount;
@ -49,6 +51,8 @@ class Asset {
isFavorite = local.isFavorite,
isArchived = false,
isTrashed = false,
isReadOnly = false,
isOffline = false,
stackCount = 0,
fileCreatedAt = local.createDateTime {
if (fileCreatedAt.year == 1970) {
@ -77,11 +81,13 @@ class Asset {
required this.fileName,
this.livePhotoVideoId,
this.exifInfo,
required this.isFavorite,
required this.isArchived,
required this.isTrashed,
this.isFavorite = false,
this.isArchived = false,
this.isTrashed = false,
this.stackParentId,
required this.stackCount,
this.stackCount = 0,
this.isReadOnly = false,
this.isOffline = false,
});
@ignore
@ -148,6 +154,10 @@ class Asset {
bool isTrashed;
bool isReadOnly;
bool isOffline;
@ignore
ExifInfo? exifInfo;
@ -256,6 +266,8 @@ class Asset {
isFavorite != a.isFavorite ||
isArchived != a.isArchived ||
isTrashed != a.isTrashed ||
isReadOnly != a.isReadOnly ||
isOffline != a.isOffline ||
a.exifInfo?.latitude != exifInfo?.latitude ||
a.exifInfo?.longitude != exifInfo?.longitude ||
// no local stack count or different count from remote
@ -288,6 +300,7 @@ class Asset {
exifInfo: exifInfo ?? a.exifInfo?.copyWith(id: id),
);
} else {
// TODO: Revisit this and remove all bool field assignments
return a._copyWith(
id: id,
remoteId: remoteId,
@ -297,6 +310,8 @@ class Asset {
isFavorite: isFavorite,
isArchived: isArchived,
isTrashed: isTrashed,
isReadOnly: isReadOnly,
isOffline: isOffline,
);
}
} else {
@ -314,6 +329,8 @@ class Asset {
isFavorite: a.isFavorite,
isArchived: a.isArchived,
isTrashed: a.isTrashed,
isReadOnly: a.isReadOnly,
isOffline: a.isOffline,
exifInfo: a.exifInfo?.copyWith(id: id) ?? exifInfo,
);
} else {
@ -346,6 +363,8 @@ class Asset {
bool? isFavorite,
bool? isArchived,
bool? isTrashed,
bool? isReadOnly,
bool? isOffline,
ExifInfo? exifInfo,
String? stackParentId,
int? stackCount,
@ -368,6 +387,8 @@ class Asset {
isFavorite: isFavorite ?? this.isFavorite,
isArchived: isArchived ?? this.isArchived,
isTrashed: isTrashed ?? this.isTrashed,
isReadOnly: isReadOnly ?? this.isReadOnly,
isOffline: isOffline ?? this.isOffline,
exifInfo: exifInfo ?? this.exifInfo,
stackParentId: stackParentId ?? this.stackParentId,
stackCount: stackCount ?? this.stackCount,
@ -426,7 +447,9 @@ class Asset {
"width": ${width ?? "N/A"},
"height": ${height ?? "N/A"},
"isArchived": $isArchived,
"isTrashed": $isTrashed
"isTrashed": $isTrashed,
"isReadOnly": $isReadOnly,
"isOffline": $isOffline,
}""";
}
}