DWorkS / VolleyPlus

🏐 Volley library : make everything faster . Its an improvements for Volley by Google for Android https://android.googlesource.com/platform/frameworks/volley
https://github.com/DWorkS/VolleyPlus
984 stars 275 forks source link

Multipart request progress bar ui stuck #75

Open SilverFoxA opened 6 years ago

SilverFoxA commented 6 years ago

I have implemented the simple multipart request which also includes setOnProgressListener but the method doesn't get called hence progress bar doesn't show updated progress.

Here's my implementation

 final int[] percentDone = {0};
    param.put("uid", new SQLiteHandler(context).getUserDetails().get("uid"));
    SimpleMultiPartRequest jsonRequest = new SimpleMultiPartRequest(Request.Method.POST, URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    listener.success(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error != null && error.getCause() != null && error.getMessage() != null) {
                Log.d(tag, error.getMessage() + "");
            } else
                Log.d(tag, "Nothing");
            listener.error(error);
        }
    });

    for (String string :
            param.keySet()) {
        jsonRequest.addMultipartParam(string, "text/plain",
                param.get(string));
    }

    // jsonRequest.setFixedStreamingMode(true);

    jsonRequest.setOnProgressListener(new Response.ProgressListener() {
        @Override
        public void onProgress(long transferredBytes, long totalSize) {
            System.out.println(">>>>>>" + transferredBytes);
            final int latestPercentDone = (int) ((transferredBytes / (float) totalSize) * 100);

            if (percentDone[0] != latestPercentDone) {
                percentDone[0] = latestPercentDone;
                if (progressDialog != null)
                    progressDialog.setProgress(percentDone[0]);
            }
            if (BuildConfig.DEBUG) Log.d(tag, percentDone[0] + "");

            if (transferredBytes >= totalSize && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
        }
    });
    RequestQueue mRequestQueue = Volley.newRequestQueue(context);
    mRequestQueue.add(jsonRequest);
    mRequestQueue.start();
larrytech7 commented 6 years ago

Do your files get uploaded?