From 6eb5f66dcc6e3604628718cf825b9d2e07a941aa Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Tue, 10 Jun 2014 22:49:47 -0400 Subject: [PATCH] [broken] BookItemHolder to Rx --- .../downloader/ActivityDownloaderModule.java | 8 -------- .../activities/downloader/BookItemHolder.java | 12 +++++++++--- .../downloader/manager/BookDownloadManager.java | 6 ++++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/ActivityDownloaderModule.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/ActivityDownloaderModule.java index ddd351c..91614d7 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/ActivityDownloaderModule.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/ActivityDownloaderModule.java @@ -3,7 +3,6 @@ package org.bspeice.minimalbible.activities.downloader; import org.bspeice.minimalbible.MinimalBible; import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadManager; import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadThread; -import org.bspeice.minimalbible.activities.downloader.manager.BookRefreshTask; import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager; import org.bspeice.minimalbible.activities.downloader.manager.InstalledManager; import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager; @@ -11,7 +10,6 @@ import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager; import dagger.Module; import dagger.Provides; import de.devland.esperandro.Esperandro; -import de.greenrobot.event.EventBus; /** * Module mappings for the classes under the Download Activity @@ -20,7 +18,6 @@ import de.greenrobot.event.EventBus; injects = { BookListFragment.class, DownloadManager.class, - BookRefreshTask.class, BookItemHolder.class, BookDownloadManager.class, BookDownloadThread.class, @@ -30,11 +27,6 @@ import de.greenrobot.event.EventBus; ) public class ActivityDownloaderModule { - @Provides - EventBus provideBus() { - return new EventBus(); - } - @Provides //@Singleton DownloadPrefs provideDownloadPrefs() { return Esperandro.getPreferences(DownloadPrefs.class, MinimalBible.getAppContext()); diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java index 24de2d1..00cc342 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java @@ -22,6 +22,9 @@ import javax.inject.Inject; import butterknife.ButterKnife; import butterknife.InjectView; import butterknife.OnClick; +import rx.Subscription; +import rx.android.schedulers.AndroidSchedulers; +import rx.functions.Action1; /** * Created by bspeice on 5/20/14. @@ -36,11 +39,11 @@ public class BookItemHolder { @InjectView(R.id.download_ibtn_download) ImageButton isDownloaded; @InjectView(R.id.download_prg_download) ProgressWheel downloadProgress; - @Inject DownloadManager downloadManager; @Inject BookDownloadManager bookDownloadManager; @Inject InstalledManager installedManager; Book b; + Subscription subscription; public BookItemHolder(View v, Book b) { ButterKnife.inject(this, v); @@ -57,7 +60,10 @@ public class BookItemHolder { } else if (installedManager.isInstalled(b)) { displayInstalled(); } - downloadManager.getDownloadBus().register(this); + //TODO: Refactor + subscription = bookDownloadManager.getDownloadEvents() + .subscribeOn(AndroidSchedulers.mainThread()) + .subscribe((event) -> onEventMainThread(event)); } private void displayInstalled() { @@ -134,6 +140,6 @@ public class BookItemHolder { } public void onScrollOffscreen() { - downloadManager.getDownloadBus().unregister(this); + subscription.unsubscribe(); } } diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadManager.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadManager.java index 0bb7951..0ff8eb8 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadManager.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadManager.java @@ -48,8 +48,6 @@ public class BookDownloadManager implements WorkListener, BooksListener { @Inject Provider dlThreadProvider; - @Inject DownloadManager downloadManager; - public BookDownloadManager() { bookMappings = new HashMap(); inProgressDownloads = new HashMap(); @@ -102,6 +100,10 @@ public class BookDownloadManager implements WorkListener, BooksListener { } } + public PublishSubject getDownloadEvents() { + return downloadEvents; + } + @Override public void workStateChanged(WorkEvent ev) { Log.d("BookDownloadManager", ev.toString());