The task is to download images from the site, create their files on the SD card and put the paths to them in the database. To call them later without an internet connection. Update data is also provided, so the image files must be overwritten. On site images in jpeg. I am trying to upload images via Picasso and output them through this library too.
Download Code:
for (k = 0; k < 5; k++) { Picasso.with(context).load(image_ar.get(k)).into(new Target() { @Override public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) { File filename = new File(context.getCacheDir().getAbsolutePath() + "/img" + k + ".jpg"); FileOutputStream out = null; try { if (filename.exists()) { if (filename.delete()) { System.out.println("Π£Π΄Π°Π»Π΅Π½ΠΎ"); } } if (filename.createNewFile()) { System.out.println("New Create"); } out = new FileOutputStream(filename); contentValues.put(DBHelperNews.KEY_HREF_TO_IMAGE, filename.getPath()); bitmap.compress(Bitmap.CompressFormat.JPEG, 40, out); } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { e.printStackTrace(); } } } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }); database.insert(DBHelperNews.TABLE_NEWS, null, contentValues); } Output code:
Picasso.with(context) .load("file:///" + image) .into(viewHolder.itemImage); In addition to the pictures, the text is also loaded. The text works fine, but the pictures are loaded through time. And once they are loaded, and with the next update, picasso does not even record. And so it is constantly, but sometimes it happens that a photo is simply not recorded, and instead of it, the previous one is displayed in the application. If this is not easier to implement through picasso, how? Thank you in advance!