mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-24 17:08:18 -05:00
Load entire chapters at a time to scroll through
Seems very slow, lots of optimization that needs to be done
This commit is contained in:
parent
989e3e8023
commit
23f992505c
@ -29,19 +29,29 @@ class BookAdapter(val b: Book) : RecyclerView.Adapter<PassageView>() {
|
||||
data class ChapterInfo(val book: Book, val chapter: Int, val bibleBook: BibleBook,
|
||||
val vStart: Int, val vEnd: Int)
|
||||
|
||||
/**
|
||||
* A list of all ChapterInfo objects needed for displaying a book
|
||||
* The for expression probably looks a bit nicer:
|
||||
* for {
|
||||
* book <- bookList
|
||||
* chapter <- 1..versification.getLastChapter(currentBook)
|
||||
* } yield ChapterInfo(...)
|
||||
*
|
||||
* Also note that getLastVerse() returns the number of verses in a chapter,
|
||||
* so we build the actual last verse by adding getFirstVerse and getLastVerse
|
||||
*/
|
||||
// TODO: Lazy compute values needed for this list
|
||||
val chapterList: List<ChapterInfo> = bookList.flatMap {
|
||||
val currentBook = it
|
||||
(1..versification.getLastChapter(currentBook)).map { chapter ->
|
||||
Log.d("BookAdapter", "Building info for chapter ${chapter}")
|
||||
ChapterInfo(b, chapter, currentBook,
|
||||
versification.getFirstVerse(currentBook, chapter),
|
||||
versification.getLastVerse(currentBook, chapter))
|
||||
(1..versification.getLastChapter(currentBook)).map {
|
||||
val firstVerse = versification.getFirstVerse(currentBook, it)
|
||||
val verseCount = versification.getLastVerse(currentBook, it)
|
||||
ChapterInfo(b, it, currentBook, firstVerse, firstVerse + verseCount)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* I'm not sure what the position argument actually is,
|
||||
* I'm not sure what the position argument actually represents,
|
||||
* but on initial load it doesn't change
|
||||
*/
|
||||
override fun onCreateViewHolder(parent: ViewGroup?,
|
||||
@ -66,11 +76,15 @@ class BookAdapter(val b: Book) : RecyclerView.Adapter<PassageView>() {
|
||||
}
|
||||
|
||||
class PassageView(val v: TextView) : RecyclerView.ViewHolder(v) {
|
||||
val parser = OsisParser()
|
||||
|
||||
fun getVerseText(b: Book, verseRange: Progression<Int>) =
|
||||
verseRange.map { parser.getVerse(b, it).content }
|
||||
|
||||
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) {
|
||||
val o = OsisParser()
|
||||
val string = o.getVerse(info.book, info.vEnd).content
|
||||
Log.d("PassageView", "Book: ${info.bibleBook}, Chapter: ${info.chapter}")
|
||||
v setText string
|
||||
v.setText(reduceText(getVerseText(info.book, info.vStart..info.vEnd)))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user