Skip to content

Commit e0c0d14

Browse files
Update usage-quickeditor.md (#649)
* Update the usage-quickeditor.md docs * Add section for the new scope options * Add images * UpdateHandler section
1 parent cca80b2 commit e0c0d14

File tree

6 files changed

+154
-14
lines changed

6 files changed

+154
-14
lines changed

docs/get-started/usage-quickeditor.md

Lines changed: 154 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
# Quick Editor Module usage
22

3-
The `:gravatar-quickeditor` module provides a fully featured component that allows the user to modify their avatar without leaving your app.
3+
## Table of Contents
4+
* [Overview](#overview)
5+
* [Authentication](#authentication)
6+
* [1. Let the Quick Editor handle the OAuth flow](#1-let-the-quick-editor-handle-the-oauth-flow)
7+
* [2. Obtain the token yourself and provide it to the Quick Editor](#2-obtain-the-token-yourself-and-provide-it-to-the-quick-editor)
8+
* [Quick Editor Scopes](#quick-editor-scopes)
9+
* [Update Handler](#update-handler)
10+
* [Activity/Fragment compatibility](#activityfragment-compatibility)
11+
* [Cache busting](#cache-busting)
12+
* [Android Permissions](#android-permissions)
13+
* [Version migrations](#version-migrations)
414

5-
To do that the QuickEditor needs an authorization token to perform requests on behalf of the user. There are two ways for that:
15+
## Overview
16+
17+
The `:gravatar-quickeditor` module provides a fully featured component that allows the user to modify their Gravatar profile information, including their avatar and "About" details, without leaving your app.
18+
19+
The Quick Editor's functionality can be tailored using `QuickEditorScopeOption` to define what the user can edit. This allows for a focused experience depending on the desired interaction:
20+
* **`QuickEditorScopeOption.avatarPicker()`**: Launches the Quick Editor focused solely on avatar management. Users can select an existing image, upload a new one, or remove their current Gravatar through a streamlined interface. This scope is ideal when you only need to offer avatar editing capabilities.
21+
* **`QuickEditorScopeOption.aboutEditor()`**: This option presents the Quick Editor with tools to modify the user's "About" profile section. This typically includes details such as their display name, full name, pronouns, a public description or bio, and current location.
22+
* **`QuickEditorScopeOption.avatarPickerAndAboutEditor()`**: For a comprehensive profile editing experience, this combined scope allows users to modify both their avatar and their "About Me" details. The Quick Editor will provide a way to navigate between the avatar editing and "About" sections seamlessly without needing to close and re-launch the component.
23+
24+
For all of this to be possible, the QuickEditor needs an authorization token to perform requests on behalf of the user.
25+
26+
## Authentication
627

728
### 1. Let the Quick Editor handle the OAuth flow
829

@@ -46,15 +67,15 @@ if (showBottomSheet) {
4667
GravatarQuickEditorBottomSheet(
4768
gravatarQuickEditorParams = GravatarQuickEditorParams {
4869
email = Email("{USER_EMAIL}")
49-
avatarPickerContentLayout = AvatarPickerContentLayout.Horizontal
70+
scopeOption = QuickEditorScopeOption.avatarPicker()
5071
},
5172
authenticationMethod = AuthenticationMethod.OAuth(
5273
OAuthParams {
5374
clientId = "{YOUR_CLIENT_ID}"
5475
redirectUri = "{YOUR_REDIRECT_URL}" // In our example this would be https://yourhost.com/redirect_url
5576
},
5677
),
57-
onAvatarSelected = { ... },
78+
updateHandler = { updateType -> ... },
5879
onDismiss = { gravatarQuickEditorDismissReason ->
5980
showBottomSheet = false
6081
...
@@ -143,10 +164,10 @@ if (showBottomSheet) {
143164
GravatarQuickEditorBottomSheet(
144165
gravatarQuickEditorParams = GravatarQuickEditorParams {
145166
email = Email("{USER_EMAIL}")
146-
avatarPickerContentLayout = AvatarPickerContentLayout.Horizontal
167+
scopeOption = QuickEditorScopeOption.avatarPicker()
147168
},
148169
authenticationMethod = AuthenticationMethod.Bearer("{TOKEN}"),
149-
onAvatarSelected = { ... },
170+
updateHandler = { updateType -> ... },
150171
onDismiss = { gravatarQuickEditorDismissReason ->
151172
showBottomSheet = false
152173
...
@@ -155,9 +176,128 @@ if (showBottomSheet) {
155176
}
156177
```
157178

158-
### Activity/Fragment compatibility
179+
## Quick Editor Scopes
180+
181+
Quick Editor scopes were already briefly described in the Overview section, but here is a more detailed explanation of each scope option:
182+
183+
### `QuickEditorScopeOption.avatarPicker()`
184+
185+
This scope option focuses solely on avatar management. When using this option, the Quick Editor will present a user interface that allows users to:
186+
- Select an avatar from the uploaded images.
187+
- Upload an existing image from their device or take a new one.
188+
- Remove their current Gravatar avatar.
189+
- Modify the Alt Text for the avatar.
190+
- Modify the rating of the avatar.
191+
- Download any of the already uploaded avatars.
192+
193+
**AvatarPicker** scope is configured via `AvatarPickerConfiguration` class. Currently it supports one parameter: `AvatarPickerContentLayout` that defines how the user's avatar will be displayed. It can be either `Horizontal` or `Vertical`. The default value is `Horizontal`.
194+
195+
Here's an example of how to configure the `AvatarPicker` scope:
196+
197+
```kotlin
198+
GravatarQuickEditorBottomSheet(
199+
gravatarQuickEditorParams = GravatarQuickEditorParams {
200+
...
201+
scopeOption = QuickEditorScopeOption.avatarPicker(
202+
config = AvatarPickerConfiguration(
203+
contentLayout = AvatarPickerContentLayout.Vertical,
204+
),
205+
)
206+
},
207+
...
208+
)
209+
```
210+
211+
| Horizontal | Vertical |
212+
|------------------------------------------------|----------------------------------------------|
213+
| ![](/docs/images/avatar_picker_horizontal.png) | ![](/docs/images/avatar_picker_vertical.png) |
214+
215+
### `QuickEditorScopeOption.aboutEditor()`
216+
217+
This scope option allows users to edit their "About" section in Gravatar. To check the currently supported fields, refer to the [AboutInputField](https://github.com/Automattic/Gravatar-SDK-Android/blob/adam/GRA-128/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/AboutInputField.kt) class.
218+
219+
In order to configure the `AboutEditor` scope, you can use the `AboutEditorConfiguration` class. This class allows you to specify which fields should be editable by the user.
220+
221+
Here's an example of how to configure the `AboutEditor` scope:
222+
223+
```kotlin
224+
GravatarQuickEditorBottomSheet(
225+
gravatarQuickEditorParams = GravatarQuickEditorParams {
226+
...
227+
scopeOption = QuickEditorScopeOption.aboutEditor(
228+
config = AboutEditorConfiguration(
229+
fields = setOf(
230+
AboutInputField.DisplayName,
231+
AboutInputField.AboutMe,
232+
),
233+
),
234+
)
235+
},
236+
...
237+
)
238+
```
239+
240+
| All fields | Only two selected |
241+
|-----------------------------------------------|-----------------------------------------------|
242+
| ![](/docs/images/about_editor_all_fields.png) | ![](/docs/images/about_editor_two_fields.png) |
243+
244+
### `QuickEditorScopeOption.avatarPickerAndAboutEditor()`
245+
246+
This scope option combines both the avatar management and "About" section editing functionalities. It allows users to seamlessly switch between editing their avatar and updating their profile information without needing to close and reopen the Quick Editor.
247+
248+
To configure the `AvatarPickerAndAboutEditor` scope, you can use the `AvatarPickerAndAboutEditorConfiguration` class. It takes all the parameters from both `AvatarPickerConfiguration` and `AboutEditorConfiguration`, allowing you to define how the avatar picker and the "About" editor should behave.
249+
On top of that it allows you to define the initial page that will be displayed when the Quick Editor is launched. The initial page can be either `AvatarPicker` or `AboutEditor`.
250+
251+
Here's an example of how to configure the `AvatarPickerAndAboutEditor` scope:
252+
253+
```kotlin
254+
GravatarQuickEditorBottomSheet(
255+
gravatarQuickEditorParams = GravatarQuickEditorParams {
256+
...
257+
scopeOption = QuickEditorScopeOption.avatarPickerAndAboutEditor(
258+
config = AvatarPickerAndAboutEditorConfiguration(
259+
contentLayout = AvatarPickerContentLayout.Vertical,
260+
fields = AboutInputField.all,
261+
initialPage = AvatarPickerAndAboutEditorConfiguration.Page.AvatarPicker,
262+
),
263+
)
264+
},
265+
...
266+
)
267+
```
268+
269+
| Avatar Picker and About Editor |
270+
|----------------------------------------|
271+
| ![](/docs/images/avatar_and_about.gif) |
272+
273+
274+
### Update Handler
275+
276+
When using the Quick Editor, you need to provide an `updateHandler` that will be called when the user makes changes to their profile. This allows you to handle updates in your app, such as refreshing the UI or saving changes to a local database.
277+
278+
Each invocation of the `updateHandler` will provide a [QuickEditorUpdateType](https://github.com/Automattic/Gravatar-SDK-Android/blob/trunk/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/UpdateHandler.kt) that indicates what type of update was made. It can be either `AvatarPickerResult` or `AboutEditorResult`, depending on whether the user changed their avatar or their "About" section.
279+
280+
Here's an example of how to implement the `updateHandler`:
281+
282+
```kotlin
283+
GravatarQuickEditorBottomSheet(
284+
...
285+
updateHandler = { updateType ->
286+
when (updateType) {
287+
is AvatarPickerResult -> {
288+
// Handle avatar update
289+
}
290+
is AboutEditorResult -> {
291+
// Handle about section update
292+
}
293+
}
294+
},
295+
)
296+
```
297+
298+
## Activity/Fragment compatibility
159299

160-
Gravatar SDK is built with Compose but we do provide some helper functions to launch the Quick Editor from an Activity or Fragment. Here's an example an Activity:
300+
Gravatar SDK is built with Compose but we do provide some helper functions to launch the Quick Editor from an Activity or Fragment. Here's an example from an Activity:
161301

162302
```kotlin
163303
GravatarQuickEditor.show(
@@ -172,13 +312,13 @@ GravatarQuickEditor.show(
172312
)
173313
```
174314

175-
### Cache busting
315+
## Cache busting
176316

177317
When an avatar is modified, the change is applied immediately, but it may take a few seconds to propagate through the Gravatar servers. As a result, requesting the avatar quickly using the usual URL might sometimes return the previous avatar.
178318

179319
To ensure you receive the updated avatar after a change, you can use a cache buster. Our SDK provides methods to assist you in this process.
180320

181-
#### Using AvatarUrl
321+
### Using AvatarUrl
182322

183323
The `AvatarUrl` method accepts an optional parameter that we'll add as a cache buster:
184324

@@ -188,7 +328,7 @@ public fun url(cacheBuster: String? = null): URL
188328

189329
You can use any string as a cache buster, but ensure that you don't repeat the value when you want to refresh the avatar. A timestamp is a good example of a unique cache buster.
190330

191-
#### Using the Avatar UI Component
331+
### Using the Avatar UI Component
192332

193333
If you're using our UI Avatar component, you can simply enable the `forceRefresh` parameter when you want to use the cache buster. We'll manage everything for you, updating the cache buster in every recomposition while the `forceRefresh` parameter remains true.
194334

@@ -203,7 +343,7 @@ public fun Avatar(
203343
)
204344
```
205345

206-
By setting `forceRefresh` to true, you ensure that the avatar is always fetched with the latest changes.
346+
By setting `forceRefresh` to true, you ensure that the avatar is always fetched with the latest changes. Although this will result in a new avatar, it must be used carefully as the image will be refreshed on each recomposition, which may not be ideal for performance.
207347

208348
If you want a more fine-grained control with the `Avatar` component you can use the version that takes the URL as a parameter and pass the URL with the cacheBuster value created with the `AvatarUrl` class.
209349

@@ -216,7 +356,7 @@ public fun Avatar(
216356
)
217357
```
218358

219-
### Android Permissions
359+
## Android Permissions
220360

221361
The Quick Editor module requires certain permissions to function correctly. Below is a table listing the permissions and the reasons why they are needed:
222362

@@ -227,7 +367,7 @@ The Quick Editor module requires certain permissions to function correctly. Belo
227367

228368
If you use the same permission with different configurations, you might end up with conflicts.
229369

230-
### Version migrations
370+
## Version migrations
231371

232372
When updating the SDK, you might need to migrate your code to the new version. Here is the list of all the migrations:
233373

210 KB
Loading
308 KB
Loading

docs/images/avatar_and_about.gif

184 KB
Loading
692 KB
Loading
838 KB
Loading

0 commit comments

Comments
 (0)