- [Commentator] Now we are back in ourGoogle photos fragment.If you see a build warning for fragment Google photoslayout here, you may want to do a clean before proceeding.Now let's go ahead and initialize our swiperefresh layout.We will call the fine view by ID.

Now I notice I have not defined the view ID for ourswipe refresh layout, so let's go ahead and do that.I'm going to press Command+C and we switch over to ourfragment Google photos layout, we go to our swipe refreshlayout, and we're going to add our view ID here.And press Command+V to define our view ID swipe refreshlayout, now let's switch back to Google photos fragment.Now we have our view.

Let's go ahead and define a class member swipe refreshlayout, so I'm going to go Command+C.Let's go to the top.And we define a private class member.Type swipe refresh layout.Now let's go back down.So swipe refresh layout, what we want to do is when weswipe down on the screen, we want to make a one time checkto see whether our picasa client library is initializedand if it is, load our albums.

And we will define a new listener here.And we will make our call to our picasa client library.Now to get rid of this build warning, what we can do ispress Alt+Return and select add dependency Googlephotos library.Now let's add a method, the private method will beload albums.

So let's define our private method here.We will return void as our type.Load album will do two things, the first is we're goingto set our refresh layout progress animation, so let'sdo that here.Call set refreshing.To true.And the next call will be to our picasa client library.Our picasa client library uses RX Java so we're going to makea couple of setup calls.

And we're going to chain to observable.And retry.We're going to also call set single.And we're going to observe on our main thread.Using the Android schedulers.mainthread.And we will provide a subscribe and we are going to defineour callbacks.In our on success callback, what we will do is make anothercall and we're going to create another private method.

It's going to be called on load album finish.And we pass in our user feed.In our on error callback, we are going to defineanother private method.We will call that handle error.And we will pass in the throwable type error.

Let's go ahead and define our on load album finished hereto private method returning void.And we pass in our user feed.On load album finished will do two things.The first is we will set our refresh layout to dismissour progress animation.The other thing we will do here is call the adapterto load our photos, but we haven't defined our recyclerview adapter yet, so we will come back to this method later.

Now let's also define our handle error method.We're going to leave it as a stub for now.While we're here, we have a private method load album.Let's also define a private method load photos.It will look very similar to load album, and it'll havea very similar RX Java call.The difference is we have an album ID and we're going topass that in.

Load photos will do two things.And it'll be similar to load albums, the first is to setthe progress animation on refresh layout,let's do that here.And the next one is the RX Java call, it will look similarto the one for load albums.We're going to call album feed and pass in our album ID.And chain some RX Java calls to observable.

Retry.We're going to observe on the main thread again, just likefor load albums.And we're going to set up subscribers here.So now we have the on success and the on error callbackfor our load photos.In the on success, we're going to create a new methodon load photos finish.

And pass in our album feed.In the on error callback we will call handle errorjust like we did for load album.Now let's define on load photos finish, it's aprivate method.And we pass in our album feed.On load photos finish will do two things.

It'll call the adapter to load the photos, and also we willcall our refresh layout to dismiss our progress animation.We haven't defined our recycler view adapter yet.So we will come back to this method later.Now we are done with load photos and we are done withload albums.

Resume Transcript Auto-Scroll

Author

Released

8/31/2017

Bring your apps into the modern era. Android UI design has evolved, and an Android developer needs to know about the most popular UI elements used today and when to use them. This course teaches developers how to incorporate side navigation drawers, create view holders, and implement custom layouts and views, and design a RecyclerView for mixed view types—such as a category header view and photo item view. Instructor Albert Lo grounds the lessons in a real-world project: a photography app that pulls photos from multiple sources, including Google Photos, and uses the new UI elements to display them in an interactive grid. Following these techniques will lead to more sophisticated and engaging user experiences for your Android apps.