diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java index 817762b..d959256 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewer.java @@ -116,9 +116,6 @@ public class BibleViewer extends BaseActivity implements Injector { setInsetToolbar(toolbar); - // Currently you must set up the menu in exactly this order. Do I need to refactor this? - bibleMenu.setScrollEventPublisher(scrollEventPublisher); - bibleMenu.setBible(mainBook); // If a new chapter is selected, make sure we close the drawer // We can't specify `this` as the subscriber since we can't @@ -130,9 +127,8 @@ public class BibleViewer extends BaseActivity implements Injector { } }); - // Set up the view to respond to scroll events as well. Again, exact order is needed. - bibleContent.setScrollPublisher(scrollEventPublisher); - bibleContent.setBook(mainBook, prefs); + bibleMenu.doInitialize(mainBook, scrollEventPublisher); + bibleContent.doInitialize(mainBook, prefs, scrollEventPublisher); } public void closeMenu() { diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt index ebe0900..fcd4e25 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleMenu.kt @@ -17,26 +17,19 @@ import rx.subjects.PublishSubject import android.widget.LinearLayout import android.app.Activity import android.util.AttributeSet -import kotlin.properties.Delegates import org.bspeice.minimalbible.activity.setInset import android.support.annotation.LayoutRes import org.crosswire.jsword.versification.BibleBook class BibleMenu(val ctx: Context, val attrs: AttributeSet) : LinearLayout(ctx, attrs) { - var menuContent: ExpandableListView by Delegates.notNull() - var scrollEventPublisher: PublishSubject by Delegates.notNull(); + val inflater = ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + val contentView = inflater.inflate(R.layout.view_bible_menu, this, true) + val menuContent = findViewById(R.id._bible_menu) as ExpandableListView - { - val inflater = ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater - inflater.inflate(R.layout.view_bible_menu, this, true) - - menuContent = findViewById(R.id._bible_menu) as ExpandableListView - } - - fun setBible(b: Book) { - val adapter = BibleAdapter(b, scrollEventPublisher) + fun doInitialize(b: Book, publisher: PublishSubject) { + val adapter = BibleAdapter(b, publisher) menuContent setAdapter adapter - scrollEventPublisher subscribe { + publisher subscribe { menuContent.collapseGroup(adapter.getGroupIdForBook(it.b)) } } diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleView.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleView.kt index 84db172..2cd412f 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleView.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleView.kt @@ -17,27 +17,25 @@ import org.bspeice.minimalbible.service.format.osisparser.OsisParser import android.util.Log import android.content.Context import android.util.AttributeSet -import kotlin.properties.Delegates import android.support.v7.widget.LinearLayoutManager import android.widget.LinearLayout +import android.view.View class BibleView(val ctx: Context, val attrs: AttributeSet) : LinearLayout(ctx, attrs) { - var bibleContent: RecyclerView by Delegates.notNull() - var scrollPublisher: PublishSubject by Delegates.notNull() val layoutManager: LinearLayoutManager = LinearLayoutManager(ctx) val inflater = ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater; + val contentView: View = inflater.inflate(R.layout.view_bible, this, true) + val bibleContent = contentView.findViewById(R.id.bible_content) as RecyclerView { - val rootView = inflater.inflate(R.layout.view_bible, this, true) - - bibleContent = rootView.findViewById(R.id.bible_content) as RecyclerView bibleContent setLayoutManager layoutManager } - fun setBook(b: Book, prefs: BibleViewerPreferences) { + fun doInitialize(b: Book, prefs: BibleViewerPreferences, + publisher: PublishSubject) { val adapter = BookAdapter(b, prefs) - adapter.bindScrollHandler(scrollPublisher, layoutManager) + adapter.bindScrollHandler(publisher, layoutManager) bibleContent setAdapter adapter bibleContent scrollToPosition prefs.currentChapter() }