mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-04 23:28:19 -05:00
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:
parent
23f992505c
commit
96c5c895e9
@ -17,6 +17,7 @@ import dagger.Provides;
|
||||
import de.devland.esperandro.Esperandro;
|
||||
import rx.functions.Action1;
|
||||
import rx.functions.Func1;
|
||||
import rx.subjects.PublishSubject;
|
||||
|
||||
/**
|
||||
* Modules used for the BibleViewer activity
|
||||
@ -101,4 +102,10 @@ public class BibleViewerModules {
|
||||
VerseLookup verseLookup(@Named("MainBook") Book b) {
|
||||
return new VerseLookup(b);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
PublishSubject<BookScrollEvent> scrollEventProvider() {
|
||||
return PublishSubject.create();
|
||||
}
|
||||
}
|
@ -14,6 +14,8 @@ import org.crosswire.jsword.book.Book;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import rx.subjects.PublishSubject;
|
||||
|
||||
/**
|
||||
* ExpandableListView for managing books of the Bible.
|
||||
* We extend from @link{BaseNavigationDrawerFragment} so we can inherit some of the lifecycle
|
||||
@ -27,6 +29,9 @@ public class BookChapterNavFragment extends NavDrawerFragment {
|
||||
@Inject @Named("MainBook")
|
||||
Book mainBook;
|
||||
|
||||
@Inject
|
||||
PublishSubject<BookScrollEvent> scrollListener;
|
||||
|
||||
ExpandableListView mActualListView;
|
||||
|
||||
@Override
|
||||
@ -35,9 +40,11 @@ public class BookChapterNavFragment extends NavDrawerFragment {
|
||||
Injector i = (Injector) getActivity();
|
||||
i.inject(this);
|
||||
|
||||
BibleMenu menu = new BibleMenu(mainBook);
|
||||
mActualListView = (ExpandableListView) inflater.inflate(
|
||||
R.layout.fragment_expandable_navigation_drawer, container, false);
|
||||
mActualListView.setAdapter(new BibleMenu(mainBook));
|
||||
mActualListView.setAdapter(menu);
|
||||
mActualListView.setOnChildClickListener(menu.getMenuClickListener(scrollListener));
|
||||
|
||||
mActualListView.setItemChecked(mCurrentSelectedPosition, true);
|
||||
return mActualListView;
|
||||
|
@ -1,20 +1,17 @@
|
||||
package org.bspeice.minimalbible.activity.viewer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import org.bspeice.minimalbible.Injector;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activity.BaseFragment;
|
||||
import org.bspeice.minimalbible.service.lookup.VerseLookup;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -22,10 +19,6 @@ import javax.inject.Named;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.schedulers.Schedulers;
|
||||
import rx.subjects.PublishSubject;
|
||||
|
||||
/**
|
||||
@ -40,14 +33,11 @@ public class BookFragment extends BaseFragment {
|
||||
@Named("MainBook")
|
||||
Book mBook;
|
||||
@Inject
|
||||
VerseLookup verseLookup;
|
||||
PublishSubject<BookScrollEvent> scrollEventProvider;
|
||||
|
||||
@InjectView(R.id.book_content)
|
||||
RecyclerView bookContent;
|
||||
|
||||
|
||||
PublishSubject<String> titleReceiver = PublishSubject.create();
|
||||
|
||||
/**
|
||||
* Returns a new instance of this fragment for the given book.
|
||||
*/
|
||||
@ -101,7 +91,10 @@ public class BookFragment extends BaseFragment {
|
||||
((BibleViewer)getActivity()).setActionBarTitle(b.getInitials());
|
||||
|
||||
final RecyclerView.LayoutManager manager = new LinearLayoutManager(getActivity());
|
||||
BookAdapter adapter = new BookAdapter(b);
|
||||
bookContent.setLayoutManager(manager);
|
||||
bookContent.setAdapter(new BookAdapter(b));
|
||||
bookContent.setAdapter(adapter);
|
||||
|
||||
adapter.bindScrollHandler(scrollEventProvider, manager);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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) {}
|
Loading…
Reference in New Issue
Block a user