Get a first manager to Kotlin

Extension functions are fun...
This commit is contained in:
Bradlee Speice
2014-09-11 00:41:11 -04:00
parent 2ae714a935
commit cb13dd64aa
7 changed files with 62 additions and 77 deletions

View File

@ -0,0 +1,33 @@
package org.bspeice.minimalbible.service.manager
import rx.Observable
import org.crosswire.jsword.book.Books
import rx.functions.Action1
import org.crosswire.jsword.book.Book
import rx.functions.Action0
/**
* Created by bspeice on 9/10/14.
*/
//@Singleton
class BookManager() {
// Some extra books like to think they're installed, but trigger NPE all over the place...
val ignore = array("ERen_no", "ot1nt2");
val installedBooks = Observable.from(Books.installed()!!.getBooks())
?.filter { !ignore.contains(it!!.getInitials()) }
?.cache()
var refreshComplete = false;
{
// TODO: Cleaner way of expressing this?
installedBooks?.subscribe(Action1<Book> { result -> },
Action1<Throwable> { error -> },
Action0 { refreshComplete = true })
}
fun getBooks(): Observable<Book> {
return installedBooks as Observable
}
}

View File

@ -0,0 +1,7 @@
package org.bspeice.minimalbible.service.manager
/**
* Created by bspeice on 9/11/14.
*/
class InvalidBookException(message: String?) : Exception(message) {}