mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-12-22 06:38:26 -05:00
Small refactor to clean the initialization process
This commit is contained in:
parent
3721ef5ee0
commit
82b8564402
@ -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() {
|
||||
|
@ -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<BookScrollEvent> 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<BookScrollEvent>) {
|
||||
val adapter = BibleAdapter(b, publisher)
|
||||
menuContent setAdapter adapter
|
||||
scrollEventPublisher subscribe {
|
||||
publisher subscribe {
|
||||
menuContent.collapseGroup(adapter.getGroupIdForBook(it.b))
|
||||
}
|
||||
}
|
||||
|
@ -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<BookScrollEvent> 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<BookScrollEvent>) {
|
||||
val adapter = BookAdapter(b, prefs)
|
||||
adapter.bindScrollHandler(scrollPublisher, layoutManager)
|
||||
adapter.bindScrollHandler(publisher, layoutManager)
|
||||
bibleContent setAdapter adapter
|
||||
bibleContent scrollToPosition prefs.currentChapter()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user