Fix infinite scroll getting thrown into an infinite loop...

Ironic, no?
This commit is contained in:
Bradlee Speice 2014-09-27 19:20:27 -04:00
parent b842ee1933
commit 2ee16ceb4f
2 changed files with 25 additions and 7 deletions

View File

@ -26,9 +26,24 @@ class BibleViewClient(b: Book, lookup: VerseLookupService) : WebViewClient() {
JavascriptInterface fun getVerses(first: Int, count: Int): String {
Log.e("getVerses", "First: " + first + " count: " + count)
val verses: MutableList<String> = ArrayList<String>()
for (i in first..first + count - 1) {
var trueCount: Int
var 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.toString())
return verses.toString()
}
}

View File

@ -17,13 +17,16 @@ class OsisParser(v: Verse) : DefaultHandler() {
// Android Studio complains about compilation, but the method
// has @NotNull annotations, so we program for those.
override fun startElement(uri: String, localName: String, qName: String, attributes: Attributes) {
if (localName.equals(OSISUtil.OSIS_ELEMENT_VERSE))
doWrite.push(true)
else
doWrite.push(false)
override fun startElement(uri: String, localName: String,
qName: String, attributes: Attributes) {
when (localName) {
OSISUtil.OSIS_ELEMENT_VERSE -> doWrite.push(true)
else -> {
doWrite.push(false)
}
}
}
// Android Studio complains about compilation, but the method
// has @NotNull annotations, so we program for those.
override fun endElement(uri: String?, localName: String, qName: String) {