Skip to content

Commit

Permalink
fix(android): append init props for image load
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and siguangli committed Aug 22, 2024
1 parent b04da96 commit 269c33d
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,29 @@ private void handleRequestProgress(final long total, final long loaded,
}
}

private void appendCustomRequestParams(@NonNull HashMap<String, String> requestParams,
@NonNull Map<String, Object> initProps) {
for (Map.Entry<String, Object> entry : initProps.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
try {
requestParams.put(key, String.valueOf(value));
} catch (Exception ignore) {
// For now, support custom attributes that can be converted to strings
}
}
}

@NonNull
private HashMap<String, String> generateRequestParams(int width, int height) {
private HashMap<String, String> generateRequestParams(int width, int height,
@Nullable Map<String, Object> initProps) {
HashMap<String, String> requestParams = new HashMap<>();
if (initProps != null) {
Object value = initProps.get("props");
if (value instanceof Map) {
appendCustomRequestParams(requestParams, (Map) value);
}
}
requestParams.put("width", String.valueOf(width));
requestParams.put("height", String.valueOf(height));
requestParams.put(REQUEST_CONTENT_TYPE, REQUEST_CONTENT_TYPE_IMAGE);
Expand All @@ -167,7 +187,7 @@ private HashMap<String, String> generateRequestParams(int width, int height) {
@Nullable
public ImageDataSupplier fetchImageSync(@NonNull String url,
@Nullable Map<String, Object> initProps, int width, int height) {
HashMap<String, String> requestParams = generateRequestParams(width, height);
HashMap<String, String> requestParams = generateRequestParams(width, height, initProps);
ResourceDataHolder dataHolder = mVfsManager.fetchResourceSync(url, null, requestParams);
byte[] bytes = dataHolder.getBytes();
if (dataHolder.resultCode
Expand Down Expand Up @@ -215,7 +235,7 @@ public void fetchImageAsync(@NonNull final String url,
if (checkRepeatRequest(urlKey, listener)) {
return;
}
HashMap<String, String> requestParams = generateRequestParams(width, height);
HashMap<String, String> requestParams = generateRequestParams(width, height, initProps);
mVfsManager.fetchResourceAsync(url, null, requestParams,
new FetchResourceCallback() {
@Override
Expand Down

0 comments on commit 269c33d

Please sign in to comment.