mirror of
https://github.com/MinimalBible/MinimalBible-Legacy
synced 2024-12-22 06:38:28 -05:00
[broken] BookItemHolder to Rx
This commit is contained in:
parent
e356c8d1fc
commit
6eb5f66dcc
@ -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());
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -48,8 +48,6 @@ public class BookDownloadManager implements WorkListener, BooksListener {
|
||||
@Inject
|
||||
Provider<BookDownloadThread> dlThreadProvider;
|
||||
|
||||
@Inject DownloadManager downloadManager;
|
||||
|
||||
public BookDownloadManager() {
|
||||
bookMappings = new HashMap<String, Book>();
|
||||
inProgressDownloads = new HashMap<Book, DLProgressEvent>();
|
||||
@ -102,6 +100,10 @@ public class BookDownloadManager implements WorkListener, BooksListener {
|
||||
}
|
||||
}
|
||||
|
||||
public PublishSubject<DLProgressEvent> getDownloadEvents() {
|
||||
return downloadEvents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void workStateChanged(WorkEvent ev) {
|
||||
Log.d("BookDownloadManager", ev.toString());
|
||||
|
Loading…
Reference in New Issue
Block a user