mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-12-21 22:28:15 -05:00
SEARCHING IS NOW WORKING
Needs some heavy work yet, but the core JSword functionality (the hardest part) is done.
This commit is contained in:
parent
5197d4acfc
commit
52573534ef
@ -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<Book> mBook = new AtomicReference<Book>(null);
|
||||
bookManager.getInstalledBooks()
|
||||
.first(new Func1<Book, Boolean>() {
|
||||
@ -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<String> exclude) {
|
||||
return new BookManager(exclude);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
IndexManager indexManager() {
|
||||
return IndexManagerFactory.getIndexManager();
|
||||
}
|
||||
|
||||
@Provides
|
||||
MBIndexManager mbIndexManager(IndexManager indexManager) {
|
||||
return new MBIndexManager(indexManager);
|
||||
}
|
||||
}
|
||||
|
@ -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<DLProgressEvent> downloadEvents,
|
||||
IndexManager indexManager) {
|
||||
return new MBIndexManager(downloadEvents, indexManager);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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<DLProgressEvent>,
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user