From 594f8bde5be3a17c9dc638f78eacf1767c94fee0 Mon Sep 17 00:00:00 2001 From: parveshneedhoo Date: Tue, 10 Sep 2024 10:57:26 +0400 Subject: [PATCH] refactor(code climate error) --- src/android/FileTransferBackground.java | 54 +++++++++++-------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/android/FileTransferBackground.java b/src/android/FileTransferBackground.java index 424aa1b0..cebcc1bf 100644 --- a/src/android/FileTransferBackground.java +++ b/src/android/FileTransferBackground.java @@ -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 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 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); + } } /**