mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-28 10:58:16 -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,
|
data class ChapterInfo(val book: Book, val chapter: Int, val bibleBook: BibleBook,
|
||||||
val vStart: Int, val vEnd: Int)
|
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
|
// TODO: Lazy compute values needed for this list
|
||||||
val chapterList: List<ChapterInfo> = bookList.flatMap {
|
val chapterList: List<ChapterInfo> = bookList.flatMap {
|
||||||
val currentBook = it
|
val currentBook = it
|
||||||
(1..versification.getLastChapter(currentBook)).map { chapter ->
|
(1..versification.getLastChapter(currentBook)).map {
|
||||||
Log.d("BookAdapter", "Building info for chapter ${chapter}")
|
val firstVerse = versification.getFirstVerse(currentBook, it)
|
||||||
ChapterInfo(b, chapter, currentBook,
|
val verseCount = versification.getLastVerse(currentBook, it)
|
||||||
versification.getFirstVerse(currentBook, chapter),
|
ChapterInfo(b, it, currentBook, firstVerse, firstVerse + verseCount)
|
||||||
versification.getLastVerse(currentBook, chapter))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* but on initial load it doesn't change
|
||||||
*/
|
*/
|
||||||
override fun onCreateViewHolder(parent: ViewGroup?,
|
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) {
|
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) {
|
fun bind(info: ChapterInfo) {
|
||||||
val o = OsisParser()
|
v.setText(reduceText(getVerseText(info.book, info.vStart..info.vEnd)))
|
||||||
val string = o.getVerse(info.book, info.vEnd).content
|
|
||||||
Log.d("PassageView", "Book: ${info.bibleBook}, Chapter: ${info.chapter}")
|
|
||||||
v setText string
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user