Skip to content

Commit

Permalink
refactor(code climate error)
Browse files Browse the repository at this point in the history
  • Loading branch information
parveshneedhoo committed Sep 10, 2024
1 parent 12da3f7 commit 594f8bd
Showing 1 changed file with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions src/android/FileTransferBackground.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,41 +411,33 @@ private void acknowledgeEvent(String eventId, CallbackContext context) {
*/
private void handleAck(final Data ackData) {
if (!ackData.getBoolean(UploadTask.KEY_OUTPUT_IS_ERROR, false)) {
handleSuccessfulUpload(ackData);
} else {
handleFailedUpload(ackData);
}
}

private void handleSuccessfulUpload(Data ackData) {
String response = null;
if (ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE) != null) {
response = readFileToStringNoThrow(ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE));
}

long startUploadTime = ackData.getLong("output_upload_start_time", 0);
long finishUploadTime = ackData.getLong("output_upload_finish_time", 0);
long uploadDuration = finishUploadTime - startUploadTime;

HashMap<String, Object> uploadData = new HashMap<>();
uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID));
uploadData.put("response", response);
uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1));

if (uploadDuration > 0) {
uploadData.put("uploadDuration", uploadDuration);
uploadData.put("finishUploadTime", finishUploadTime);
}

sendSuccess(uploadData);
}

private void handleFailedUpload(Data ackData) {
sendError(
sendError(
ackData.getString(UploadTask.KEY_OUTPUT_ID),
ackData.getString(UploadTask.KEY_OUTPUT_FAILURE_REASON),
ackData.getBoolean(UploadTask.KEY_OUTPUT_FAILURE_CANCELED, false)
);
} else {
String response = null;
if (ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE) != null) {
response = readFileToStringNoThrow(ackData.getString(UploadTask.KEY_OUTPUT_RESPONSE_FILE));
}

long startUploadTime = ackData.getLong("output_upload_start_time", 0);
long finishUploadTime = ackData.getLong("output_upload_finish_time", 0);
long uploadDuration = finishUploadTime - startUploadTime;

HashMap<String, Object> uploadData = new HashMap<>();
uploadData.put("outputId", ackData.getString(UploadTask.KEY_OUTPUT_ID));
uploadData.put("response", response);
uploadData.put("statusCode", ackData.getInt(UploadTask.KEY_OUTPUT_STATUS_CODE, -1));

if (uploadDuration > 0) {
uploadData.put("uploadDuration", uploadDuration);
uploadData.put("finishUploadTime", finishUploadTime);
}

sendSuccess(uploadData);
}
}

/**
Expand Down

0 comments on commit 594f8bd

Please sign in to comment.