// Path: app/src/main/java/app/data/foundation/UIUtils.java
// public interface UIUtils {
//     String getLang();
//     String getString(@StringRes int idResource);
//     File getFilesDir();
// }
// 
// Path: app/src/main/java/app/data/sections/WireframeRepository.java
// public class WireframeRepository extends Repository {
// 
//     @Inject public WireframeRepository(RestApi restApi, RxProviders rxProviders, UIUtils uiUtils) {
//         super(restApi, rxProviders, uiUtils);
//     }
// 
//     public <T> Observable<T> getWireframeCurrentObject() {
//         return rxProviders
//                 .<T>getWireframeCurrentObject(Observable.just(null), new EvictProvider(false))
//                 .doOnError(throwable -> {
//                     throw new WireframeException();
//                 });
//     }
// 
//     public Observable<Void> setWireframeCurrentObject(Object object) {
//         return rxProviders.getWireframeCurrentObject(Observable.just(object), new EvictProvider(true))
//                 .map(_I -> null);
//     }
// 
//     public class WireframeException extends RuntimeException {
// 
//         public WireframeException() {
//             super("There is not cached object in the wireframe");
//         }
// 
//     }
// }
// 
// Path: app/src/main/java/app/data/sections/user_demo/UserRepository.java
// public class UserRepository extends Repository {
//     public static final int USERS_PER_PAGE = 50, MAX_USERS_TO_LOAD = 300;
// 
//     @Inject public UserRepository(RestApi restApi, RxProviders rxProviders, UIUtils uiUtils) {
//         super(restApi, rxProviders, uiUtils);
//     }
// 
//     @RxLogObservable
//     public Observable<List<User>> getUsers(Integer lastIdQueried, final boolean refresh) {
//         lastIdQueried = lastIdQueried == null ? FIRST_ID_QUERIED : lastIdQueried;
// 
//         Observable<List<User>> loader = restApi.getUsers(lastIdQueried, USERS_PER_PAGE).map(response -> {
//             handleError(response);
//             return response.body();
//         });
// 
// 
//         if (lastIdQueried == FIRST_ID_QUERIED) {
//             loader = rxProviders.getUsers(loader, new DynamicKey(lastIdQueried), new EvictProvider(refresh));
//         }
// 
//         return loader;
//     }
// 
//     @RxLogObservable
//     public Observable<User> searchByUserName(final String  username) {
//         return restApi.getUserByName(username).map(response -> {
//             handleError(response);
//             final User user = response.body();
//             return user;
//         });
//     }
// }
// 
// Path: app/src/main/java/app/domain/user_demo/User.java
// @Data
// public class User {
//     private final int id;
//     private String login;
//     private String avatar_url = "";
// 
//     public String getAvatarUrl() {
//         if (avatar_url.isEmpty()) return avatar_url;
//         return avatar_url.split("\\?")[0];
//     }
// }
// 
// Path: app/src/main/java/app/presentation/foundation/PresenterFragment.java
// public abstract class PresenterFragment {
//     protected final WireframeRepository wireframeRepository;
//     protected final UIUtils uiUtils;
// 
//     protected PresenterFragment(WireframeRepository wireframeRepository, UIUtils uiUtils) {
//         this.wireframeRepository = wireframeRepository;
//         this.uiUtils = uiUtils;
//     }
// 
//     public Observable<Void> dataForNextScreen(Object data) {
//         return wireframeRepository.setWireframeCurrentObject(data);
//     }
// }


import android.text.TextUtils;
import java.util.List;
import javax.inject.Inject;
import app.data.foundation.UIUtils;
import app.data.sections.WireframeRepository;
import app.data.sections.user_demo.UserRepository;
import app.domain.user_demo.User;
import app.presentation.foundation.PresenterFragment;
import rx.Observable;
package app.presentation.sections.user_demo.list;





/**
 * Created by victor on 08/04/16.
 */
public class UsersPresenter extends PresenterFragment {
    private final UserRepository repository;

    @Inject public UsersPresenter(WireframeRepository wireframeRepository, UserRepository repository, UIUtils uiUtils) {
        super(wireframeRepository, uiUtils);
        this.repository = repository;
    }

    public Observable<List<User>> nextPage(User user, String query) {
        Integer id = null;
        if (user != null) id = user.getId();

        return filter(repository.getUsers(id, false), query);
    }

    public Observable<List<User>> refreshList(String query) {
        return filter(repository.getUsers(0, true), query);
    }

    private Observable<List<User>> filter(Observable<List<User>> oUsers, String query) {
        if (TextUtils.isEmpty(query)) return oUsers;

        return oUsers
                .flatMapIterable(users -> users)
// Path: app/src/main/java/app/data/foundation/UIUtils.java
// public interface UIUtils {
//     String getLang();
//     String getString(@StringRes int idResource);
//     File getFilesDir();
// }
// 
// Path: app/src/main/java/app/data/sections/WireframeRepository.java
// public class WireframeRepository extends Repository {
// 
//     @Inject public WireframeRepository(RestApi restApi, RxProviders rxProviders, UIUtils uiUtils) {
//         super(restApi, rxProviders, uiUtils);
//     }
// 
//     public <T> Observable<T> getWireframeCurrentObject() {
//         return rxProviders
//                 .<T>getWireframeCurrentObject(Observable.just(null), new EvictProvider(false))
//                 .doOnError(throwable -> {
//                     throw new WireframeException();
//                 });
//     }
// 
//     public Observable<Void> setWireframeCurrentObject(Object object) {
//         return rxProviders.getWireframeCurrentObject(Observable.just(object), new EvictProvider(true))
//                 .map(_I -> null);
//     }
// 
//     public class WireframeException extends RuntimeException {
// 
//         public WireframeException() {
//             super("There is not cached object in the wireframe");
//         }
// 
//     }
// }
// 
// Path: app/src/main/java/app/data/sections/user_demo/UserRepository.java
// public class UserRepository extends Repository {
//     public static final int USERS_PER_PAGE = 50, MAX_USERS_TO_LOAD = 300;
// 
//     @Inject public UserRepository(RestApi restApi, RxProviders rxProviders, UIUtils uiUtils) {
//         super(restApi, rxProviders, uiUtils);
//     }
// 
//     @RxLogObservable
//     public Observable<List<User>> getUsers(Integer lastIdQueried, final boolean refresh) {
//         lastIdQueried = lastIdQueried == null ? FIRST_ID_QUERIED : lastIdQueried;
// 
//         Observable<List<User>> loader = restApi.getUsers(lastIdQueried, USERS_PER_PAGE).map(response -> {
//             handleError(response);
//             return response.body();
//         });
// 
// 
//         if (lastIdQueried == FIRST_ID_QUERIED) {
//             loader = rxProviders.getUsers(loader, new DynamicKey(lastIdQueried), new EvictProvider(refresh));
//         }
// 
//         return loader;
//     }
// 
//     @RxLogObservable
//     public Observable<User> searchByUserName(final String  username) {
//         return restApi.getUserByName(username).map(response -> {
//             handleError(response);
//             final User user = response.body();
//             return user;
//         });
//     }
// }
// 
// Path: app/src/main/java/app/domain/user_demo/User.java
// @Data
// public class User {
//     private final int id;
//     private String login;
//     private String avatar_url = "";
// 
//     public String getAvatarUrl() {
//         if (avatar_url.isEmpty()) return avatar_url;
//         return avatar_url.split("\\?")[0];
//     }
// }
// 
// Path: app/src/main/java/app/presentation/foundation/PresenterFragment.java
// public abstract class PresenterFragment {
//     protected final WireframeRepository wireframeRepository;
//     protected final UIUtils uiUtils;
// 
//     protected PresenterFragment(WireframeRepository wireframeRepository, UIUtils uiUtils) {
//         this.wireframeRepository = wireframeRepository;
//         this.uiUtils = uiUtils;
//     }
// 
//     public Observable<Void> dataForNextScreen(Object data) {
//         return wireframeRepository.setWireframeCurrentObject(data);
//     }
// }


// Path: app/src/main/java/app/presentation/sections/user_demo/list/UsersPresenter.java
import android.text.TextUtils;
import java.util.List;
import javax.inject.Inject;
import app.data.foundation.UIUtils;
import app.data.sections.WireframeRepository;
import app.data.sections.user_demo.UserRepository;
import app.domain.user_demo.User;
import app.presentation.foundation.PresenterFragment;
import rx.Observable;

package app.presentation.sections.user_demo.list;





/**
 * Created by victor on 08/04/16.
 */
public class UsersPresenter extends PresenterFragment {
    private final UserRepository repository;

    @Inject public UsersPresenter(WireframeRepository wireframeRepository, UserRepository repository, UIUtils uiUtils) {
        super(wireframeRepository, uiUtils);
        this.repository = repository;
    }

    public Observable<List<User>> nextPage(User user, String query) {
        Integer id = null;
        if (user != null) id = user.getId();

        return filter(repository.getUsers(id, false), query);
    }

    public Observable<List<User>> refreshList(String query) {
        return filter(repository.getUsers(0, true), query);
    }

    private Observable<List<User>> filter(Observable<List<User>> oUsers, String query) {
        if (TextUtils.isEmpty(query)) return oUsers;

        return oUsers
                .flatMapIterable(users -> users)
                .filter(user -> user.getLogin().toLowerCase().contains(query.trim().toLowerCase()))