多次调用改造时如何解除对话?

时间:2017-08-30 06:57:21

标签: android retrofit progressdialog

  

我正在使用改造来访问具有计数器值的API,即当我   获得第一次响应呼叫改造方法一次又一次   直到最后一个计数器值。我也在做出响应下载后做了   使用AsyncTask的图像。

     

当我第一次调用改装方法时,显示进度   对话。我想在下载最后一张图片时关闭对话框。

visibleProgressBar(getString(R.string.fetch_data_msg));

    getMyOxygenInitialSync();






public  void  getMyOxygenInitialSync() {



            if (new CheckConnection(context).isConnectedToInternet()) {
                UserPreferences preferences = UserPreferences.getUserPreferences(context);

                ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
                try {
                    JsonObject params = new JsonObject();
                    params.addProperty("my_oxygen_user_id", "984");
                    params.addProperty("action", "fullSync");
                    params.addProperty("page", String.valueOf(page));
                    params.addProperty("syncDate", "");
                    // RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),(new JSONObject(params)).toString());

                    Call<MyOxygenSyncResponseMain> call = apiService.getMyOxygenSycList(params);


                    call.enqueue(new Callback<MyOxygenSyncResponseMain>() {
                        @Override
                        public void onResponse(Call<MyOxygenSyncResponseMain> call, retrofit2.Response<MyOxygenSyncResponseMain> response) {
                            invisibleProgressDialog();


                            try {
                                if (response != null) {
                              /*  MyOxygenSyncResponseMain myOxygenSyncResponseMain = new MyOxygenSyncResponseMain();
                                myOxygenSyncResponseMain = ((MyOxygenSyncResponseMain)response);*/
                                    totalPage = response.body().getTotalPage();
                                    page++;
                                    if (response.body().getImageDetail() != null && response.body().getImageDetail().size() > 0) {
                                        for (int i = 0; i < response.body().getImageDetail().size(); i++) {
                                            MyOxygen myOxygen = new MyOxygen();
                                            myOxygen.setImageId(response.body().getImageDetail().get(i).getMy_oxygen_image_id());
                                            myOxygen.setImageName(response.body().getImageDetail().get(i).getMy_oxygen_image_name());
                                            myOxygen.setImagePhysicalPath(response.body().getImageDetail().get(i).getMy_oxygen_image_url());
                                            myOxygen.setCategory(response.body().getImageDetail().get(i).getMy_oxygen_image_cat());
                                            myOxygen.setSyncDate(response.body().getImageDetail().get(i).getSyncDate());
                                            //  myOxygen.setOrderId(myOxygenSyncResponseMain.getImageDetail().get(i).getOrde());
                                            myOxygen.setIsUpdated(Integer.parseInt(response.body().getImageDetail().get(i).getMy_oxygen_is_deleted()) == 0 ? 1 : 0);
                                            myOxygen.setIsDeleted(response.body().getImageDetail().get(i).getMy_oxygen_is_deleted());

                                            myOxygenDBHelpher.saveMyOxygen(myOxygen);

                                            downloadImage(myOxygen.getImageName(),myOxygen.getImagePhysicalPath(),myOxygen.getImageId());

                                        }

                                            for(page=page;page<=totalPage+1;page++){
                                                getMyOxygenInitialSync();
                                            }

                                          /*  if( page== totalPage){
                                                downloadImage();
                                            }*/

                                    }

                                    Log.d("Resp ", response.raw().body().toString());

                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }


                        }

                        @Override
                        public void onFailure(Call<MyOxygenSyncResponseMain> call, Throwable t) {
                            invisibleProgressDialog();
                            try {

                                Log.d("Error ", call.toString());
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });


                } catch (Exception e) {
                    e.printStackTrace();
                }
            }


    }

0 个答案:

没有答案