SEARCHING IS NOW WORKING

Needs some heavy work yet, but the core JSword functionality (the hardest part) is done.
This commit is contained in:
Bradlee Speice 2015-02-15 22:49:42 -05:00
parent 5197d4acfc
commit 52573534ef
5 changed files with 42 additions and 46 deletions

View File

@ -3,10 +3,14 @@ package org.bspeice.minimalbible;
import android.app.Application; import android.app.Application;
import android.util.Log; import android.util.Log;
import org.bspeice.minimalbible.activity.search.MBIndexManager;
import org.bspeice.minimalbible.activity.viewer.BibleViewerPreferences; import org.bspeice.minimalbible.activity.viewer.BibleViewerPreferences;
import org.bspeice.minimalbible.service.manager.BookManager; import org.bspeice.minimalbible.service.manager.BookManager;
import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.book.Books; 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.ArrayList;
import java.util.List; import java.util.List;
@ -99,7 +103,8 @@ public class MinimalBibleModules {
@Provides @Provides
@Named("MainBook") @Named("MainBook")
Book provideMainBook(BookManager bookManager, final BibleViewerPreferences prefs) { Book provideMainBook(BookManager bookManager, final BibleViewerPreferences prefs,
MBIndexManager indexManager) {
final AtomicReference<Book> mBook = new AtomicReference<Book>(null); final AtomicReference<Book> mBook = new AtomicReference<Book>(null);
bookManager.getInstalledBooks() bookManager.getInstalledBooks()
.first(new Func1<Book, Boolean>() { .first(new Func1<Book, Boolean>() {
@ -134,15 +139,20 @@ public class MinimalBibleModules {
.toBlocking().first(); .toBlocking().first();
prefs.defaultBookInitials(fallback.getName()); prefs.defaultBookInitials(fallback.getName());
return fallback; mBook.set(fallback);
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
// If no books are installed, there's really nothing we can do... // 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."); Log.d("BibleViewerModules", "No books are installed, so can't select a main book.");
return null; return null;
} }
} else {
return mBook.get();
} }
Book b = mBook.get();
if (b.getIndexStatus() != IndexStatus.DONE) {
indexManager.buildIndex(b);
}
return b;
} }
@Provides @Provides
@ -150,4 +160,15 @@ public class MinimalBibleModules {
BookManager bookManager(List<String> exclude) { BookManager bookManager(List<String> exclude) {
return new BookManager(exclude); return new BookManager(exclude);
} }
@Provides
@Singleton
IndexManager indexManager() {
return IndexManagerFactory.getIndexManager();
}
@Provides
MBIndexManager mbIndexManager(IndexManager indexManager) {
return new MBIndexManager(indexManager);
}
} }

View File

@ -8,15 +8,12 @@ import org.bspeice.minimalbible.MinimalBibleModules;
import org.bspeice.minimalbible.activity.downloader.manager.BookManager; import org.bspeice.minimalbible.activity.downloader.manager.BookManager;
import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent; import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent;
import org.bspeice.minimalbible.activity.downloader.manager.LocaleManager; 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.downloader.manager.RefreshManager;
import org.bspeice.minimalbible.activity.search.MBIndexManager;
import org.crosswire.jsword.book.BookCategory; import org.crosswire.jsword.book.BookCategory;
import org.crosswire.jsword.book.Books; import org.crosswire.jsword.book.Books;
import org.crosswire.jsword.book.install.InstallManager; import org.crosswire.jsword.book.install.InstallManager;
import org.crosswire.jsword.book.install.Installer; 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.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -129,16 +126,5 @@ public class DownloadActivityModules {
return new LocaleManager(refreshManager); return new LocaleManager(refreshManager);
} }
@Provides
IndexManager indexManager() {
IndexManager manager = IndexManagerFactory.getIndexManager();
manager.setIndexPolicy(new IndexPolicyAdapter());
return manager;
}
@Provides
MBIndexManager mbIndexManager(PublishSubject<DLProgressEvent> downloadEvents,
IndexManager indexManager) {
return new MBIndexManager(downloadEvents, indexManager);
}
} }

View File

@ -3,7 +3,6 @@ package org.bspeice.minimalbible.activity.search;
import org.bspeice.minimalbible.MinimalBibleModules; import org.bspeice.minimalbible.MinimalBibleModules;
import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.index.IndexManager; import org.crosswire.jsword.index.IndexManager;
import org.crosswire.jsword.index.IndexManagerFactory;
import javax.inject.Named; import javax.inject.Named;
@ -22,8 +21,5 @@ public class SearchModules {
return new SearchProvider(book, indexManager); return new SearchProvider(book, indexManager);
} }
@Provides
IndexManager jswordIndexManager() {
return IndexManagerFactory.getIndexManager();
}
} }

View File

@ -13,6 +13,7 @@ import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject; import rx.subjects.PublishSubject;
import org.crosswire.jsword.book.BookException import org.crosswire.jsword.book.BookException
import org.crosswire.common.progress.Progress 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 * Single point of authority for what is being downloaded and its progress

View File

@ -1,38 +1,30 @@
package org.bspeice.minimalbible.activity.downloader.manager package org.bspeice.minimalbible.activity.search
import org.crosswire.jsword.index.IndexManager import org.crosswire.jsword.index.IndexManager
import rx.subjects.PublishSubject
import org.crosswire.jsword.book.Book import org.crosswire.jsword.book.Book
import rx.Observable
import rx.schedulers.Schedulers
import android.util.Log import android.util.Log
import rx.schedulers.Schedulers
import rx.Observable
/** /**
* There's already an IndexManager, that's why the funky name * There's already an IndexManager, that's why the funky name
*/ */
class MBIndexManager(val downloadEvents: PublishSubject<DLProgressEvent>, class MBIndexManager(val indexManager: IndexManager) {
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)
}
fun buildIndex(b: Book) { fun buildIndex(b: Book) {
Observable.just(b) Observable.just(b)
.observeOn(Schedulers.computation()) .observeOn(Schedulers.computation())
.subscribe { .subscribe({
try { try {
Log.d("MBIndexManager", "Beginning index status: ${b.getIndexStatus()}") Log.e("MBIndexManager", "Beginning index status: ${b.getIndexStatus()}")
indexManager scheduleIndexCreation b indexManager scheduleIndexCreation b
Log.d("MBIndexManager", "Ending index status: ${b.getIndexStatus()}") Log.e("MBIndexManager", "Ending index status: ${b.getIndexStatus()}")
} catch (e: Exception) { } catch (e: Exception) {
Log.e("MBIndexManager", "Exception building index: ${e}", e) Log.e("MBIndexManager", "Exception building index: ${e}", e)
} }
} }, {
Log.e("MBIndexManager", "Exception building index: $it", it)
})
Log.d("MBIndexManager", "Building index for ${b.getInitials()}") Log.d("MBIndexManager", "Building index for ${b.getInitials()}")
} }