Skip to content

Commit

Permalink
Merge pull request #2140 from dhis2/androsdk-1843
Browse files Browse the repository at this point in the history
docs: [ANDROSDK-1843] docs: custom icons documentation
  • Loading branch information
marcamsn authored May 7, 2024
2 parents 42f543d + 66420cc commit 58f0016
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
40 changes: 31 additions & 9 deletions docs/content/developer/object-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,44 @@ This property is optional and it is not defined in most of the cases. An object

## Icon

The set of icons used in DHIS2 are included in the SDK. They are located within the resources, in the "drawable" folder. Currently they are predefined and cannot be customized.
DHIS2 includes a predefined set of icons. Those icons are included in the SDK and are located within the resources, in the "drawable" folder.

```java
Staring on version v41, it is possible to upload user-defined icons and assign them to metadata objects. The actual images of these icons are stored as a FileResource and must be explicitly downloaded in a separate query.

// Illustrative code to get the resource id
if (program.style().icon() != null) {
String iconName = program.style().icon();
int resourceId = getResources().getIdentifier(iconName, "drawable", getPackageName());
```kt
d2.fileResourceModule().fileResourceDownloader()
.byDomainType().eq(FileResourceDomainType.ICON)
.download()
```

You can get the information about a particular icon by using the IconCollectionRepository. It returns an Icon object, which is a sealed class with two possible values: Default or Custom.

The way to render the actual image will depend on the Icon type.

```kt

val icon = d2.iconModule().icons().key("icon_key").blockingGet()

icon?.let {
when (icon) {
is Icon.Custom -> {
val path = icon.path
val fileResourceUid = icon.fileResourceUid
// Use this information to load the file
}

is Icon.Default -> {
val resourceName = icon.key
// Use this information to load the resource
}
}
}
```

## Color

It contains the Hex value for the color. It can be used to customize the background, text color, line headings, etc.

```java
program.style().color(); // For example #9C33FF

```kt
program.style().color() // For example #9C33FF
```
21 changes: 7 additions & 14 deletions docs/content/developer/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,6 @@ Data whose state is `ERROR` or `WARNING` cannot be uploaded. It is required to s

As of version 2.37, a new tracker importer was introduced (`/api/tracker` endpoint). The default tracker importer is still the legacy one (`/api/trackedEntityInstances`), but you can opt-in to use this new tracker importer by using the Android Settings webapp (see [Synchronization](#android_sdk_synchronization_settings)). This is internal to the SDK; the API exposed to the app does not change.

File resources must be uploaded in a different post call before tracker data upload. The query to post file resources is:

```java
d2.fileResourceModule().fileResources().upload();
```

More information about file resources in the section [*Dealing with FileResources*](#android_sdk_file_resources).

#### Tracker conflicts

Server response is parsed to ensure that data has been correctly uploaded to the server. In case the server response includes import conflicts, these conflicts are stored in the database, so the app can check them and take an action to solve them.
Expand Down Expand Up @@ -781,13 +773,14 @@ This module contains methods to download the file resources associated with the
- **File resources download**.
The `fileResourceDownloader()` offers methods to filter the fileResources we want to download. It will search for values that match the filters and whose file resource has not been previously downloaded.

```java
```kt
d2.fileResourceModule().fileResourceDownloader()
.byDomainType().eq(FileResourceDomainType.TRACKER)
.byElementType().eq(FileResourceElementType.DATA_ELEMENT)
.byValueType().in(FileResourceValueType.IMAGE, FileResourceValueType.FILE_RESOURCE)
.byMaxContentLength().eq(2000000)
.download();
.byDomainType().eq(FileResourceDomainType.DATA_VALUE)
.byDataDomainType().eq(FileResourceDataDomainType.TRACKER)
.byElementType().eq(FileResourceElementType.DATA_ELEMENT)
.byValueType().in(FileResourceValueType.IMAGE, FileResourceValueType.FILE_RESOURCE)
.byMaxContentLength().eq(2000000)
.download()
```

The SDK has a default maxContentLength of 6000000.
Expand Down

0 comments on commit 58f0016

Please sign in to comment.