1

So I'm looking for a solution. I currently have a Firebase database that stores all my users’ information. I then take this and place it into an ImageView and TextView by running a listener for a single value event which gives me a list of users that I'm able to iterate over.

The key point to this is that I do not want to swipe in order to change the user they are looking at; I want them to click on a button. This is the current onClick listener:

button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        try {
            boolean verified;
            //REMOVE USER FROM LIST
            String matchUid = userList.get(0).getUid();
            userList.remove(0);
        }
        // GET NEW USER
        String url = userList.get(0).getPhoto1URI();
        String name = userList.get(0).getFirstname();

        final String userage = String.valueOf(userList.get(0).getAge());

        // SET NEW USER
        if(url != null && name != null) {
            mainName.setText(name);
            mainAge.setText(userage);
            Glide.with(getApplicationContext())
                           .load(url)
                           .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                           .centerCrop()
                           .crossFade()
                           .error(R.drawable.addimage)
                           .into(profileImage);
        }
    }
});

Currently, this process takes too long to switch between users once the button is pressed so there must be a more efficient way of doing this. Is there any way of preloading the next image so that it gives quicker loading times?

Zoe
  • 27,060
  • 21
  • 118
  • 148
James Palfrey
  • 753
  • 6
  • 29

2 Answers2

0

You should fetch and add all the details in the Arraylist in starting only. Then you get the specific details from the list according to the button click.

Raj
  • 2,997
  • 2
  • 12
  • 30
0

This post has an answer from user Vinay Wadhwa that shows that you can use .downloadOnly:

FutureTarget<File> future = Glide.with(context)
                                .load(url)
                                .downloadOnly(width, height);

Or, you can use .preload:

Glide.with(context)
    .load(url)
    .preload(width, height);

And then you can use the image by calling it something like:

Glide.with(context)
    .load(url)
    .into(imageView);

In the same post that I linked above, the accepted answer demonstrates another solution to preloading images by using a LruCache.

Make sure to check out the above link and let me know if the info helps.

0xCursor
  • 2,242
  • 4
  • 15
  • 33
  • so this answer works if you're only loading 2 images.. the fact that i'm loading image one...preloading image 2...then the next time around image one needs to be the url of image 2 and image 2 needs to be the next image stops me from using it as a final solution. Unless i'm missing something the way you call the image back is by using the same url variable which in this case would change prior to the glide statements – James Palfrey Jul 17 '18 at 05:45
  • Maybe putting the URLs into an array and then updating the indices each time the button is clicked could work. – 0xCursor Jul 17 '18 at 13:19