Example usage for com.facebook.react.bridge WritableMap hasKey

List of usage examples for com.facebook.react.bridge WritableMap hasKey

Introduction

In this page you can find the example usage for com.facebook.react.bridge WritableMap hasKey.

Prototype

boolean hasKey(@NonNull String name);

Source Link

Usage

From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java

License:Open Source License

private void subscribe(TransferObserver observer) {
    observer.setTransferListener(new TransferListener() {
        @Override/* www.j  a v  a  2  s.c o m*/
        public void onStateChanged(final int id, final TransferState state) {
            final WritableMap map = Arguments.createMap();
            final String uuid = transferIDMap.get(id);
            final Map<String, Object> req = requestMap.get(uuid);
            if (!(boolean) req.get(COMPLETIONHANDLER)) {
                return;
            }
            map.putString(REQUESTID, uuid);
            if (state == TransferState.CANCELED) {
                map.putString(ERROR, "canceled");
            } else if (state == TransferState.FAILED) {
                map.putString(ERROR, "failed");
            } else if (state == TransferState.COMPLETED) {
                final WritableMap request = Arguments.createMap();
                TransferObserver observer = null;
                try {
                    observer = transferUtility.getTransferById(id);
                } catch (final AmazonClientException e) {
                    throw e;
                }
                request.putString(BUCKET, observer.getBucket());
                request.putString(KEY, observer.getKey());
                request.putString(LOCATION, observer.getAbsoluteFilePath());
                map.putMap(REQUEST, request);
                removeTransferFromMap(uuid, id);
            }
            if ((state.equals(TransferState.CANCELED) || state.equals(TransferState.FAILED)
                    || state.equals(TransferState.COMPLETED)) && (map.hasKey(ERROR) || map.hasKey(REQUEST))) {
                sendEvent(getReactApplicationContext(), "CompletionHandlerEvent", map);
            }
        }

        @Override
        public void onProgressChanged(final int id, final long bytesCurrent, final long bytesTotal) {
            final WritableMap map = Arguments.createMap();
            final String uuid = transferIDMap.get(id);
            final Map<String, Object> req = requestMap.get(uuid);
            map.putString(TYPE, (String) req.get(TYPE));
            map.putString(REQUESTID, uuid);
            map.putDouble(COMPLETEDUNITCOUNT, (double) bytesCurrent);
            map.putDouble(TOTALUNITCOUNT, (double) bytesTotal);
            if (bytesTotal == 0) {
                map.putDouble(FRACTIONCOMPLETED, 0);
            } else {
                map.putDouble(FRACTIONCOMPLETED, ((double) bytesCurrent / (double) bytesTotal));
            }
            sendEvent(getReactApplicationContext(), "ProgressEventUtility", map);
        }

        @Override
        public void onError(final int id, final Exception ex) {
            final WritableMap map = Arguments.createMap();
            final WritableMap errorMap = Arguments.createMap();
            final String uuid = transferIDMap.get(id);
            map.putString(REQUESTID, uuid);
            errorMap.putString(ERROR, ex.toString());
            errorMap.putString(DESCRIPTION, ex.getLocalizedMessage());
            errorMap.putInt(CODE, ex.hashCode());
            map.putMap(ERROR, errorMap);
            sendEvent(getReactApplicationContext(), "ProgressEventUtility", map);
        }
    });
}

From source file:com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocationModule.java

@ReactMethod
public void getState(Callback success, Callback failure) {
    WritableMap state = getState();
    if (state != null && !state.hasKey("error")) {
        success.invoke(state);/*from  w ww .j a  v  a  2s .  c  o m*/
    } else {
        failure.invoke(state);
    }
}