// Path: app/src/main/java/org/xdty/kindle/application/Application.java
// public class Application extends android.app.Application {
// 
//     private static AppComponent sAppComponent;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         sAppComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
//     }
// 
//     public static AppComponent getAppComponent() {
//         return sAppComponent;
//     }
// 
// }
// 
// Path: app/src/main/java/org/xdty/kindle/contract/DetailContract.java
// public interface DetailContract {
// 
//     interface View extends BaseView<Presenter> {
//         void updateReview(String review);
// 
//         void openTab(String url);
//     }
// 
//     interface Presenter extends BasePresenter {
//         void start(Book itemId);
// 
//         void clickFab();
//     }
// }
// 
// Path: app/src/main/java/org/xdty/kindle/data/BookDataSource.java
// public interface BookDataSource {
// 
//     Observable<List<Book>> getDailyBooks();
// 
//     Observable<List<Book>> getFreeCnBooks();
// 
//     Observable<List<Book>> getFreeEnBooks();
// 
//     Observable<List<Book>> getBooks(Mode mode);
// 
//     Observable<List<Node>> getBookNodes(String itemId);
// 
//     Observable<List<Review>> getReviews(String itemId);
// 
//     Observable<Review> getReview(String itemId);
// 
//     Observable<Book> getBook(String itemId);
// }


import org.xdty.kindle.application.Application;
import org.xdty.kindle.contract.DetailContract;
import org.xdty.kindle.data.BookDataSource;
import org.xdty.kindle.module.Book;
import org.xdty.kindle.module.Review;
import javax.inject.Inject;
import rx.functions.Action1;
package org.xdty.kindle.presenter;




public class DetailPresenter implements DetailContract.Presenter {

    @Inject
    BookDataSource mBookDataSource;
    private DetailContract.View mView;
    private Book mBook;
    private Review mReview;

    public DetailPresenter(DetailContract.View view) {
        mView = view;
        Application.getAppComponent().inject(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void clickFab() {
        if (mBook != null) {
            mView.openTab(mBook.getUrl());
        }
    }

    @Override
    public void start(Book book) {

        mBook = book;

        if (book.getEditorialReview() == null) {
            mBookDataSource.getReview(book.getItemId()).subscribe(new Action1<Review>() {
                @Override
                public void call(Review review) {
                    mReview = review;
                    mView.updateReview(review.getEditorialReview());
                }
// Path: app/src/main/java/org/xdty/kindle/application/Application.java
// public class Application extends android.app.Application {
// 
//     private static AppComponent sAppComponent;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         sAppComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
//     }
// 
//     public static AppComponent getAppComponent() {
//         return sAppComponent;
//     }
// 
// }
// 
// Path: app/src/main/java/org/xdty/kindle/contract/DetailContract.java
// public interface DetailContract {
// 
//     interface View extends BaseView<Presenter> {
//         void updateReview(String review);
// 
//         void openTab(String url);
//     }
// 
//     interface Presenter extends BasePresenter {
//         void start(Book itemId);
// 
//         void clickFab();
//     }
// }
// 
// Path: app/src/main/java/org/xdty/kindle/data/BookDataSource.java
// public interface BookDataSource {
// 
//     Observable<List<Book>> getDailyBooks();
// 
//     Observable<List<Book>> getFreeCnBooks();
// 
//     Observable<List<Book>> getFreeEnBooks();
// 
//     Observable<List<Book>> getBooks(Mode mode);
// 
//     Observable<List<Node>> getBookNodes(String itemId);
// 
//     Observable<List<Review>> getReviews(String itemId);
// 
//     Observable<Review> getReview(String itemId);
// 
//     Observable<Book> getBook(String itemId);
// }


// Path: app/src/main/java/org/xdty/kindle/presenter/DetailPresenter.java
import org.xdty.kindle.application.Application;
import org.xdty.kindle.contract.DetailContract;
import org.xdty.kindle.data.BookDataSource;
import org.xdty.kindle.module.Book;
import org.xdty.kindle.module.Review;
import javax.inject.Inject;
import rx.functions.Action1;

package org.xdty.kindle.presenter;




public class DetailPresenter implements DetailContract.Presenter {

    @Inject
    BookDataSource mBookDataSource;
    private DetailContract.View mView;
    private Book mBook;
    private Review mReview;

    public DetailPresenter(DetailContract.View view) {
        mView = view;
        Application.getAppComponent().inject(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void clickFab() {
        if (mBook != null) {
            mView.openTab(mBook.getUrl());
        }
    }

    @Override
    public void start(Book book) {

        mBook = book;

        if (book.getEditorialReview() == null) {
            mBookDataSource.getReview(book.getItemId()).subscribe(new Action1<Review>() {
                @Override
                public void call(Review review) {
                    mReview = review;
                    mView.updateReview(review.getEditorialReview());
                }
            });