From 52573534ef3bb2e9456e7a2b83f4bfec6a7c88c5 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sun, 15 Feb 2015 22:49:42 -0500 Subject: [PATCH] SEARCHING IS NOW WORKING Needs some heavy work yet, but the core JSword functionality (the hardest part) is done. --- .../minimalbible/MinimalBibleModules.java | 29 +++++++++++++++--- .../downloader/DownloadActivityModules.java | 16 +--------- .../activity/search/SearchModules.java | 6 +--- .../downloader/manager/BookManager.kt | 7 +++-- .../manager => search}/MBIndexManager.kt | 30 +++++++------------ 5 files changed, 42 insertions(+), 46 deletions(-) rename app/src/main/kotlin/org/bspeice/minimalbible/activity/{downloader/manager => search}/MBIndexManager.kt (53%) diff --git a/app/src/main/java/org/bspeice/minimalbible/MinimalBibleModules.java b/app/src/main/java/org/bspeice/minimalbible/MinimalBibleModules.java index 0e4e535..59e86cd 100644 --- a/app/src/main/java/org/bspeice/minimalbible/MinimalBibleModules.java +++ b/app/src/main/java/org/bspeice/minimalbible/MinimalBibleModules.java @@ -3,10 +3,14 @@ package org.bspeice.minimalbible; import android.app.Application; import android.util.Log; +import org.bspeice.minimalbible.activity.search.MBIndexManager; import org.bspeice.minimalbible.activity.viewer.BibleViewerPreferences; import org.bspeice.minimalbible.service.manager.BookManager; import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.Books; +import org.crosswire.jsword.index.IndexManager; +import org.crosswire.jsword.index.IndexManagerFactory; +import org.crosswire.jsword.index.IndexStatus; import java.util.ArrayList; import java.util.List; @@ -99,7 +103,8 @@ public class MinimalBibleModules { @Provides @Named("MainBook") - Book provideMainBook(BookManager bookManager, final BibleViewerPreferences prefs) { + Book provideMainBook(BookManager bookManager, final BibleViewerPreferences prefs, + MBIndexManager indexManager) { final AtomicReference mBook = new AtomicReference(null); bookManager.getInstalledBooks() .first(new Func1() { @@ -134,15 +139,20 @@ public class MinimalBibleModules { .toBlocking().first(); prefs.defaultBookInitials(fallback.getName()); - return fallback; + mBook.set(fallback); } catch (NoSuchElementException e) { // If no books are installed, there's really nothing we can do... Log.d("BibleViewerModules", "No books are installed, so can't select a main book."); return null; } - } else { - return mBook.get(); } + + Book b = mBook.get(); + if (b.getIndexStatus() != IndexStatus.DONE) { + indexManager.buildIndex(b); + } + + return b; } @Provides @@ -150,4 +160,15 @@ public class MinimalBibleModules { BookManager bookManager(List exclude) { return new BookManager(exclude); } + + @Provides + @Singleton + IndexManager indexManager() { + return IndexManagerFactory.getIndexManager(); + } + + @Provides + MBIndexManager mbIndexManager(IndexManager indexManager) { + return new MBIndexManager(indexManager); + } } 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 1769e11..5c2c22f 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 @@ -8,15 +8,12 @@ import org.bspeice.minimalbible.MinimalBibleModules; import org.bspeice.minimalbible.activity.downloader.manager.BookManager; import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent; import org.bspeice.minimalbible.activity.downloader.manager.LocaleManager; -import org.bspeice.minimalbible.activity.downloader.manager.MBIndexManager; import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager; +import org.bspeice.minimalbible.activity.search.MBIndexManager; import org.crosswire.jsword.book.BookCategory; import org.crosswire.jsword.book.Books; import org.crosswire.jsword.book.install.InstallManager; import org.crosswire.jsword.book.install.Installer; -import org.crosswire.jsword.index.IndexManager; -import org.crosswire.jsword.index.IndexManagerFactory; -import org.crosswire.jsword.index.IndexPolicyAdapter; import java.util.ArrayList; import java.util.Collection; @@ -129,16 +126,5 @@ public class DownloadActivityModules { return new LocaleManager(refreshManager); } - @Provides - IndexManager indexManager() { - IndexManager manager = IndexManagerFactory.getIndexManager(); - manager.setIndexPolicy(new IndexPolicyAdapter()); - return manager; - } - @Provides - MBIndexManager mbIndexManager(PublishSubject downloadEvents, - IndexManager indexManager) { - return new MBIndexManager(downloadEvents, indexManager); - } } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/search/SearchModules.java b/app/src/main/java/org/bspeice/minimalbible/activity/search/SearchModules.java index 75a0af1..7b6b55b 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/search/SearchModules.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/search/SearchModules.java @@ -3,7 +3,6 @@ package org.bspeice.minimalbible.activity.search; import org.bspeice.minimalbible.MinimalBibleModules; import org.crosswire.jsword.book.Book; import org.crosswire.jsword.index.IndexManager; -import org.crosswire.jsword.index.IndexManagerFactory; import javax.inject.Named; @@ -22,8 +21,5 @@ public class SearchModules { return new SearchProvider(book, indexManager); } - @Provides - IndexManager jswordIndexManager() { - return IndexManagerFactory.getIndexManager(); - } + } diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/BookManager.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/BookManager.kt index 5477bee..bb4194a 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/BookManager.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/BookManager.kt @@ -13,6 +13,7 @@ import rx.schedulers.Schedulers; import rx.subjects.PublishSubject; import org.crosswire.jsword.book.BookException import org.crosswire.common.progress.Progress +import org.bspeice.minimalbible.activity.search.MBIndexManager /** * Single point of authority for what is being downloaded and its progress @@ -107,8 +108,8 @@ class BookManager(private val installedBooks: Books, indexManager removeIndex realBook return true } catch (e: BookException) { -// Log.e("InstalledManager", -// "Unable to remove book (already uninstalled?): ${e.getDetailedMessage()}") + // Log.e("InstalledManager", + // "Unable to remove book (already uninstalled?): ${e.getDetailedMessage()}") return false } } @@ -150,7 +151,7 @@ class BookManager(private val installedBooks: Books, } override fun workStateChanged(ev: WorkEvent) { -// Log.d("BookDownloadManager", ev.toString()) + // Log.d("BookDownloadManager", ev.toString()) } override fun bookAdded(booksEvent: BooksEvent) { diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/MBIndexManager.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/search/MBIndexManager.kt similarity index 53% rename from app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/MBIndexManager.kt rename to app/src/main/kotlin/org/bspeice/minimalbible/activity/search/MBIndexManager.kt index e221680..6885950 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/MBIndexManager.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/activity/search/MBIndexManager.kt @@ -1,40 +1,32 @@ -package org.bspeice.minimalbible.activity.downloader.manager +package org.bspeice.minimalbible.activity.search import org.crosswire.jsword.index.IndexManager -import rx.subjects.PublishSubject import org.crosswire.jsword.book.Book -import rx.Observable -import rx.schedulers.Schedulers import android.util.Log +import rx.schedulers.Schedulers +import rx.Observable /** * There's already an IndexManager, that's why the funky name */ -class MBIndexManager(val downloadEvents: PublishSubject, - val indexManager: IndexManager) { - - val subscription = downloadEvents subscribe { handleDlEvent(it) } - - fun handleDlEvent(event: DLProgressEvent): Unit = - if (event.progress == DLProgressEvent.PROGRESS_COMPLETE) { - subscription.unsubscribe() - buildIndex(event.b) - } +class MBIndexManager(val indexManager: IndexManager) { fun buildIndex(b: Book) { Observable.just(b) .observeOn(Schedulers.computation()) - .subscribe { + .subscribe({ try { - Log.d("MBIndexManager", "Beginning index status: ${b.getIndexStatus()}") + Log.e("MBIndexManager", "Beginning index status: ${b.getIndexStatus()}") indexManager scheduleIndexCreation b - Log.d("MBIndexManager", "Ending index status: ${b.getIndexStatus()}") + Log.e("MBIndexManager", "Ending index status: ${b.getIndexStatus()}") } catch (e: Exception) { Log.e("MBIndexManager", "Exception building index: ${e}", e) } - } + }, { + Log.e("MBIndexManager", "Exception building index: $it", it) + }) Log.d("MBIndexManager", "Building index for ${b.getInitials()}") } fun removeIndex(b: Book) = indexManager.deleteIndex(b) -} +} \ No newline at end of file