From b0327dd491e376a94d6ff9bd16a1a155cb9cdfd9 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Wed, 9 Jul 2014 22:15:18 -0400 Subject: [PATCH] Continue refactoring out static fields --- .../downloader/DownloadActivityModules.java | 17 +++++++++++- .../downloader/manager/InstalledManager.java | 26 +++++-------------- .../activity/viewer/BookFragment.java | 2 +- app/src/main/res/values/html_strings.xml | 3 ++- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java index 73a8e6d..d45b16c 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java @@ -4,8 +4,11 @@ import org.bspeice.minimalbible.Injector; import org.bspeice.minimalbible.MinimalBibleModules; import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadManager; import org.bspeice.minimalbible.activity.downloader.manager.BookDownloadThread; +import org.bspeice.minimalbible.activity.downloader.manager.InstalledManager; import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager; +import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.BookCategory; +import org.crosswire.jsword.book.Books; import java.util.ArrayList; import java.util.List; @@ -29,7 +32,8 @@ import de.devland.esperandro.Esperandro; BookDownloadThread.class, RefreshManager.class, DownloadNavDrawerFragment.class, - DownloadActivity.class + DownloadActivity.class, + InstalledManager.class }, addsTo = MinimalBibleModules.class ) @@ -70,4 +74,15 @@ public class DownloadActivityModules { add(BookCategory.MAPS); }}; } + + //TODO: Move this to a true async + @Provides @Singleton + Books provideInstalledBooksManager() { + return Books.installed(); + } + + @Provides + List provideInstalledBooks(Books b) { + return b.getBooks(); + } } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/InstalledManager.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/InstalledManager.java index 16a1224..aad93df 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/InstalledManager.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/InstalledManager.java @@ -2,6 +2,7 @@ package org.bspeice.minimalbible.activity.downloader.manager; import android.util.Log; +import org.bspeice.minimalbible.Injector; import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.BookException; import org.crosswire.jsword.book.Books; @@ -19,28 +20,18 @@ import javax.inject.Singleton; @Singleton public class InstalledManager implements BooksListener { - private Books installedBooks; - private List installedBooksList; + @Inject Books installedBooks; + @Inject List installedBooksList; + private String TAG = "InstalledManager"; - @Inject InstalledManager() {} - - /** - * Register our manager to receive events on Book install - * This is a relatively expensive operation, - * so we don't put it in the constructor. - */ - public void initialize() { - //TODO: Move this to a true async, rather than separate initialize() function - installedBooks = Books.installed(); - installedBooksList = installedBooks.getBooks(); + @Inject + InstalledManager(Injector injector) { + injector.inject(this); installedBooks.addBooksListener(this); } public boolean isInstalled(Book b) { - if (installedBooks == null) { - initialize(); - } return installedBooksList.contains(b); } @@ -63,9 +54,6 @@ public class InstalledManager implements BooksListener { } public void removeBook(Book b) { - if (installedBooks == null) { - initialize(); - } // Not sure why we need to call this multiple times, but... while (Books.installed().getBooks().contains(b)) { try { diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java index d0fa594..5b5f274 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java @@ -105,7 +105,7 @@ public class BookFragment extends BaseFragment { private void displayBook(Book b) { Log.d("BookFragment", b.getName()); ((BibleViewer)getActivity()).setActionBarTitle(b.getInitials()); - mainContent.loadUrl(getString(R.string.content_page)); + mainContent.loadUrl(getString(R.string.book_html)); mainContent.setWebViewClient(new WebViewClient(){ @Override public void onPageFinished(WebView view, String url) { diff --git a/app/src/main/res/values/html_strings.xml b/app/src/main/res/values/html_strings.xml index a228ccf..a163e88 100644 --- a/app/src/main/res/values/html_strings.xml +++ b/app/src/main/res/values/html_strings.xml @@ -1,4 +1,5 @@ - file:///android_asset/book.html + file:///android_asset/ + file:///android_asset/book.html \ No newline at end of file