mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-21 23:48:18 -05:00
Not pretty, but displays verse at top of screen
This commit is contained in:
parent
ff9f2ac7b3
commit
9424d43ef7
@ -14,7 +14,6 @@ import org.bspeice.minimalbible.R;
|
|||||||
import org.bspeice.minimalbible.activity.BaseFragment;
|
import org.bspeice.minimalbible.activity.BaseFragment;
|
||||||
import org.bspeice.minimalbible.service.book.VerseLookupService;
|
import org.bspeice.minimalbible.service.book.VerseLookupService;
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
import org.crosswire.jsword.passage.Verse;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
@ -22,6 +21,9 @@ import javax.inject.Named;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.InjectView;
|
import butterknife.InjectView;
|
||||||
import dagger.Lazy;
|
import dagger.Lazy;
|
||||||
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
|
import rx.functions.Action1;
|
||||||
|
import rx.subjects.PublishSubject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A placeholder fragment containing a simple view.
|
* A placeholder fragment containing a simple view.
|
||||||
@ -29,16 +31,20 @@ import dagger.Lazy;
|
|||||||
public class BookFragment extends BaseFragment {
|
public class BookFragment extends BaseFragment {
|
||||||
|
|
||||||
private static final String ARG_BOOK_NAME = "book_name";
|
private static final String ARG_BOOK_NAME = "book_name";
|
||||||
|
|
||||||
|
Injector i;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("MainBook")
|
@Named("MainBook")
|
||||||
Lazy<Book> mBook;
|
Lazy<Book> mBook;
|
||||||
|
|
||||||
// TODO: Factory?
|
|
||||||
VerseLookupService lookupService;
|
|
||||||
@InjectView(R.id.book_content)
|
@InjectView(R.id.book_content)
|
||||||
WebView mainContent;
|
WebView mainContent;
|
||||||
|
|
||||||
|
PublishSubject<String> titleReceiver = PublishSubject.create();
|
||||||
|
|
||||||
public BookFragment() {
|
public BookFragment() {
|
||||||
|
// We can't initialize the lookupService here since the fragment hasn't been tied
|
||||||
|
// to the parent activity yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,10 +69,8 @@ public class BookFragment extends BaseFragment {
|
|||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View rootView = inflater.inflate(R.layout.fragment_viewer_main, container,
|
View rootView = inflater.inflate(R.layout.fragment_viewer_main, container,
|
||||||
false);
|
false);
|
||||||
Injector i = (Injector) getActivity();
|
this.i = (Injector) getActivity();
|
||||||
i.inject(this);
|
i.inject(this);
|
||||||
// TODO: Defer lookup until after webview created? When exactly is WebView created?
|
|
||||||
this.lookupService = new VerseLookupService(i, mBook.get());
|
|
||||||
ButterKnife.inject(this, rootView);
|
ButterKnife.inject(this, rootView);
|
||||||
mainContent.getSettings().setJavaScriptEnabled(true);
|
mainContent.getSettings().setJavaScriptEnabled(true);
|
||||||
|
|
||||||
@ -99,7 +103,17 @@ public class BookFragment extends BaseFragment {
|
|||||||
((BibleViewer)getActivity()).setActionBarTitle(b.getInitials());
|
((BibleViewer)getActivity()).setActionBarTitle(b.getInitials());
|
||||||
mainContent.loadUrl(getString(R.string.book_html));
|
mainContent.loadUrl(getString(R.string.book_html));
|
||||||
|
|
||||||
BibleViewClient client = new BibleViewClient(b, lookupService);
|
VerseLookupService lookupService = new VerseLookupService(i, mBook.get());
|
||||||
|
BibleViewClient client = new BibleViewClient(b, lookupService, titleReceiver);
|
||||||
|
titleReceiver
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Action1<String>() {
|
||||||
|
@Override
|
||||||
|
public void call(String s) {
|
||||||
|
((BibleViewer) getActivity()).setActionBarTitle(s);
|
||||||
|
Log.d("BibleViewClient", s);
|
||||||
|
}
|
||||||
|
});
|
||||||
mainContent.setWebViewClient(client);
|
mainContent.setWebViewClient(client);
|
||||||
mainContent.addJavascriptInterface(client, "Android");
|
mainContent.addJavascriptInterface(client, "Android");
|
||||||
|
|
||||||
@ -108,15 +122,4 @@ public class BookFragment extends BaseFragment {
|
|||||||
WebView.setWebContentsDebuggingEnabled(true);
|
WebView.setWebContentsDebuggingEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Do the heavy lifting of getting the actual text for a verse
|
|
||||||
*
|
|
||||||
* @param v The verse to display
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public void displayVerse(Verse v) {
|
|
||||||
Book b = mBook.get();
|
|
||||||
lookupService.getJsonVerse(v);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,18 +8,20 @@ import org.crosswire.jsword.book.Book
|
|||||||
import org.crosswire.jsword.versification.getVersification
|
import org.crosswire.jsword.versification.getVersification
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import rx.subjects.PublishSubject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by bspeice on 9/14/14.
|
* Created by bspeice on 9/14/14.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BibleViewClient(b: Book, lookup: VerseLookupService) : WebViewClient() {
|
class BibleViewClient(val b: Book, val lookup: VerseLookupService,
|
||||||
val b = b
|
val subject: PublishSubject<String>?) : WebViewClient() {
|
||||||
val lookup = lookup
|
|
||||||
|
|
||||||
// We can receive and return only primitives and Strings. Still means we can use JSON :)
|
// We can receive and return only primitives and Strings. Still means we can use JSON :)
|
||||||
JavascriptInterface fun getVerse(ordinal: Int): String {
|
JavascriptInterface fun getVerse(ordinal: Int): String {
|
||||||
val v = Verse(b.getVersification(), ordinal)
|
val v = Verse(b.getVersification(), ordinal)
|
||||||
|
// TODO: WebView should notify us what verse it's on
|
||||||
|
subject?.onNext(v.getBook().toString() + " " + v.getChapter() + ":" + v.getVerse())
|
||||||
return lookup.getJsonVerse(v) as String
|
return lookup.getJsonVerse(v) as String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user