From 28dfec81d71993a2610e494be6d60eeb3620f909 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Tue, 10 Jun 2014 23:17:20 -0400 Subject: [PATCH] [broken probably] Refactoring to Rx should be done... But having issues with compiling. Checking if Dagger and retrolambda play nice. --- .../downloader/BookListFragment.java | 1 - .../manager/BookDownloadThread.java | 31 +++++++++---------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java index 8858a74..d769c61 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java @@ -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; diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadThread.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadThread.java index 70edeec..409bd50 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadThread.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadThread.java @@ -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(); }