mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-04 23:28:19 -05:00
Displaying chapter and verse headers now
This commit is contained in:
parent
3eb4b77cdb
commit
4d0a8618a8
@ -4,7 +4,11 @@
|
||||
</head>
|
||||
<body ng-controller="BookCtrl" id="bookController">
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
16
app/src/main/assets/dist/book-bundle.js
vendored
16
app/src/main/assets/dist/book-bundle.js
vendored
@ -8,22 +8,24 @@ require('angular');
|
||||
app = angular.module('bookApp', []);
|
||||
|
||||
app.controller('BookCtrl', [
|
||||
'$scope', function($scope) {
|
||||
'$scope', '$filter', function($scope, $filter) {
|
||||
$scope.verses = [];
|
||||
return $scope.appendVerse = function(text) {
|
||||
return $scope.verses.push({
|
||||
'text': text
|
||||
});
|
||||
$scope.order_verses = function() {
|
||||
return $scope.verses = $filter('orderBy')($scope.verses, 'id', false);
|
||||
};
|
||||
return $scope.appendVerse = function(verse) {
|
||||
$scope.verses.push(verse);
|
||||
return $scope.order_verses();
|
||||
};
|
||||
}
|
||||
]);
|
||||
|
||||
controller = "#bookController";
|
||||
|
||||
window.appendVerse = function(text) {
|
||||
window.appendVerse = function(jsonVerseString) {
|
||||
var scope;
|
||||
scope = angular.element($("#bookController")).scope();
|
||||
scope.appendVerse(text);
|
||||
scope.appendVerse(angular.fromJson(jsonVerseString));
|
||||
return scope.$apply();
|
||||
};
|
||||
|
||||
|
@ -3,11 +3,15 @@ require 'angular'
|
||||
|
||||
app = angular.module('bookApp', [])
|
||||
|
||||
app.controller 'BookCtrl', ['$scope', ($scope) ->
|
||||
app.controller 'BookCtrl', ['$scope', '$filter', ($scope, $filter) ->
|
||||
$scope.verses = []
|
||||
|
||||
$scope.appendVerse = (text) ->
|
||||
$scope.verses.push {'text': text}
|
||||
$scope.order_verses = ->
|
||||
$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.
|
||||
@ -15,9 +19,9 @@ app.controller 'BookCtrl', ['$scope', ($scope) ->
|
||||
# etc. to grab the scope ahead of time and re-use it.
|
||||
controller = "#bookController"
|
||||
|
||||
window.appendVerse = (text) ->
|
||||
window.appendVerse = (jsonVerseString) ->
|
||||
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
|
||||
scope.$apply()
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user