package com.yosriz.gphotosclient;

import com.google.android.gms.auth.api.signin.GoogleSignInAccount;

import com.yosriz.gphotosclient.model.AlbumEntry;
import com.yosriz.gphotosclient.model.AlbumFeed;
import com.yosriz.gphotosclient.model.AlbumFeedResponse;
import com.yosriz.gphotosclient.model.UserFeed;
import com.yosriz.gphotosclient.model.UserFeedResponse;

import io.reactivex.Single;
import io.reactivex.schedulers.Schedulers;


public class GooglePhotosService {

    private final PicasaApi picasaApi;
    private final GoogleSignInAccount account;

    GooglePhotosService(PicasaApi picasaApi,
                        GoogleSignInAccount account) {
        this.picasaApi = picasaApi;
        this.account = account;
    }

    public Single<UserFeed> getUserFeed() {
        return picasaApi.getUserFeedResponse()
                .map(UserFeedResponse::getFeed)
                .subscribeOn(Schedulers.io());
    }

    public Single<UserFeed> getUserFeed(int startIndex, int maxResults) {
        if (startIndex < 1) {
            throw new IllegalArgumentException("Illegal start index, must be above 0");
        }
        return picasaApi.getUserFeedResponse(startIndex, maxResults)
                .map(UserFeedResponse::getFeed)
                .subscribeOn(Schedulers.io());
    }

    public Single<AlbumFeed> getAlbumFeed(long albumId) {
        return picasaApi.getAlbumFeedResponse(albumId)
                .map(AlbumFeedResponse::getFeed)
                .subscribeOn(Schedulers.io());

    }

    public Single<AlbumFeed> getAlbumFeed(long albumId, int startIndex, int maxResults) {
        if (startIndex < 1) {
            throw new IllegalArgumentException("Illegal start index, must be above 0");
        }
        return picasaApi.getAlbumFeedResponse(albumId, startIndex, maxResults)
                .map(AlbumFeedResponse::getFeed)
                .subscribeOn(Schedulers.io());
    }

    public Single<AlbumEntry> getGooglePhotosInstantUploadAlbum() {
        return getUserFeed()
                .flattenAsObservable(UserFeed::getAlbumEntries)
                .filter(albumEntry -> AlbumEntry.TYPE_GOOGLE_PHOTOS_INSTANT_UPLOAD.equals(albumEntry.getGphotoAlbumType()))
                .firstOrError();
    }

    public GoogleSignInAccount getAccount() {
        return account;
    }
}

@@ -91,25 +91,24 @@
 nInAccount;%0A
-%0A
 import com.y
@@ -735,786 +735,1930 @@
     
-public Single%3CUserFeed%3E getUserFeed() %7B%0A        return picasaApi.getUserFeedResponse()%0A                .map(UserFeedResponse::getFeed)%0A                .subscribeOn(Schedulers.io());%0A    %7D%0A%0A    public Single%3CUserFeed%3E getUserFeed(int startIndex, int maxResults) %7B%0A        if (startIndex %3C 1) %7B%0A            throw new IllegalArgumentException(%22Illegal start index, must be above 0%22);%0A        %7D%0A        return picasaApi.getUserFeedResponse(startIndex, maxResults)%0A                .map(UserFeedResponse::getFeed)%0A                .subscribeOn(Schedulers.io());%0A    %7D%0A%0A    public Single%3CAlbumFeed%3E getAlbumFeed(long albumId) %7B%0A        return picasaApi.getAlbumFeedResponse(albumId)%0A                .map(AlbumFeedResponse::getFeed)%0A                .subscribeOn(Schedulers.io());%0A%0A    %7D%0A
+/**%0A     * Get user feed, feed contains all user various albums and photos collection.%0A     * %3Cp%3Ethere's a limit of 1,000 albums per response, for getting paged result use %7B@link #getUserFeed(int, int)%7D.%3C/p%3E%0A     *%0A     * @return %7B@link UserFeed%7D object.%0A     */%0A    public Single%3CUserFeed%3E getUserFeed() %7B%0A        return picasaApi.getUserFeedResponse()%0A                .map(UserFeedResponse::getFeed)%0A                .subscribeOn(Schedulers.io());%0A    %7D%0A%0A    /**%0A     * Get user feed, feed contains all user various albums and photos collection.%0A     *%0A     * @param startIndex start album index (first index is 1)%0A     * @param maxResults max results%0A     * @return %7B@link UserFeed%7D object.%0A     */%0A    public Single%3CUserFeed%3E getUserFeed(int startIndex, int maxResults) %7B%0A        if (startIndex %3C 1) %7B%0A            throw new IllegalArgumentException(%22Illegal start index, must be above 0%22);%0A        %7D%0A        return picasaApi.getUserFeedResponse(startIndex, maxResults)%0A                .map(UserFeedResponse::getFeed)%0A                .subscribeOn(Schedulers.io());%0A    %7D%0A%0A    /**%0A     * Get album feed by id. %7B@link AlbumFeed%7D photos can be retrieved using %7B@link AlbumFeed#getPhotoEntries()%7D.%0A     * %3Cp%3Ethere's a limit of 1,000 photos per response, for getting paged result use %7B@link #getAlbumFeed(long, int, int)%7D.%3C/p%3E%0A     *%0A     * @param albumId album id%0A     * @return %7B@link AlbumFeed%7D%0A     */%0A    public Single%3CAlbumFeed%3E getAlbumFeed(long albumId) %7B%0A        return picasaApi.getAlbumFeedResponse(albumId)%0A                .map(AlbumFeedResponse::getFeed)%0A                .subscribeOn(Schedulers.io());%0A%0A    %7D%0A%0A    /**%0A     * Get album feed by id. %7B@link AlbumFeed%7D photos can be retrieved using %7B@link AlbumFeed#getPhotoEntries()%7D.%0A     *%0A     * @param albumId    album id%0A     * @param startIndex start photo index (first index is 1)%0A     * @param maxResults max results%0A     * @return %7B@link AlbumFeed%7D%0A     */
 %0A   
@@ -3046,32 +3046,237 @@
 s.io());%0A    %7D%0A%0A
+    /**%0A     * Get Instant upload album, this album, contains all photos that are backed up automatically by Google Photos.%0A     *%0A     * @return %7B@link AlbumEntry%7D represents instant upload album%0A     */%0A
     public Singl

add some documentation