Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mobile): thumbhash support #7028

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion mobile/lib/shared/models/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class Asset {
isReadOnly = remote.isReadOnly,
isOffline = remote.isOffline,
stackParentId = remote.stackParentId,
stackCount = remote.stackCount;
stackCount = remote.stackCount,
thumbhash = _decodeThumbhash(remote.thumbhash);

Asset.local(AssetEntity local, List<int> hash)
: localId = local.id,
Expand Down Expand Up @@ -88,6 +89,7 @@ class Asset {
this.stackCount = 0,
this.isReadOnly = false,
this.isOffline = false,
this.thumbhash,
});

@ignore
Expand Down Expand Up @@ -116,6 +118,8 @@ class Asset {
/// because Isar cannot sort lists of byte arrays
String checksum;

List<byte>? thumbhash;

@Index(unique: false, replace: false, type: IndexType.hash)
String? remoteId;

Expand Down Expand Up @@ -271,6 +275,7 @@ class Asset {
a.exifInfo?.latitude != exifInfo?.latitude ||
a.exifInfo?.longitude != exifInfo?.longitude ||
// no local stack count or different count from remote
a.thumbhash != thumbhash ||
((stackCount == null && a.stackCount != null) ||
(stackCount != null &&
a.stackCount != null &&
Expand Down Expand Up @@ -332,6 +337,7 @@ class Asset {
isReadOnly: a.isReadOnly,
isOffline: a.isOffline,
exifInfo: a.exifInfo?.copyWith(id: id) ?? exifInfo,
thumbhash: a.thumbhash,
);
} else {
// add only missing values (and set isLocal to true)
Expand Down Expand Up @@ -368,6 +374,7 @@ class Asset {
ExifInfo? exifInfo,
String? stackParentId,
int? stackCount,
List<byte>? thumbhash,
}) =>
Asset(
id: id ?? this.id,
Expand All @@ -392,6 +399,7 @@ class Asset {
exifInfo: exifInfo ?? this.exifInfo,
stackParentId: stackParentId ?? this.stackParentId,
stackCount: stackCount ?? this.stackCount,
thumbhash: thumbhash ?? this.thumbhash,
);

Future<void> put(Isar db) async {
Expand Down Expand Up @@ -504,3 +512,10 @@ extension AssetsHelper on IsarCollection<Asset> {
return where().anyOf(ids, (q, String e) => q.localIdEqualTo(e));
}
}

List<byte>? _decodeThumbhash(String? hash) {
if (hash == null) {
return null;
}
return base64.decode(base64.normalize(hash)).toList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base64.decode already returns an Uint8List. No need to call toList() which makes it less efficient.

also, I don't think normalize is needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this in to my branch and address this and the other comment there.

}
202 changes: 191 additions & 11 deletions mobile/lib/shared/models/asset.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading