From 989e3e8023ccb3733dc55ffab24c01204967631e Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Wed, 26 Nov 2014 16:50:27 -0500 Subject: [PATCH] Scrolling through verses works correctly Binding not working correctly, but shouldn't be hard to fix --- .../activity/viewer/BookAdapter.kt | 51 ++++++++++++++----- .../jsword/versification/VersificationUtil.kt | 2 +- jsword-minimalbible | 2 +- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BookAdapter.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BookAdapter.kt index 10d0abc..823ab21 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BookAdapter.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BookAdapter.kt @@ -10,6 +10,10 @@ 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 android.util.Log /** * Adapter used for displaying a book @@ -18,36 +22,55 @@ import org.crosswire.jsword.book.getVersification */ class BookAdapter(val b: Book) : RecyclerView.Adapter() { + val versification = b.getVersification() + val bookList = versification.getBooks() + val chapterCount = bookList.map { versification.getLastChapter(it) - 1 }.sum() + + data class ChapterInfo(val book: Book, val chapter: Int, val bibleBook: BibleBook, + val vStart: Int, val vEnd: Int) + + // TODO: Lazy compute values needed for this list + val chapterList: List = 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)) + } + } + /** - * Create a new view + * I'm not sure what the position argument actually is, + * but on initial load it doesn't change */ override fun onCreateViewHolder(parent: ViewGroup?, - position: Int): PassageView? { + position: Int): PassageView { val emptyView = LayoutInflater.from(parent?.getContext()) - .inflate(R.layout.viewer_passage_view, parent, false) + .inflate(R.layout.viewer_passage_view, parent, false) as TextView val passage = PassageView(emptyView) -// passage.v setText o.getVerse(b, position).content return passage } /** - * Bind an existing view + * Bind an existing view to its chapter content */ - override fun onBindViewHolder(view: PassageView, position: Int) { - val o = OsisParser() - view.v setText o.getVerse(b, position).content - } + override fun onBindViewHolder(view: PassageView, position: Int) = + view bind chapterList[position] /** * Get the number of chapters in the book */ - override fun getItemCount(): Int = b.getVersification() - .getAllVerses().getEnd().getOrdinal() + override fun getItemCount(): Int = chapterCount } -class PassageView(val _v: View) : RecyclerView.ViewHolder(_v) { - - val v = _v as TextView +class PassageView(val v: TextView) : RecyclerView.ViewHolder(v) { + 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 + } } diff --git a/app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt b/app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt index 2ef1094..1d5dc5b 100644 --- a/app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt +++ b/app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt @@ -34,4 +34,4 @@ fun Versification.getBookNames(): List = fun Versification.getChapterCount(b: BibleBook): Int { return this.getLastChapter(b) -} \ No newline at end of file +} diff --git a/jsword-minimalbible b/jsword-minimalbible index 865d8ff..00b9da9 160000 --- a/jsword-minimalbible +++ b/jsword-minimalbible @@ -1 +1 @@ -Subproject commit 865d8ff6b859d1a08be4fe12e99473f481cd6f07 +Subproject commit 00b9da93beac2d79f03c71b80c2b822fafa32a20