Join Albert Lo for an in-depth discussion in this video Picasa API calls, part of Android Development: Modern Android UI Design Elements.
- [Commentator] Now we are back in our Google photos fragment. If you see a build warning for fragment Google photos layout here, you may want to do a clean before proceeding. Now let's go ahead and initialize our swipe refresh layout. We will call the fine view by ID.
Now I notice I have not defined the view ID for our swipe refresh layout, so let's go ahead and do that. I'm going to press Command+C and we switch over to our fragment Google photos layout, we go to our swipe refresh layout, and we're going to add our view ID here. And press Command+V to define our view ID swipe refresh layout, now let's switch back to Google photos fragment. Now we have our view.
Let's go ahead and define a class member swipe refresh layout, 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 we swipe down on the screen, we want to make a one time check to see whether our picasa client library is initialized and if it is, load our albums.
Let's make one call before we add our listener. We're going to make a method call, set color scheme colors on refresh layout. And we're going to pass in our accent color using our context compat get color. Again I'm going to pass in our color resource called color accent. Now we're ready to add our listener, let's call set on refresh listener.
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 is press Alt+Return and select add dependency Google photos library. Now let's add a method, the private method will be load 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 going to set our refresh layout progress animation, so let's do 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 make a 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 define our callbacks. In our on success callback, what we will do is make another call 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 define another 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 here to 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 dismiss our progress animation. The other thing we will do here is call the adapter to load our photos, but we haven't defined our recycler view 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 have a very similar RX Java call. The difference is we have an album ID and we're going to pass that in.
Load photos will do two things. And it'll be similar to load albums, the first is to set the progress animation on refresh layout, let's do that here. And the next one is the RX Java call, it will look similar to 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 like for load albums. And we're going to set up subscribers here. So now we have the on success and the on error callback for our load photos. In the on success, we're going to create a new method on load photos finish.
And pass in our album feed. In the on error callback we will call handle error just like we did for load album. Now let's define on load photos finish, it's a private 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 will call 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 with load albums.
- Creating a custom layout with XML
- Setting up OnClick handlers
- Making API calls
- Creating custom views
- Implementing ViewHolder objects
- Signing certificates
- Adding a checkbox