mirror of
https://github.com/MinimalBible/MinimalBible-Legacy
synced 2024-11-16 04:58:26 -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.MinimalBible;
|
||||||
import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadManager;
|
import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadManager;
|
||||||
import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadThread;
|
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.DownloadManager;
|
||||||
import org.bspeice.minimalbible.activities.downloader.manager.InstalledManager;
|
import org.bspeice.minimalbible.activities.downloader.manager.InstalledManager;
|
||||||
import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager;
|
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.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
import de.devland.esperandro.Esperandro;
|
import de.devland.esperandro.Esperandro;
|
||||||
import de.greenrobot.event.EventBus;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module mappings for the classes under the Download Activity
|
* Module mappings for the classes under the Download Activity
|
||||||
@ -20,7 +18,6 @@ import de.greenrobot.event.EventBus;
|
|||||||
injects = {
|
injects = {
|
||||||
BookListFragment.class,
|
BookListFragment.class,
|
||||||
DownloadManager.class,
|
DownloadManager.class,
|
||||||
BookRefreshTask.class,
|
|
||||||
BookItemHolder.class,
|
BookItemHolder.class,
|
||||||
BookDownloadManager.class,
|
BookDownloadManager.class,
|
||||||
BookDownloadThread.class,
|
BookDownloadThread.class,
|
||||||
@ -30,11 +27,6 @@ import de.greenrobot.event.EventBus;
|
|||||||
)
|
)
|
||||||
public class ActivityDownloaderModule {
|
public class ActivityDownloaderModule {
|
||||||
|
|
||||||
@Provides
|
|
||||||
EventBus provideBus() {
|
|
||||||
return new EventBus();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides //@Singleton
|
@Provides //@Singleton
|
||||||
DownloadPrefs provideDownloadPrefs() {
|
DownloadPrefs provideDownloadPrefs() {
|
||||||
return Esperandro.getPreferences(DownloadPrefs.class, MinimalBible.getAppContext());
|
return Esperandro.getPreferences(DownloadPrefs.class, MinimalBible.getAppContext());
|
||||||
|
@ -22,6 +22,9 @@ import javax.inject.Inject;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.InjectView;
|
import butterknife.InjectView;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
import rx.Subscription;
|
||||||
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
|
import rx.functions.Action1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by bspeice on 5/20/14.
|
* 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_ibtn_download) ImageButton isDownloaded;
|
||||||
@InjectView(R.id.download_prg_download) ProgressWheel downloadProgress;
|
@InjectView(R.id.download_prg_download) ProgressWheel downloadProgress;
|
||||||
|
|
||||||
@Inject DownloadManager downloadManager;
|
|
||||||
@Inject BookDownloadManager bookDownloadManager;
|
@Inject BookDownloadManager bookDownloadManager;
|
||||||
@Inject InstalledManager installedManager;
|
@Inject InstalledManager installedManager;
|
||||||
|
|
||||||
Book b;
|
Book b;
|
||||||
|
Subscription subscription;
|
||||||
|
|
||||||
public BookItemHolder(View v, Book b) {
|
public BookItemHolder(View v, Book b) {
|
||||||
ButterKnife.inject(this, v);
|
ButterKnife.inject(this, v);
|
||||||
@ -57,7 +60,10 @@ public class BookItemHolder {
|
|||||||
} else if (installedManager.isInstalled(b)) {
|
} else if (installedManager.isInstalled(b)) {
|
||||||
displayInstalled();
|
displayInstalled();
|
||||||
}
|
}
|
||||||
downloadManager.getDownloadBus().register(this);
|
//TODO: Refactor
|
||||||
|
subscription = bookDownloadManager.getDownloadEvents()
|
||||||
|
.subscribeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe((event) -> onEventMainThread(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayInstalled() {
|
private void displayInstalled() {
|
||||||
@ -134,6 +140,6 @@ public class BookItemHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onScrollOffscreen() {
|
public void onScrollOffscreen() {
|
||||||
downloadManager.getDownloadBus().unregister(this);
|
subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,6 @@ public class BookDownloadManager implements WorkListener, BooksListener {
|
|||||||
@Inject
|
@Inject
|
||||||
Provider<BookDownloadThread> dlThreadProvider;
|
Provider<BookDownloadThread> dlThreadProvider;
|
||||||
|
|
||||||
@Inject DownloadManager downloadManager;
|
|
||||||
|
|
||||||
public BookDownloadManager() {
|
public BookDownloadManager() {
|
||||||
bookMappings = new HashMap<String, Book>();
|
bookMappings = new HashMap<String, Book>();
|
||||||
inProgressDownloads = new HashMap<Book, DLProgressEvent>();
|
inProgressDownloads = new HashMap<Book, DLProgressEvent>();
|
||||||
@ -102,6 +100,10 @@ public class BookDownloadManager implements WorkListener, BooksListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PublishSubject<DLProgressEvent> getDownloadEvents() {
|
||||||
|
return downloadEvents;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void workStateChanged(WorkEvent ev) {
|
public void workStateChanged(WorkEvent ev) {
|
||||||
Log.d("BookDownloadManager", ev.toString());
|
Log.d("BookDownloadManager", ev.toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user