Try to implement a Universal Image Loader library but I really did not understand anything about the documentation so look for others, now I'm trying to adapt my way of showing my images but using GLIDE , what happens is that I want to show the images in IndexActivity (it's my activity where I have my GridView initialized) but that they look as they load because what I used to do before was to launch the IndexActivity until all the images were not there, but that is harming me for other processes that I want to do.
IndexActivity.java
//creo una instancia de CheckIn
CheckIn checkIn = CheckIn.getInstance();
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
if (checkIn.getImages().size() > 0) {//valido de que existan imagenes
for (ImageData object: checkIn.getImages()) {
bitmaps.add(object.getBitmap());//al ArrayList le agrego los Bitmaps
}//for
gridView.setAdapter(new ImageAdapter(this, bitmaps));//seteo las imagenes al gridView
}//./if
PictureActivity.java
CheckIn checkIn = CheckIn.getInstance();//TODO YA NO
for (int i = 0; i < principalListOfImages.size(); i++) {
ImageData imageData = new ImageData();//creo una instancia de ImageData
Bitmap bitmap = BitmapFactory.decodeFile(principalListOfImages.get(i));//paso el path a Bitmap
imageData.setBitmap(bitmap);//le setteo el bitmap
imageData.setPath(principalListOfImages.get(i));//le setteo el path
checkIn.getImages().add(imageData);//recupero mi arreglo de objetos y le setteo mi nuevo objeto
listOfBitmaps.add(bitmap);//cada BItmap lo setteo al arraylist
}//for
new UploadImage().execute(listOfBitmaps);
UploadImage.java (AsyncTask)
//ejecuta nuestras tareas
@Override
protected Void doInBackground(Object... params) {principales
CloseableHttpClient httpClient;
CloseableHttpResponse httpResponse;
try {
CheckIn checkIn = CheckIn.getInstance();//hago una instancia de checkin
JSONObject jsonImage = new JSONObject();//creo un JSONObject
ArrayList<Bitmap> listOfBitmaps = (ArrayList<Bitmap>) params[0];//Obtengo mi Arreglo de objetos para despues pasarlos a un array lis de Bitmap
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();//permitira la salida de los bytes
for (int i = 0; i < listOfBitmaps.size(); i++) {//itero el arreglo
listOfBitmaps.get(i).compress(Bitmap.CompressFormat.JPEG, 70, byteArrayOutputStream);//se comprime la imagen
byte[] byteArray = byteArrayOutputStream.toByteArray();//codifica el path a un arreglo de byte
String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);//codifico ese byteArray a base64 y despues a scrintg
jsonImage.put("folio", checkIn.getFolio());//paso el folio al JSONObject
jsonImage.put("images", encoded);//le paso al JSONObject los codigos de las iameges
StringEntityHC4 entityHC4 = new StringEntityHC4(jsonImage.toString(), ContentType.create("json/application", "UTF-8"));//la direccion del servidor a la que va a apuntar
HttpPutHC4 httpPutHC4 = new HttpPutHC4(DynamicUrl.BASE_URL + DynamicUrl.SERVER_HOST + ":" + DynamicUrl.SERVER_PORT + "/api/checkkin");//la direccion del dervidor al que va a apuntar
httpPutHC4.setEntity(entityHC4);//seteo los datos que tengo en el JSONObject
httpClient = HttpClients.createDefault();//La configuracion del servidor va a ser default
httpResponse = httpClient.execute(httpPutHC4);//Obtengo la respuesta del servidor
if (httpResponse.getStatusLine().getStatusCode() == 200) {//si el estatus de la respuesta es igual a 200
JSONObject jsonRosponse = new JSONObject(EntityUtilsHC4.toString(httpResponse.getEntity()));//creo un JSONObject y le paso el JSON que recibio de la sespuesta del servidor
if (jsonRosponse.getString("code").equals("OK")) {//checo que el JSON tenga la clave OK
System.out.println("Las imagenes se guardaron correctamente");
} else {
System.out.println("Error al subir las imagenes");
}
} else {
System.out.println("Ocurrio un error");
}
}//./for
} catch (Exception e) {
e.printStackTrace();
}
return null;
}