mirror of
https://github.com/MinimalBible/MinimalBible
synced 2025-07-12 03:04:43 -04:00
Displaying chapter and verse headers now
This commit is contained in:
@ -114,7 +114,8 @@ public class BookFragment extends BaseFragment {
|
||||
Verse initial = new Verse(vUtil.getVersification(mBook.get()),
|
||||
BibleBook.GEN, 1, 1);
|
||||
super.onPageFinished(view, url);
|
||||
invokeJavascript("appendVerse", lookupService.getHTMLVerse(initial));
|
||||
Log.e(getClass().getSimpleName(), lookupService.getJsonVerse(initial));
|
||||
invokeJavascript("appendVerse", lookupService.getJsonVerse(initial));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -148,7 +149,7 @@ public class BookFragment extends BaseFragment {
|
||||
@SuppressWarnings("unused")
|
||||
public void displayVerse(Verse v) {
|
||||
Book b = mBook.get();
|
||||
lookupService.getHTMLVerse(v);
|
||||
lookupService.getJsonVerse(v);
|
||||
}
|
||||
|
||||
/*-----------------------------------------
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.bspeice.minimalbible.service.book;
|
||||
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
|
||||
import org.bspeice.minimalbible.Injector;
|
||||
import org.bspeice.minimalbible.service.format.osisparser.OsisParser;
|
||||
@ -56,9 +55,9 @@ public class VerseLookupService implements Action1<Verse> {
|
||||
* In all cases, notify that we're looking up a verse so we can get the surrounding ones.
|
||||
*
|
||||
* @param v The verse to look up
|
||||
* @return The HTML text for this verse (\<p\/>)
|
||||
* @return The JSON object for this verse (\<p\/>)
|
||||
*/
|
||||
public String getHTMLVerse(Verse v) {
|
||||
public String getJsonVerse(Verse v) {
|
||||
if (contains(v)) {
|
||||
return cache.get(getEntryName(v));
|
||||
} else {
|
||||
@ -72,20 +71,19 @@ public class VerseLookupService implements Action1<Verse> {
|
||||
|
||||
/**
|
||||
* Perform the ugly work of getting the actual data for a verse
|
||||
* TODO: Return a verse object, JS should be left to templating.
|
||||
* Note that we build the verse object, JS should be left to determine how
|
||||
* it is displayed.
|
||||
*
|
||||
* @param v The verse to look up
|
||||
* @return The string content of this verse
|
||||
* @return The JSON content of this verse
|
||||
*/
|
||||
public String doVerseLookup(Verse v) {
|
||||
BookData bookData = new BookData(book, v);
|
||||
try {
|
||||
SAXEventProvider provider = bookData.getSAXEventProvider();
|
||||
// OsisToHtmlSaxHandler handler = new OsisToHtmlSaxHandler(new OsisToHtmlParameters());
|
||||
OsisParser handler = new OsisParser(v);
|
||||
provider.provideSAXEvents(handler);
|
||||
Log.e(this.getClass().getName(), handler.toString());
|
||||
return handler.getContent().getContent();
|
||||
return handler.getContent().toJson();
|
||||
} catch (BookException e) {
|
||||
e.printStackTrace();
|
||||
return "Unable to locate " + v.toString() + "!";
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.bspeice.minimalbible.service.format.osisparser;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.crosswire.jsword.book.OSISUtil;
|
||||
import org.crosswire.jsword.passage.Verse;
|
||||
import org.xml.sax.Attributes;
|
||||
@ -9,17 +11,18 @@ import org.xml.sax.helpers.DefaultHandler;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 9/8/14.
|
||||
* Parse a single verse into a VerseContent object.
|
||||
* Need to benchmark if I should process ranges at a time...
|
||||
*/
|
||||
public class OsisParser extends DefaultHandler {
|
||||
|
||||
VerseContent verseContent;
|
||||
// ArrayDeque requires API 9
|
||||
Stack<Boolean> doWrite;
|
||||
Verse verse;
|
||||
|
||||
public OsisParser(Verse v) {
|
||||
this.verse = v;
|
||||
verseContent = new VerseContent(v);
|
||||
doWrite = new Stack<Boolean>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,7 +32,6 @@ public class OsisParser extends DefaultHandler {
|
||||
|
||||
if (name.equals(OSISUtil.OSIS_ELEMENT_VERSE)) {
|
||||
doWrite.push(true);
|
||||
verseContent.setId(getId(attributes));
|
||||
} else {
|
||||
doWrite.push(false);
|
||||
}
|
||||
@ -43,15 +45,11 @@ public class OsisParser extends DefaultHandler {
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
if (ch != null && doWrite.peek()) {
|
||||
verseContent.appendContent(new String(ch));
|
||||
Log.e(getClass().getName(), new String(ch, start, length));
|
||||
verseContent.appendContent(new String(ch, start, length));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDocument() throws SAXException {
|
||||
super.startDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endDocument() throws SAXException {
|
||||
super.endDocument();
|
||||
|
@ -1,7 +1,10 @@
|
||||
package org.bspeice.minimalbible.service.format.osisparser;
|
||||
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.crosswire.jsword.passage.Verse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -9,10 +12,23 @@ import java.util.List;
|
||||
*/
|
||||
public class VerseContent {
|
||||
private int id;
|
||||
private String content;
|
||||
private String chapterTitle;
|
||||
private String paraTitle;
|
||||
private List<VerseReference> references;
|
||||
private String bookName = "";
|
||||
private int chapter;
|
||||
private int verseNum;
|
||||
private String content = "";
|
||||
private String chapterTitle = "";
|
||||
private String paraTitle = "";
|
||||
private List<VerseReference> references = new ArrayList<VerseReference>();
|
||||
|
||||
public VerseContent() {
|
||||
}
|
||||
|
||||
public VerseContent(Verse v) {
|
||||
this.id = v.getOrdinal();
|
||||
this.bookName = v.getBook().toString();
|
||||
this.chapter = v.getChapter();
|
||||
this.verseNum = v.getVerse();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
@ -58,7 +74,37 @@ public class VerseContent {
|
||||
this.content += content;
|
||||
}
|
||||
|
||||
public void appendReference(VerseReference reference) {
|
||||
this.references.add(reference);
|
||||
}
|
||||
|
||||
public String getBookName() {
|
||||
return bookName;
|
||||
}
|
||||
|
||||
public void setBookName(String bookName) {
|
||||
this.bookName = bookName;
|
||||
}
|
||||
|
||||
public int getChapter() {
|
||||
return chapter;
|
||||
}
|
||||
|
||||
public void setChapter(int chapter) {
|
||||
this.chapter = chapter;
|
||||
}
|
||||
|
||||
public int getVerseNum() {
|
||||
return verseNum;
|
||||
}
|
||||
|
||||
public void setVerseNum(int verseNum) {
|
||||
this.verseNum = verseNum;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
throw new NotImplementedException("JSON conversion not implemented yet!");
|
||||
// Lazy load Gson - not likely that we'll call this method multiple times, so
|
||||
// don't have to worry about a penalty there.
|
||||
return new Gson().toJson(this);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user