Seek-to working!

For some reason, things at 1st Timothy onward don't work, but everything up to that point does. I'll call that enough for now.
PLEASE NOTE: This code needs serious refactoring and testing, dependencies are all over the place. Functionally it's OK for now though.
This commit is contained in:
Bradlee Speice
2014-11-26 22:41:55 -05:00
parent 23f992505c
commit 96c5c895e9
6 changed files with 65 additions and 20 deletions

View File

@ -13,6 +13,8 @@ import android.content.Context
import android.view.LayoutInflater
import android.content.res.Resources
import android.support.annotation.IdRes
import android.widget.ExpandableListView
import rx.subjects.PublishSubject
/**
* Created by bspeice on 10/24/14.
@ -25,6 +27,22 @@ class BibleMenu(val b: Book) : BaseExpandableListAdapter() {
Pair(it, b.getVersification().getLastChapter(it))
}
/**
* The listener that should be registered to receive click events
* It's created here because we need access to the menuMappings
*/
fun getMenuClickListener(listener: PublishSubject<BookScrollEvent>) =
object : ExpandableListView.OnChildClickListener {
override fun onChildClick(listView: ExpandableListView?, childView: View?,
groupPosition: Int, childPosition: Int, id: Long): Boolean {
val map = menuMappings[groupPosition]
listener onNext BookScrollEvent(map.first, map.second)
return true; // Event was handled
}
}
var groupHighlighted: Int = 0
var childHighlighted: Int = 0
@ -82,4 +100,4 @@ class BibleMenu(val b: Book) : BaseExpandableListAdapter() {
content setTextColor getHighlightedColor(highlighted)
}
}
}
}

View File

@ -3,8 +3,6 @@ package org.bspeice.minimalbible.activity.viewer
import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import org.crosswire.jsword.book.Book
import org.crosswire.jsword.passage.Verse
import android.view.View
import android.view.LayoutInflater
import org.bspeice.minimalbible.R
import android.widget.TextView
@ -13,14 +11,15 @@ 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
import rx.subjects.PublishSubject
/**
* 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) : RecyclerView.Adapter<PassageView>() {
class BookAdapter(val b: Book)
: RecyclerView.Adapter<PassageView>() {
val versification = b.getVersification()
val bookList = versification.getBooks()
@ -48,7 +47,7 @@ class BookAdapter(val b: Book) : RecyclerView.Adapter<PassageView>() {
val verseCount = versification.getLastVerse(currentBook, it)
ChapterInfo(b, it, currentBook, firstVerse, firstVerse + verseCount)
}
}
};
/**
* I'm not sure what the position argument actually represents,
@ -73,6 +72,19 @@ class BookAdapter(val b: Book) : RecyclerView.Adapter<PassageView>() {
* Get the number of chapters in the book
*/
override fun getItemCount(): Int = chapterCount
fun bindScrollHandler(provider: PublishSubject<BookScrollEvent>,
lM: RecyclerView.LayoutManager) {
provider subscribe {
val event = it
chapterList.withIndices()
.filter {
event.b == it.second.bibleBook &&
event.chapter == it.second.chapter
}
.forEach { lM scrollToPosition it.first }
}
}
}
class PassageView(val v: TextView) : RecyclerView.ViewHolder(v) {

View File

@ -0,0 +1,8 @@
package org.bspeice.minimalbible.activity.viewer
import org.crosswire.jsword.versification.BibleBook
/**
* Created by bspeice on 11/26/14.
*/
data class BookScrollEvent(val b: BibleBook, val chapter: Int) {}