diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java index 84b4e58..b94e744 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java @@ -2,9 +2,9 @@ package org.bspeice.minimalbible.activity.viewer; import android.util.Log; -import org.bspeice.minimalbible.Injector; import org.bspeice.minimalbible.activity.navigation.ExpListNavAdapter; import org.bspeice.minimalbible.activity.viewer.bookutil.VersificationUtil; +import org.bspeice.minimalbible.service.book.VerseLookupModules; import org.crosswire.jsword.book.Book; import java.util.concurrent.atomic.AtomicReference; @@ -28,7 +28,7 @@ import rx.functions.Func1; ExpListNavDrawerFragment.class, ExpListNavAdapter.class }, - library = true + includes = VerseLookupModules.class ) public class BibleViewerModules { BibleViewer activity; @@ -37,12 +37,6 @@ public class BibleViewerModules { this.activity = activity; } - @Provides - @Singleton - Injector provideInjector() { - return activity; - } - @Provides @Singleton BibleViewerPreferences providePrefs() { 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 8d92eed..ec44dd7 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 @@ -70,9 +70,10 @@ public class BookFragment extends BaseFragment { Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_viewer_main, container, false); - ((Injector)getActivity()).inject(this); + Injector i = (Injector) getActivity(); + i.inject(this); // TODO: Defer lookup until after webview created? When exactly is WebView created? - this.lookupService = new VerseLookupService(mBook.get()); + this.lookupService = new VerseLookupService(i, mBook.get()); ButterKnife.inject(this, rootView); mainContent.getSettings().setJavaScriptEnabled(true); @@ -98,7 +99,7 @@ public class BookFragment extends BaseFragment { * Do the initial work of displaying a book. Requires setting up WebView, etc. * TODO: Get initial content from cache? * - * @param b + * @param b The book we want to display */ private void displayBook(Book b) { Log.d("BookFragment", b.getName()); @@ -117,10 +118,11 @@ public class BookFragment extends BaseFragment { } /** - * Do the heavy listing of getting the actual text for a verse + * Do the heavy lifting of getting the actual text for a verse * - * @param v + * @param v The verse to display */ + @SuppressWarnings("unused") public void displayVerse(Verse v) { Book b = mBook.get(); lookupService.getHTMLVerse(v); @@ -135,6 +137,7 @@ public class BookFragment extends BaseFragment { mainContent.loadUrl("javascript:" + function + "('" + arg.toString() + "')"); } + @SuppressWarnings("unused") private void invokeJavascript(String function, List args) { mainContent.loadUrl("javascript:" + function + "(" + joinString(",", args.toArray()) + ")"); } diff --git a/app/src/main/java/org/bspeice/minimalbible/service/book/VerseLookupModules.java b/app/src/main/java/org/bspeice/minimalbible/service/book/VerseLookupModules.java new file mode 100644 index 0000000..26976c7 --- /dev/null +++ b/app/src/main/java/org/bspeice/minimalbible/service/book/VerseLookupModules.java @@ -0,0 +1,25 @@ +package org.bspeice.minimalbible.service.book; + +import android.support.v4.util.LruCache; + +import dagger.Module; +import dagger.Provides; + +/** + * Created by bspeice on 9/1/14. + */ +@Module(injects = VerseLookupService.class) +public class VerseLookupModules { + private static final int MAX_SIZE = 1000000; // 1MB + + /** + * Create a new LruCache. We're free to create new ones since they're all backed by the file + * system anyways. + * + * @return The LruCache to use + */ + @Provides + LruCache getLruCache() { + return new LruCache(MAX_SIZE); + } +} diff --git a/app/src/main/java/org/bspeice/minimalbible/service/book/VerseLookupService.java b/app/src/main/java/org/bspeice/minimalbible/service/book/VerseLookupService.java index 844d047..0da91ac 100644 --- a/app/src/main/java/org/bspeice/minimalbible/service/book/VerseLookupService.java +++ b/app/src/main/java/org/bspeice/minimalbible/service/book/VerseLookupService.java @@ -3,6 +3,7 @@ package org.bspeice.minimalbible.service.book; import android.support.v4.util.LruCache; import android.util.Log; +import org.bspeice.minimalbible.Injector; import org.bspeice.minimalbible.service.format.osistohtml.OsisToHtmlParameters; import org.bspeice.minimalbible.service.format.osistohtml.OsisToHtmlSaxHandler; import org.crosswire.common.xml.SAXEventProvider; @@ -12,6 +13,8 @@ import org.crosswire.jsword.book.BookException; import org.crosswire.jsword.passage.Verse; import org.xml.sax.SAXException; +import javax.inject.Inject; + import rx.functions.Action1; import rx.schedulers.Schedulers; import rx.subjects.PublishSubject; @@ -29,8 +32,10 @@ import rx.subjects.PublishSubject; */ public class VerseLookupService implements Action1 { - private static final int MAX_SIZE = 1000000; // 1MB + Book book; + + @Inject LruCache cache; /** * The listener is responsible for delegating calls to cache verses. @@ -39,11 +44,11 @@ public class VerseLookupService implements Action1 { */ private PublishSubject listener = PublishSubject.create(); - public VerseLookupService(Book b) { + public VerseLookupService(Injector i, Book b) { listener.subscribeOn(Schedulers.io()) .subscribe(this); this.book = b; - this.cache = new LruCache(MAX_SIZE); + i.inject(this); } /**