[broken probably] Refactoring to Rx should be done...

But having issues with compiling. Checking if Dagger and retrolambda
play nice.
Rx/Retrolambda
Bradlee Speice 2014-06-10 23:17:20 -04:00
parent fb0c5fdaaa
commit 28dfec81d7
2 changed files with 14 additions and 18 deletions

View File

@ -16,7 +16,6 @@ import org.bspeice.minimalbible.MinimalBible;
import org.bspeice.minimalbible.R;
import org.bspeice.minimalbible.activities.BaseFragment;
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
import org.bspeice.minimalbible.activities.downloader.manager.EventBookList;
import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager;
import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.book.BookCategory;

View File

@ -18,8 +18,9 @@ public class BookDownloadThread {
private final String TAG = "BookDownloadThread";
@Inject
DownloadManager downloadManager;
@Inject RefreshManager refreshManager;
BookDownloadManager bookDownloadManager;
@Inject
RefreshManager refreshManager;
public BookDownloadThread() {
MinimalBible.getApplication().inject(this);
@ -29,31 +30,27 @@ public class BookDownloadThread {
// So, the JobManager can't be injected, but we'll make do
// First, look up where the Book came from
final Installer i = refreshManager.installerFromBook(b);
refreshManager.installerFromBook(b)
.subscribe((installer) -> {
try {
installer.install(b);
} catch (InstallException e) {
Log.d(TAG, e.getMessage());
}
final Thread worker = new Thread() {
@Override
public void run() {
try {
i.install(b);
} catch (InstallException e) {
Log.d(TAG, e.getMessage());
}
}
};
worker.start();
// The worker automatically communicates with the JobManager for its progress.
downloadManager.getDownloadBus().post(new DLProgressEvent(DLProgressEvent.PROGRESS_BEGINNING, b));
bookDownloadManager.getDownloadEvents().onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_BEGINNING, b));
});
}
/**
* Build what the installer creates the job name as.
* Likely prone to be brittle.
* TODO: Make sure to test that this is an accurate job name
*
* @param b The book to predict the download job name of
* @return The name of the job that will/is download/ing this book
*/
public static String getJobId(Book b) {
return "INSTALL_BOOK-" + b.getInitials();
}