Switch to the VerseLookup over parser

Allows me to use the LRUCache frontent
This commit is contained in:
Bradlee Speice
2014-11-26 23:22:18 -05:00
parent 96c5c895e9
commit 66076c759a
5 changed files with 21 additions and 77 deletions

View File

@ -1,50 +0,0 @@
package org.bspeice.minimalbible.activity.viewer
import org.crosswire.jsword.passage.Verse
import android.webkit.WebViewClient
import android.webkit.JavascriptInterface
import org.crosswire.jsword.book.Book
import android.util.Log
import rx.subjects.PublishSubject
import org.crosswire.jsword.book.getVersification
import org.bspeice.minimalbible.service.lookup.VerseLookup
/**
* Created by bspeice on 9/14/14.
*/
class BibleViewClient(val b: Book, val lookup: VerseLookup,
val subject: PublishSubject<String>?) : WebViewClient() {
// We can receive and return only primitives and Strings. Still means we can use JSON :)
JavascriptInterface fun getVerse(ordinal: Int): String {
val v = Verse(b.getVersification(), ordinal)
// TODO: WebView should notify us what verse it's on
subject?.onNext("${v.getBook()} ${v.getChapter()}:${v.getVerse()}")
return lookup getJson v
}
JavascriptInterface fun getVerses(first: Int, count: Int): String {
Log.e("getVerses", "First: $first count: $count")
val verses: MutableList<String> = linkedListOf()
val trueCount: Int
val trueFirst: Int
when {
first < 0 - count -> return ""
first < 0 -> {
trueCount = count + first // Equivalent to count - abs(first)
trueFirst = 0
}
else -> {
trueCount = count
trueFirst = first
}
}
for (i in trueFirst..trueFirst + trueCount - 1) {
verses.add(getVerse(i))
}
Log.e("getVerses", "return verses size: ${verses.size}")
return verses.toString()
}
}

View File

@ -6,19 +6,19 @@ import org.crosswire.jsword.book.Book
import android.view.LayoutInflater
import org.bspeice.minimalbible.R
import android.widget.TextView
import org.bspeice.minimalbible.service.format.osisparser.OsisParser
import org.crosswire.jsword.book.getVersification
import org.crosswire.jsword.versification.getBooks
import org.crosswire.jsword.versification.BibleBook
import org.bspeice.minimalbible.activity.viewer.BookAdapter.ChapterInfo
import rx.subjects.PublishSubject
import org.bspeice.minimalbible.service.lookup.VerseLookup
/**
* Adapter used for displaying a book
* Displays one chapter at a time,
* as each TextView widget is it's own line break
*/
class BookAdapter(val b: Book)
class BookAdapter(val b: Book, val lookup: VerseLookup)
: RecyclerView.Adapter<PassageView>() {
val versification = b.getVersification()
@ -58,7 +58,7 @@ class BookAdapter(val b: Book)
val emptyView = LayoutInflater.from(parent?.getContext())
.inflate(R.layout.viewer_passage_view, parent, false) as TextView
val passage = PassageView(emptyView)
val passage = PassageView(emptyView, b, lookup)
return passage
}
@ -87,16 +87,16 @@ class BookAdapter(val b: Book)
}
}
class PassageView(val v: TextView) : RecyclerView.ViewHolder(v) {
val parser = OsisParser()
class PassageView(val v: TextView, val b: Book, val lookup: VerseLookup)
: RecyclerView.ViewHolder(v) {
fun getVerseText(b: Book, verseRange: Progression<Int>) =
verseRange.map { parser.getVerse(b, it).content }
fun getVerseText(verseRange: Progression<Int>) =
verseRange.map { lookup.getText(b.getVersification().decodeOrdinal(it)) }
fun reduceText(verses: List<String>) = verses.join(" ")
// Uses functional style, but those parentheses man... you'd think I was writing LISP
fun bind(info: ChapterInfo) {
v.setText(reduceText(getVerseText(info.book, info.vStart..info.vEnd)))
v.setText(reduceText(getVerseText(info.vStart..info.vEnd)))
}
}