mirror of
https://github.com/MinimalBible/MinimalBible
synced 2025-07-12 19:25:06 -04:00
RefreshManager going functional!
This commit is contained in:
@ -0,0 +1,46 @@
|
||||
package org.bspeice.minimalbible.activity.downloader.manager
|
||||
|
||||
import org.crosswire.jsword.book.install.Installer
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import rx.Observable
|
||||
import org.crosswire.jsword.book.Book
|
||||
import rx.schedulers.Schedulers
|
||||
|
||||
/**
|
||||
* Created by bspeice on 10/22/14.
|
||||
*/
|
||||
|
||||
class RefreshManager(val installers: Collection<Installer>) {
|
||||
val refreshComplete = AtomicBoolean()
|
||||
val availableModules: Observable<Map<Installer, List<Book>>> =
|
||||
Observable.from(installers)
|
||||
.map {
|
||||
if (doReload()) {
|
||||
it.reloadBookList()
|
||||
}
|
||||
mapOf(Pair(it, it.getBooks()))
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.cache();
|
||||
|
||||
val availableModulesFlat: Observable<Book>
|
||||
get() = availableModules
|
||||
// Map -> Lists
|
||||
.flatMap { Observable.from(it.values()) }
|
||||
// Lists -> Single list
|
||||
.flatMap { Observable.from(it) };
|
||||
|
||||
// Constructor - Split from the value creation because `subscribe` returns
|
||||
// the subscriber object, not the underlying value
|
||||
{
|
||||
availableModules.subscribe({}, {}, { refreshComplete set true })
|
||||
}
|
||||
|
||||
fun doReload(): Boolean = true
|
||||
|
||||
fun installerFromBook(b: Book): Observable<Installer> = Observable.just(
|
||||
availableModules.filter {
|
||||
it.flatMap { it.value } contains b
|
||||
}
|
||||
.toBlocking().first().entrySet().first().getKey())
|
||||
}
|
@ -22,7 +22,7 @@ class BibleViewClient(val b: Book, val lookup: VerseLookupService,
|
||||
val v = Verse(b.getVersification(), ordinal)
|
||||
// TODO: WebView should notify us what verse it's on
|
||||
subject?.onNext(v.getBook().toString() + " " + v.getChapter() + ":" + v.getVerse())
|
||||
return lookup.getJsonVerse(v) as String
|
||||
return lookup.getJsonVerse(v)
|
||||
}
|
||||
|
||||
JavascriptInterface fun getVerses(first: Int, count: Int): String {
|
||||
|
@ -33,7 +33,7 @@ class OsisParser(v: Verse) : DefaultHandler() {
|
||||
doWrite.pop()
|
||||
}
|
||||
override fun characters(ch: CharArray?, start: Int, length: Int) {
|
||||
if (doWrite.peek() as Boolean)
|
||||
if (doWrite.peek())
|
||||
verseContent.appendContent(String(ch as CharArray))
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ class VerseContent(v: Verse) {
|
||||
public fun toJson(): String {
|
||||
// Lazy load Gson - not likely that we'll call this method multiple times, so
|
||||
// don't have to worry about a penalty there.
|
||||
return Gson().toJson(this) as String
|
||||
return Gson().toJson(this)
|
||||
}
|
||||
|
||||
public fun appendContent(content: String) {
|
||||
|
@ -22,11 +22,11 @@ class VersificationUtil() {
|
||||
}
|
||||
|
||||
fun getBookNames(b: Book): Observable<String> {
|
||||
return Observable.from(b.getVersification().getBookNames()) as Observable
|
||||
return Observable.from(b.getVersification().getBookNames())
|
||||
}
|
||||
|
||||
fun getBooks(b: Book): Observable<BibleBook> {
|
||||
return Observable.from(b.getVersification().getBooks()) as Observable
|
||||
return Observable.from(b.getVersification().getBooks())
|
||||
}
|
||||
|
||||
fun getChapterCount(b: Book, bibleBook: BibleBook): Int {
|
||||
@ -34,7 +34,7 @@ class VersificationUtil() {
|
||||
}
|
||||
|
||||
fun getBookName(b: Book, bibleBook: BibleBook): String {
|
||||
return b.getVersification().getLongName(bibleBook) as String
|
||||
return b.getVersification().getLongName(bibleBook)
|
||||
}
|
||||
|
||||
fun getVersification(b: Book): Versification {
|
||||
@ -58,7 +58,7 @@ fun Versification.getBooks(): List<BibleBook> {
|
||||
}
|
||||
|
||||
fun Versification.getBookNames(): List<String> {
|
||||
return this.getBooks().map { this.getLongName(it) as String }
|
||||
return this.getBooks().map { this.getLongName(it) }
|
||||
}
|
||||
|
||||
fun Versification.getChapterCount(b: BibleBook): Int {
|
||||
@ -70,7 +70,7 @@ fun Book.getVersification(): Versification {
|
||||
this.getBookMetaData()!!.getProperty(BookMetaData.KEY_VERSIFICATION).toString()
|
||||
)
|
||||
if (v == null) {
|
||||
Log.e(getClass()!!.getSimpleName(), "Invalid book: " + this.getInitials())
|
||||
Log.e(javaClass<Book>().getSimpleName(), "Invalid book: " + this.getInitials())
|
||||
throw InvalidBookException(this.getInitials())
|
||||
} else
|
||||
return v
|
||||
|
Reference in New Issue
Block a user