Fix books not being removed...

This commit is contained in:
Bradlee Speice 2014-06-14 15:04:17 -04:00
parent 93abe065a2
commit dda5c79299
4 changed files with 13 additions and 9 deletions

View File

@ -58,8 +58,9 @@ public class BookItemHolder {
}
//TODO: Refactor
subscription = bookDownloadManager.getDownloadEvents()
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe((event) -> onEventMainThread(event));
.observeOn(AndroidSchedulers.mainThread())
.filter((event) -> event.getB().getInitials() == b.getInitials())
.subscribe((event) -> displayProgress((int)event.toCircular()));
}
private void displayInstalled() {
@ -77,12 +78,6 @@ public class BookItemHolder {
}
}
public void onEventMainThread(DLProgressEvent event) {
if (event.getB().getOsisID().equals(b.getOsisID())) {
displayProgress((int) event.toCircular());
}
}
/**
* Display the current progress of this download
* @param progress The progress out of 360 (degrees of a circle)
@ -121,6 +116,7 @@ public class BookItemHolder {
downloadProgress.setProgress(progress);
} else {
// Download complete
subscription.unsubscribe();
RelativeLayout.LayoutParams acronymParams =
(RelativeLayout.LayoutParams)acronym.getLayoutParams();
acronymParams.addRule(RelativeLayout.LEFT_OF, isDownloaded.getId());

View File

@ -72,6 +72,7 @@ public class BookDownloadManager implements WorkListener, BooksListener {
if (job.getWorkDone() == job.getTotalWork()) {
// Download is complete
inProgressDownloads.remove(bookMappings.get(job.getJobID()));
bookMappings.remove(job.getJobID());
downloadEvents.onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_COMPLETE, b));
} else {
// Track the ongoing download

View File

@ -21,6 +21,7 @@ public class InstalledManager implements BooksListener {
private Books installedBooks;
private List<Book> installedBooksList;
private String TAG = "InstalledManager";
@Inject InstalledManager() {}
@ -45,6 +46,7 @@ public class InstalledManager implements BooksListener {
@Override
public void bookAdded(BooksEvent booksEvent) {
Log.d(TAG, "Book added: " + booksEvent.getBook().toString());
Book b = booksEvent.getBook();
if (!installedBooksList.contains(b)) {
installedBooksList.add(b);
@ -53,6 +55,7 @@ public class InstalledManager implements BooksListener {
@Override
public void bookRemoved(BooksEvent booksEvent) {
Log.d(TAG, "Book removed: " + booksEvent.getBook().toString());
Book b = booksEvent.getBook();
if (installedBooksList.contains(b)) {
installedBooksList.remove(b);
@ -61,7 +64,10 @@ public class InstalledManager implements BooksListener {
public void removeBook(Book b) {
try {
installedBooks.removeBook(b);
// This worked in the past, but isn't now...
// installedBooks.remove(b);
Book realBook = installedBooks.getBook(b.getInitials());
b.getDriver().delete(realBook);
} catch (BookException e) {
Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage());
}

View File

@ -28,6 +28,7 @@ import rx.schedulers.Schedulers;
public class RefreshManager {
@Inject DownloadManager downloadManager;
@Inject InstalledManager installedManager;
/**
* Cached copy of modules that are available so we don't refresh for everyone who requests it.