From dda5c792997c148c720c8bf75a554c9001202e98 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sat, 14 Jun 2014 15:04:17 -0400 Subject: [PATCH] Fix books not being removed... --- .../activities/downloader/BookItemHolder.java | 12 ++++-------- .../downloader/manager/BookDownloadManager.java | 1 + .../downloader/manager/InstalledManager.java | 8 +++++++- .../downloader/manager/RefreshManager.java | 1 + 4 files changed, 13 insertions(+), 9 deletions(-) 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 6a4095d..c5e4b8b 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 @@ -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()); 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 26ce3ae..ef04d1d 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 @@ -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 diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/InstalledManager.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/InstalledManager.java index 0279c4b..b17a136 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/InstalledManager.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/InstalledManager.java @@ -21,6 +21,7 @@ public class InstalledManager implements BooksListener { private Books installedBooks; private List 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()); } diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java index cc794e4..98948a8 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java @@ -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.