Alright, so moving on. How do we get the photo details activity to display the photo now that we've got
the photo details activity working.
Well the first thing we have to do is retrieve the details from the intent.
So let's go to photo details activity and do that first.
I'm going to make a bit of space here,
so it's a bit clearer what's happening.
So let's add a line now to actually get the details from the intent, and to do that we're going to type
val photo is equal to intent dot
getSerializableExtra parentheses, which are there, photo underscore transfer
as Photo.
Now we're using the activity's intent property to retrieve the intent that started this activity.
Now to retrieve the photo object, we use a get extra function. We have to use the get method that's appropriate
for the data we want to retrieve,
and in this case it's a serializable object which we then cast to be a photo.
Now we're using the photo transfer constant as the key, to make sure we retrieve the same value that was
stored by main activity.
Alright so now that we've done that,
so next we need to set the values from the fields of the photo object into the appropriate widget in
the display.
Now the text views are easy, so let's the try the first one, so photo
underscore title. Now
be careful with the suggested imports
the first time you access a widget in this way. We haven't yet got a synthetic import,
so Android Studio is going to try to find the best import to use.
Now sometimes it wants to find it in the R class and, that's definitely not what we want.
You want to make sure you're choosing content underscore photo underscore details from the tool
tip.
Now in my case that's the only option I've got, and that's fine,
but if you do get the wrong one, delete the import that's added and use alt enter
to get a list of suggestions, and you want to choose the Kotlin Android synthetic main content underscore
photo underscore details, and you'll find that if I select this one here, we get the import added
on line 4 automatically for us. So photo underscore title dot
text equals photo.title.
So again we've got the synthetic import added now and we can refer to the remaining widgets as well at this
point.
So photo underscore tags dot text, is equal to photo dot tags.
Then we want photo underscore author dot text is equal to photo dot author.
Now showing the picture in the image view is also straightforward.
It's almost exactly the same as the code we used in the on bind view holder function of our adapter,
the flickr recycler view adapter.
So I'm going to go back to that code now, the FlickrRecyclerViewAdapter, and the code in on bind is Picasso
dot with. I'm going to copy that code,
and go back to our PhotoDetailsActivity. I'm going to paste that in. We want to accept the import to com dot squareup dot picasso dot
Picasso, and there's just a few minor changes to make, and they're actually all highlighted for us.
The first one is the context.
Now an activity is a context, so we can just use this for that, so I'm going to go ahead and do that to fix
that first one up, this. Now the next change is the URL to load the picture from. Now
the thumbnail URL was in the image property, and we've stored the full photo URL in the link property,
so we can use photo dot link instead.
I'll come over here and change that.
That's going to be photo.link, and we've also called our photo object photo,
rather than photo item, so obviously I changed that as well.
And finally the image view's stored in photo underscore image,
rather than the holder.thumbnail, so into photo
underscore image,
and we don't need the dot thumbnail at all anymore. Alright, so
let's try running this and see if it works.
We're going to long tap an image, and at this point we've actually got an error.
So we need to figure out what we've done wrong and fix the code.
So let's firstly have a look at log cat, and the problem there is I've left this.thumbnail.context showing,
and of course that should have just been this, because we know we're not using the thumbnail there.
And again the reason we're using this, is that an activity is a context so we can just use this literally
as the context, so I didn't need to use the thumbnail at all.
So let's just try running that again.
OK we'll try long tapping an image, and you notice that there was a short delay while picasso
downloaded the image the first time,
and that's why we've specified a placeholder image is displayed when the real image is downloaded.
If we go back and choose the same image again, notice how it's instant this time,
and that's because picasso's loading it from a local cache, and the other thing we've got is our other
text
views are actually working nicely as well. To do that let's just try another image,
and you can see that's working nicely as well.
So basically, we're now seeing our images load, and we're seeing the text represented on the screen as well,
and it's all working fine.
So at this point let's stop the video, and in the next one I'm going to show you how to use parcelable instead of serializable.
So I'll see you in the next video.