From bb57e82358c890e443a87957b8c04103994d0ff4 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Tue, 25 Oct 2022 23:08:56 +0200 Subject: [PATCH] specs,nextcloud,neon: Implement dark avatars --- .../neon/lib/src/widgets/account_avatar.dart | 20 +++++++--- .../nextcloud/lib/src/nextcloud.openapi.dart | 22 +++++++++++ .../nextcloud/lib/src/nextcloud.openapi.json | 39 +++++++++++++++++++ specs/core.json | 39 +++++++++++++++++++ 4 files changed, 115 insertions(+), 5 deletions(-) diff --git a/packages/neon/lib/src/widgets/account_avatar.dart b/packages/neon/lib/src/widgets/account_avatar.dart index 5afa3d52..52b10e22 100644 --- a/packages/neon/lib/src/widgets/account_avatar.dart +++ b/packages/neon/lib/src/widgets/account_avatar.dart @@ -12,6 +12,7 @@ class AccountAvatar extends StatelessWidget { @override Widget build(final BuildContext context) { + final isDark = Theme.of(context).brightness == Brightness.dark; final size = (kAvatarSize * MediaQuery.of(context).devicePixelRatio).toInt(); return Stack( alignment: Alignment.center, @@ -21,11 +22,20 @@ class AccountAvatar extends StatelessWidget { child: ClipOval( child: CachedAPIImage( account: account, - cacheKey: 'avatar-${account.id}-$size', - download: () async => account.client.core.getAvatar( - userId: account.username, - size: size, - ), + cacheKey: 'avatar-${account.id}-${isDark ? 'dark' : 'light'}$size', + download: () async { + if (isDark) { + return account.client.core.getDarkAvatar( + userId: account.username, + size: size, + ); + } else { + return account.client.core.getAvatar( + userId: account.username, + size: size, + ); + } + }, ), ), ), diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.dart b/packages/nextcloud/lib/src/nextcloud.openapi.dart index cbb2daf0..0cf74575 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.dart @@ -1606,6 +1606,28 @@ class CoreClient { throw ApiException.fromResponse(response); // coverage:ignore-line } + Future getDarkAvatar({ + required String userId, + required int size, + }) async { + var path = '/avatar/{userId}/{size}/dark'; + final queryParameters = {}; + final headers = {}; + Uint8List? body; + path = path.replaceAll('{userId}', Uri.encodeQueryComponent(userId.toString())); + path = path.replaceAll('{size}', Uri.encodeQueryComponent(size.toString())); + final response = await rootClient.doRequest( + 'get', + Uri(path: path, queryParameters: queryParameters).toString(), + headers, + body, + ); + if (response.statusCode == 200) { + return response.body; + } + throw ApiException.fromResponse(response); // coverage:ignore-line + } + Future getAvatar({ required String userId, required int size, diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.json b/packages/nextcloud/lib/src/nextcloud.openapi.json index b82dda4e..14170ed3 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.json +++ b/packages/nextcloud/lib/src/nextcloud.openapi.json @@ -2310,6 +2310,45 @@ } } }, + "/avatar/{userId}/{size}/dark": { + "parameters": [ + { + "name": "userId", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "size", + "in": "path", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "get": { + "operationId": "get-dark-avatar", + "tags": [ + "core" + ], + "responses": { + "200": { + "description": "", + "content": { + "image/png": { + "schema": { + "type": "string", + "format": "binary" + } + } + } + } + } + } + }, "/avatar/{userId}/{size}": { "parameters": [ { diff --git a/specs/core.json b/specs/core.json index 91178778..550f69c4 100644 --- a/specs/core.json +++ b/specs/core.json @@ -1260,6 +1260,45 @@ } } }, + "/avatar/{userId}/{size}/dark": { + "parameters": [ + { + "name": "userId", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "size", + "in": "path", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "get": { + "operationId": "get-dark-avatar", + "tags": [ + "core" + ], + "responses": { + "200": { + "description": "", + "content": { + "image/png": { + "schema": { + "type": "string", + "format": "binary" + } + } + } + } + } + } + }, "/avatar/{userId}/{size}": { "parameters": [ {