Can't fix tests, fix application instead

See documentation for more information on why I can't fix the tests to actually guarantee anything.
This commit is contained in:
Bradlee Speice
2014-07-19 23:27:49 -04:00
parent f2a4ceceff
commit d685beaae6
5 changed files with 51 additions and 32 deletions

View File

@ -1,9 +1,11 @@
package org.bspeice.minimalbible.activity.downloader;
import android.content.Context;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.todddavies.components.progressbar.ProgressWheel;
@ -15,6 +17,7 @@ import org.bspeice.minimalbible.activity.downloader.manager.InstalledManager;
import org.crosswire.jsword.book.Book;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.ButterKnife;
import butterknife.InjectView;
@ -45,6 +48,8 @@ public class BookItemHolder {
BookDownloadManager bookDownloadManager;
@Inject
InstalledManager installedManager;
@Inject @Named("DownloadActivityContext")
Context ctx;
private final Book b;
private Subscription subscription;
@ -90,8 +95,13 @@ public class BookItemHolder {
public void onDownloadItem(View v) {
if (installedManager.isInstalled(b)) {
// Remove the book
installedManager.removeBook(b);
isDownloaded.setImageResource(R.drawable.ic_action_download);
boolean didRemove = installedManager.removeBook(b);
if (didRemove) {
isDownloaded.setImageResource(R.drawable.ic_action_download);
} else {
Toast.makeText(ctx, "Unable to remove book, might need to restart the application."
, Toast.LENGTH_SHORT).show();
}
} else {
bookDownloadManager.installBook(this.b);
}

View File

@ -1,5 +1,7 @@
package org.bspeice.minimalbible.activity.downloader;
import android.content.Context;
import org.bspeice.minimalbible.Injector;
import org.bspeice.minimalbible.MinimalBibleModules;
import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadManager;
@ -59,6 +61,16 @@ public class DownloadActivityModules {
return activity;
}
/**
* Provide the context for the DownloadActivity. We name it so that we don't have to
* \@Provides a specific class, but can keep track of what exactly we mean by "Context"
* @return
*/
@Provides @Singleton @Named("DownloadActivityContext")
Context provideActivityContext() {
return activity;
}
@Provides @Singleton
BookDownloadManager provideBookDownloadManager() {
return new BookDownloadManager(activity);

View File

@ -62,14 +62,23 @@ public class InstalledManager implements BooksListener {
}
}
public void removeBook(Book b) {
/**
* Remove a book from being installed.
* Currently only supports books that have been installed outside the current application run.
* Not quite sure why this is, but And-Bible exhibits the same behavior.
* @param b The book to remove
* @return Whether the book was removed.
*/
public boolean removeBook(Book b) {
try {
// This worked in the past, but isn't now...
// installedBooks.remove(b);
Book realBook = installedBooks.getBook(b.getInitials());
b.getDriver().delete(realBook);
return true;
} catch (BookException e) {
Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage());
return false;
}
}
}