mirror of
https://github.com/MinimalBible/MinimalBible
synced 2025-07-01 13:55:56 -04:00
Test the MBIndexManager
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user