I'm creating an application where the user is allowed to upload pictures. When the picture has been uploaded successfully I would like to add a green check at the upper right corner (drawable). The same when failed but with a cross. Atm I'm using Glide to show URI's on the screen. How could I achieve this?
You can achieve this by calling glide listeners. First you have to add overlay ImageView in layout file with android:visibility="gone"
.
For example: Layout.xml file
<RelativeLayout
android:layout_width="200dp"
android:layout_height="200dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="Your main image view"
android:src="@drawable/gradient_background"/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/ivIcon"
android:contentDescription="Icon to be displayed after result"
android:src="@drawable/ic_thumb"
android:layout_margin="10dp"
android:layout_alignParentEnd="true"
android:visibility="gone"/>
</RelativeLayout>
Then use glide like this
Glide.with(getActivity())
.load(RESOURCE_ID)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
ivIcon.setImageResource(faliureImageResourceID);
ivIcon.setVisibility(View.VISIBLE);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
ivIcon.setImageResource(successImageID);
ivIcon.setVisibility(View.VISIBLE);
return false;
}
})
.into(mainImageView);
Hope this will work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With