Displaying chapter and verse headers now

This commit is contained in:
Bradlee Speice 2014-09-09 23:05:58 -04:00
parent 3eb4b77cdb
commit 4d0a8618a8
7 changed files with 92 additions and 39 deletions

View File

@ -4,7 +4,11 @@
</head> </head>
<body ng-controller="BookCtrl" id="bookController"> <body ng-controller="BookCtrl" id="bookController">
<div ng-repeat="verse in verses"> <div ng-repeat="verse in verses">
{{ verse.text }} <h3 style="display: inline;" ng-show="verse.verseNum === 1">
{{ verse.chapter }}
</h3>
<sup ng-show="verse.verseNum !== 1">{{ verse.verseNum }}</sup>
{{ verse.content }}
</div> </div>
</body> </body>
</html> </html>

View File

@ -8,22 +8,24 @@ require('angular');
app = angular.module('bookApp', []); app = angular.module('bookApp', []);
app.controller('BookCtrl', [ app.controller('BookCtrl', [
'$scope', function($scope) { '$scope', '$filter', function($scope, $filter) {
$scope.verses = []; $scope.verses = [];
return $scope.appendVerse = function(text) { $scope.order_verses = function() {
return $scope.verses.push({ return $scope.verses = $filter('orderBy')($scope.verses, 'id', false);
'text': text };
}); return $scope.appendVerse = function(verse) {
$scope.verses.push(verse);
return $scope.order_verses();
}; };
} }
]); ]);
controller = "#bookController"; controller = "#bookController";
window.appendVerse = function(text) { window.appendVerse = function(jsonVerseString) {
var scope; var scope;
scope = angular.element($("#bookController")).scope(); scope = angular.element($("#bookController")).scope();
scope.appendVerse(text); scope.appendVerse(angular.fromJson(jsonVerseString));
return scope.$apply(); return scope.$apply();
}; };

View File

@ -3,11 +3,15 @@ require 'angular'
app = angular.module('bookApp', []) app = angular.module('bookApp', [])
app.controller 'BookCtrl', ['$scope', ($scope) -> app.controller 'BookCtrl', ['$scope', '$filter', ($scope, $filter) ->
$scope.verses = [] $scope.verses = []
$scope.appendVerse = (text) -> $scope.order_verses = ->
$scope.verses.push {'text': text} $scope.verses = $filter('orderBy')($scope.verses, 'id', false)
$scope.appendVerse = (verse) ->
$scope.verses.push verse
$scope.order_verses()
] ]
# Due to page initialization, we can only store the controller string. # Due to page initialization, we can only store the controller string.
@ -15,9 +19,9 @@ app.controller 'BookCtrl', ['$scope', ($scope) ->
# etc. to grab the scope ahead of time and re-use it. # etc. to grab the scope ahead of time and re-use it.
controller = "#bookController" controller = "#bookController"
window.appendVerse = (text) -> window.appendVerse = (jsonVerseString) ->
scope = angular.element($("#bookController")).scope() scope = angular.element($("#bookController")).scope()
scope.appendVerse text scope.appendVerse angular.fromJson jsonVerseString
# Since we're calling outside of angular, we need to manually apply # Since we're calling outside of angular, we need to manually apply
scope.$apply() scope.$apply()

View File

@ -114,7 +114,8 @@ public class BookFragment extends BaseFragment {
Verse initial = new Verse(vUtil.getVersification(mBook.get()), Verse initial = new Verse(vUtil.getVersification(mBook.get()),
BibleBook.GEN, 1, 1); BibleBook.GEN, 1, 1);
super.onPageFinished(view, url); super.onPageFinished(view, url);
invokeJavascript("appendVerse", lookupService.getHTMLVerse(initial)); Log.e(getClass().getSimpleName(), lookupService.getJsonVerse(initial));
invokeJavascript("appendVerse", lookupService.getJsonVerse(initial));
} }
@Override @Override
@ -148,7 +149,7 @@ public class BookFragment extends BaseFragment {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void displayVerse(Verse v) { public void displayVerse(Verse v) {
Book b = mBook.get(); Book b = mBook.get();
lookupService.getHTMLVerse(v); lookupService.getJsonVerse(v);
} }
/*----------------------------------------- /*-----------------------------------------

View File

@ -1,7 +1,6 @@
package org.bspeice.minimalbible.service.book; package org.bspeice.minimalbible.service.book;
import android.support.v4.util.LruCache; import android.support.v4.util.LruCache;
import android.util.Log;
import org.bspeice.minimalbible.Injector; import org.bspeice.minimalbible.Injector;
import org.bspeice.minimalbible.service.format.osisparser.OsisParser; 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. * 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 * @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)) { if (contains(v)) {
return cache.get(getEntryName(v)); return cache.get(getEntryName(v));
} else { } else {
@ -72,20 +71,19 @@ public class VerseLookupService implements Action1<Verse> {
/** /**
* Perform the ugly work of getting the actual data for a 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 * @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) { public String doVerseLookup(Verse v) {
BookData bookData = new BookData(book, v); BookData bookData = new BookData(book, v);
try { try {
SAXEventProvider provider = bookData.getSAXEventProvider(); SAXEventProvider provider = bookData.getSAXEventProvider();
// OsisToHtmlSaxHandler handler = new OsisToHtmlSaxHandler(new OsisToHtmlParameters());
OsisParser handler = new OsisParser(v); OsisParser handler = new OsisParser(v);
provider.provideSAXEvents(handler); provider.provideSAXEvents(handler);
Log.e(this.getClass().getName(), handler.toString()); return handler.getContent().toJson();
return handler.getContent().getContent();
} catch (BookException e) { } catch (BookException e) {
e.printStackTrace(); e.printStackTrace();
return "Unable to locate " + v.toString() + "!"; return "Unable to locate " + v.toString() + "!";

View File

@ -1,5 +1,7 @@
package org.bspeice.minimalbible.service.format.osisparser; package org.bspeice.minimalbible.service.format.osisparser;
import android.util.Log;
import org.crosswire.jsword.book.OSISUtil; import org.crosswire.jsword.book.OSISUtil;
import org.crosswire.jsword.passage.Verse; import org.crosswire.jsword.passage.Verse;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -9,17 +11,18 @@ import org.xml.sax.helpers.DefaultHandler;
import java.util.Stack; 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 { public class OsisParser extends DefaultHandler {
VerseContent verseContent; VerseContent verseContent;
// ArrayDeque requires API 9 // ArrayDeque requires API 9
Stack<Boolean> doWrite; Stack<Boolean> doWrite;
Verse verse;
public OsisParser(Verse v) { public OsisParser(Verse v) {
this.verse = v; verseContent = new VerseContent(v);
doWrite = new Stack<Boolean>();
} }
@Override @Override
@ -29,7 +32,6 @@ public class OsisParser extends DefaultHandler {
if (name.equals(OSISUtil.OSIS_ELEMENT_VERSE)) { if (name.equals(OSISUtil.OSIS_ELEMENT_VERSE)) {
doWrite.push(true); doWrite.push(true);
verseContent.setId(getId(attributes));
} else { } else {
doWrite.push(false); doWrite.push(false);
} }
@ -43,15 +45,11 @@ public class OsisParser extends DefaultHandler {
@Override @Override
public void characters(char[] ch, int start, int length) throws SAXException { public void characters(char[] ch, int start, int length) throws SAXException {
if (ch != null && doWrite.peek()) { 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 @Override
public void endDocument() throws SAXException { public void endDocument() throws SAXException {
super.endDocument(); super.endDocument();

View File

@ -1,7 +1,10 @@
package org.bspeice.minimalbible.service.format.osisparser; 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; import java.util.List;
/** /**
@ -9,10 +12,23 @@ import java.util.List;
*/ */
public class VerseContent { public class VerseContent {
private int id; private int id;
private String content; private String bookName = "";
private String chapterTitle; private int chapter;
private String paraTitle; private int verseNum;
private List<VerseReference> references; 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() { public int getId() {
return id; return id;
@ -58,7 +74,37 @@ public class VerseContent {
this.content += content; 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() { 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);
} }
} }