diff --git a/android/src/main/java/ee/forgr/capacitor/uploader/UploaderPlugin.java b/android/src/main/java/ee/forgr/capacitor/uploader/UploaderPlugin.java index 843209a..fe7ed8b 100644 --- a/android/src/main/java/ee/forgr/capacitor/uploader/UploaderPlugin.java +++ b/android/src/main/java/ee/forgr/capacitor/uploader/UploaderPlugin.java @@ -49,66 +49,66 @@ private void createNotificationChannel() { @Override public void load() { createNotificationChannel(); - + // Create a request observer for all uploads RequestObserver observer = new RequestObserver( - getContext().getApplicationContext(), - getActivity(), - new RequestObserverDelegate() { - @Override - public void onProgress(Context context, UploadInfo uploadInfo) { - JSObject event = new JSObject(); - event.put("name", "uploading"); - JSObject payload = new JSObject(); - payload.put("percent", uploadInfo.getProgressPercent()); - event.put("payload", payload); - event.put("id", uploadInfo.getUploadId()); - notifyListeners("events", event); - } - - @Override - public void onSuccess( - Context context, - UploadInfo uploadInfo, - ServerResponse serverResponse - ) { - JSObject event = new JSObject(); - event.put("name", "completed"); - JSObject payload = new JSObject(); - payload.put("statusCode", serverResponse.getCode()); - event.put("payload", payload); - event.put("id", uploadInfo.getUploadId()); - notifyListeners("events", event); - } - - @Override - public void onError( - Context context, - UploadInfo uploadInfo, - Throwable exception - ) { - JSObject event = new JSObject(); - event.put("name", "failed"); - JSObject payload = new JSObject(); - payload.put("error", exception.getMessage()); - event.put("payload", payload); - event.put("id", uploadInfo.getUploadId()); - notifyListeners("events", event); - } - - @Override - public void onCompleted(Context context, UploadInfo uploadInfo) { - JSObject event = new JSObject(); - event.put("name", "finished"); - event.put("id", uploadInfo.getUploadId()); - notifyListeners("events", event); - } - - @Override - public void onCompletedWhileNotObserving() { - // Handle completion while not observing if needed - } + getContext().getApplicationContext(), + getActivity(), + new RequestObserverDelegate() { + @Override + public void onProgress(Context context, UploadInfo uploadInfo) { + JSObject event = new JSObject(); + event.put("name", "uploading"); + JSObject payload = new JSObject(); + payload.put("percent", uploadInfo.getProgressPercent()); + event.put("payload", payload); + event.put("id", uploadInfo.getUploadId()); + notifyListeners("events", event); + } + + @Override + public void onSuccess( + Context context, + UploadInfo uploadInfo, + ServerResponse serverResponse + ) { + JSObject event = new JSObject(); + event.put("name", "completed"); + JSObject payload = new JSObject(); + payload.put("statusCode", serverResponse.getCode()); + event.put("payload", payload); + event.put("id", uploadInfo.getUploadId()); + notifyListeners("events", event); + } + + @Override + public void onError( + Context context, + UploadInfo uploadInfo, + Throwable exception + ) { + JSObject event = new JSObject(); + event.put("name", "failed"); + JSObject payload = new JSObject(); + payload.put("error", exception.getMessage()); + event.put("payload", payload); + event.put("id", uploadInfo.getUploadId()); + notifyListeners("events", event); } + + @Override + public void onCompleted(Context context, UploadInfo uploadInfo) { + JSObject event = new JSObject(); + event.put("name", "finished"); + event.put("id", uploadInfo.getUploadId()); + notifyListeners("events", event); + } + + @Override + public void onCompletedWhileNotObserving() { + // Handle completion while not observing if needed + } + } ); implementation = new Uploader(getContext().getApplicationContext());