URL to ImageViwe using Glide Library | Android App Development | Lecture#64 | Hive Learners

𝓖𝓻𝓮𝓮𝓽𝓲𝓷𝓰𝓼

Hello Hiveans, I hope you all are well. In lecture 63 we learn how to get and store the Uploaded file link. We continue lecture 63 and in this lecture, we learn how to use the Glide Android Java library to load an image from a URL to an ImageView.So, let's get started.

multi purpose (10).png

GitHub Link

Use this GitHub project to clone into your directory. The following lecture will update it so you will never miss the latest code. Happy Coding!

What Should I Learn

  • What is Glide Library
  • How to add and use Glide Library
  • How to load image from URL to ImageView using Glide

Assignment

  • Load image from URL to ImageView using Glide

Procedure

First, we need to add the Library in the Gradle file. Add the Glide implementation in the module-level Gradle file. Here is the GitHub Link to the Glide Library.

An image loading and caching library for Android focused on smooth scrolling

https://github.com/bumptech/glide

implementation 'com.github.bumptech.glide:glide:4.13.2'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'

Add this implementation in the tag of dependencies and sync the project.

image.png

After the successful sync, We can use the Glide library with full benefits. We need to write the code to load the image from the URL to the ImageView. We will add a try-catch to catch any exceptions while image loading.

public class Profile_Activity extends AppCompatActivity {

    private TextView username_tv, email_tv;
    private ImageView profile_image;
    private FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);

        username_tv = findViewById(R.id.profile_username_tv);
        email_tv = findViewById(R.id.profile_email_tv);
        profile_image = findViewById(R.id.profile_image_iv);

        username_tv.setText(firebaseAuth.getCurrentUser().getDisplayName());
        email_tv.setText(firebaseAuth.getCurrentUser().getEmail());

        try {
            Glide.with(Profile_Activity.this).load(firebaseAuth.getCurrentUser().getPhotoUrl()).into(profile_image);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

image.png

When the user signup we upload the profile image and then create the user account with the profile link of the uploaded image. In this way, we can get the profile image link from the FirebaseAuth. Then we can use that link in the Glide Library to load the image in the ImageView. In this way, there is no need to save the profile image link separately. FirebaseUser will save it automatically. In the next lecture, we will learn how to edit the details in the FirebaseUser. We will check how to update the profile image link. See you soon. Thank You.


hl_divider.png

Thank You

hl_footer_banner.png



0
0
0.000
7 comments
avatar

Congratulations @faisalamin! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You have been a buzzy bee and published a post every day of the week.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

Our Hive Power Delegations to the August PUM Winners
Feedback from the September 1st Hive Power Up Day
Hive Power Up Month Challenge 2022-08 - Winners List
0
0
0.000
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

0
0
0.000