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

View File

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

View File

@ -21,6 +21,7 @@ public class InstalledManager implements BooksListener {
private Books installedBooks; private Books installedBooks;
private List<Book> installedBooksList; private List<Book> installedBooksList;
private String TAG = "InstalledManager";
@Inject InstalledManager() {} @Inject InstalledManager() {}
@ -45,6 +46,7 @@ public class InstalledManager implements BooksListener {
@Override @Override
public void bookAdded(BooksEvent booksEvent) { public void bookAdded(BooksEvent booksEvent) {
Log.d(TAG, "Book added: " + booksEvent.getBook().toString());
Book b = booksEvent.getBook(); Book b = booksEvent.getBook();
if (!installedBooksList.contains(b)) { if (!installedBooksList.contains(b)) {
installedBooksList.add(b); installedBooksList.add(b);
@ -53,6 +55,7 @@ public class InstalledManager implements BooksListener {
@Override @Override
public void bookRemoved(BooksEvent booksEvent) { public void bookRemoved(BooksEvent booksEvent) {
Log.d(TAG, "Book removed: " + booksEvent.getBook().toString());
Book b = booksEvent.getBook(); Book b = booksEvent.getBook();
if (installedBooksList.contains(b)) { if (installedBooksList.contains(b)) {
installedBooksList.remove(b); installedBooksList.remove(b);
@ -61,7 +64,10 @@ public class InstalledManager implements BooksListener {
public void removeBook(Book b) { public void removeBook(Book b) {
try { 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) { } catch (BookException e) {
Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage()); Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage());
} }

View File

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