Test the MBIndexManager

This commit is contained in:
Bradlee Speice
2015-02-16 10:00:37 -05:00
parent a77076c96c
commit 7a35ad69ea
2 changed files with 97 additions and 12 deletions

View File

@ -5,27 +5,34 @@ import org.crosswire.jsword.book.Book
import android.util.Log
import rx.schedulers.Schedulers
import rx.Observable
import rx.subjects.PublishSubject
import org.crosswire.jsword.index.IndexStatus
/**
* There's already an IndexManager, that's why the funky name
*/
class MBIndexManager(val indexManager: IndexManager) {
fun buildIndex(b: Book) {
/**
* Do the hard work of actually building the book index.
* Returns a PublishSubject<> that completes when the
* index is complete. Also is nice enough to broadcast
* what work is being done when.
*/
fun buildIndex(b: Book): PublishSubject<IndexStatus> {
val indexStatus: PublishSubject<IndexStatus> = PublishSubject.create();
Observable.just(b)
.observeOn(Schedulers.computation())
.subscribe({
try {
Log.e("MBIndexManager", "Beginning index status: ${b.getIndexStatus()}")
indexManager scheduleIndexCreation b
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()}")
indexStatus.onNext(b.getIndexStatus())
indexManager scheduleIndexCreation b
indexStatus.onNext(b.getIndexStatus())
indexStatus.onCompleted()
}, { Log.e("MBIndexManager", "Exception building index: $it", it) })
return indexStatus
}
fun removeIndex(b: Book) = indexManager.deleteIndex(b)