// Path: sample/src/main/java/com/agna/ferro/sample/domain/Book.java
// public class Book {
//     private String id;
//     private String name;
//     private int downloadProgress;
//     private String imageUrl;
// 
//     public Book(String id, String name, String imageUrl) {
//         this.id = id;
//         this.name = name;
//         this.imageUrl = imageUrl;
//         this.downloadProgress = -1;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public String getImageUrl() {
//         return imageUrl;
//     }
// 
//     public boolean isDownloaded() {
//         return downloadProgress == 100;
//     }
// 
//     public boolean isDownloading() {
//         return downloadProgress >= 0;
//     }
// 
//     public int getDownloadProgress() {
//         return downloadProgress;
//     }
// 
//     public void setDownloadProgress(int downloadProgress) {
//         this.downloadProgress = downloadProgress;
//     }
// }


import android.content.Context;
import com.agna.ferro.mvp.component.scope.PerApplication;
import com.agna.ferro.sample.R;
import com.agna.ferro.sample.domain.Book;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import rx.Observable;
import rx.subjects.PublishSubject;

    /**
     * @return description for book with bookId
     */
    public Observable<String> getBookDescription(String bookId) {
        return Observable.just(appContext.getString(R.string.test_book_description));
    }

    /**
     * start download book, events about updating book can receive via {@link #observeChangingBooks()}
     */
    public void startDownload(String bookId) {
        imitateDownloading(bookId);
    }

    private void imitateDownloading(String bookId) {
        List<Integer> percents = Arrays.asList(5, 17, 33, 50, 66, 81, 92, 100);
        Observable.zip(
                Observable.interval(600, TimeUnit.MILLISECONDS),
                Observable.from(percents),
                (t, percent) -> percent)
                .doOnNext(percent -> updateBook(bookId, percent))
                .subscribe();


    }

    /**
     * emit event, when book changed
     */
// Path: sample/src/main/java/com/agna/ferro/sample/domain/Book.java
// public class Book {
//     private String id;
//     private String name;
//     private int downloadProgress;
//     private String imageUrl;
// 
//     public Book(String id, String name, String imageUrl) {
//         this.id = id;
//         this.name = name;
//         this.imageUrl = imageUrl;
//         this.downloadProgress = -1;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public String getImageUrl() {
//         return imageUrl;
//     }
// 
//     public boolean isDownloaded() {
//         return downloadProgress == 100;
//     }
// 
//     public boolean isDownloading() {
//         return downloadProgress >= 0;
//     }
// 
//     public int getDownloadProgress() {
//         return downloadProgress;
//     }
// 
//     public void setDownloadProgress(int downloadProgress) {
//         this.downloadProgress = downloadProgress;
//     }
// }


// Path: sample/src/main/java/com/agna/ferro/sample/interactor/book/BookRepository.java
import android.content.Context;
import com.agna.ferro.mvp.component.scope.PerApplication;
import com.agna.ferro.sample.R;
import com.agna.ferro.sample.domain.Book;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import rx.Observable;
import rx.subjects.PublishSubject;


    /**
     * @return description for book with bookId
     */
    public Observable<String> getBookDescription(String bookId) {
        return Observable.just(appContext.getString(R.string.test_book_description));
    }

    /**
     * start download book, events about updating book can receive via {@link #observeChangingBooks()}
     */
    public void startDownload(String bookId) {
        imitateDownloading(bookId);
    }

    private void imitateDownloading(String bookId) {
        List<Integer> percents = Arrays.asList(5, 17, 33, 50, 66, 81, 92, 100);
        Observable.zip(
                Observable.interval(600, TimeUnit.MILLISECONDS),
                Observable.from(percents),
                (t, percent) -> percent)
                .doOnNext(percent -> updateBook(bookId, percent))
                .subscribe();


    }

    /**
     * emit event, when book changed
     */
    public Observable<Book> observeChangingBooks() {