public void downloadImages(ImageVehicle object) { final ImageVehicle imageObject = object; if ((imagesMap.get(imageObject.getUrl()) != null) || (imageObject.getAngle() == currentAngle)) { return; } final Handler handler = new Handler(); final Thread thread = new Thread( new Runnable() { String url = imageObject.getUrl(); Bitmap bitmap; public void run() { threadNumber++; Log.d("Threads number", "Threads number = " + threadNumber); try { bitmap = Glide.with(mContext) .load(url) .asBitmap() .into(imageWidthToDownload, imageWidthToDownload / 3) .get(); } catch (Exception e) { e.printStackTrace(); Log.d("Thread stopped", "" + e.getMessage()); } handler.post( new Runnable() { @Override public void run() { if (bitmap != null) { imagesMap.put(url, bitmap); progressBar.setProgress(currentProgress++); } else { downloadImages(imageObject); } } }); } }); thread.start(); }
private void loadImagesUrls(String order, int width) { ImageVehicle.getImages( new GetListHandler<ImageVehicle>() { @Override public void done(ArrayList<ImageVehicle> data) { imageVehicles = data; setFirstImageThread(); for (final ImageVehicle object : imageVehicles) { if (object.getAngle() == currentAngle) { continue; } downloadImages(object); } checkForCompleteDownloadThread(); // checkInternetConnectionThread(); } @Override public void error(String responseError) {} }, order, width); }