diff options
Diffstat (limited to 'app/src/main/java/com/camilstaps/taize/BibleText.java')
-rw-r--r-- | app/src/main/java/com/camilstaps/taize/BibleText.java | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/app/src/main/java/com/camilstaps/taize/BibleText.java b/app/src/main/java/com/camilstaps/taize/BibleText.java index 6a9dba8..4f73ad8 100644 --- a/app/src/main/java/com/camilstaps/taize/BibleText.java +++ b/app/src/main/java/com/camilstaps/taize/BibleText.java @@ -4,6 +4,7 @@ import android.content.Context; import com.android.volley.Response; import com.android.volley.VolleyError; +import com.camilstaps.common.Listener; /** * Class for holding some text in the Bible @@ -16,6 +17,17 @@ public class BibleText { private int start_chap, end_chap, start_verse, end_verse; /** + * Constructor for a bible text consisting of a full chapter + * @param book + * @param chapter + */ + public BibleText(String book, int chapter) { + this.book = book; + start_chap = end_chap = chapter; + start_verse = end_verse = -1; + } + + /** * Constructor for a bible text consisting of a single verse * @param book * @param chapter @@ -46,13 +58,17 @@ public class BibleText { @Override public String toString() { StringBuilder sb = new StringBuilder(book); - sb.append(' ').append(Integer.toString(start_chap)).append(':').append(Integer.toString(start_verse)); - if (start_chap != end_chap || start_verse != end_verse) { - sb.append('-'); - if (start_chap != end_chap) { - sb.append(Integer.toString(end_chap)).append('-'); + sb.append(' ').append(Integer.toString(start_chap)); + if (start_verse != -1) { + sb.append(':').append(Integer.toString(start_verse)); + + if (start_chap != end_chap || start_verse != end_verse) { + sb.append('-'); + if (start_chap != end_chap) { + sb.append(Integer.toString(end_chap)).append('-'); + } + sb.append(Integer.toString(end_verse)); } - sb.append(Integer.toString(end_verse)); } return sb.toString(); } @@ -61,13 +77,14 @@ public class BibleText { * Get the text (without verse numbers, line breaks, etc.) of this passage * @param context * @param listener - * @param errorListener */ - public void getText(Context context, Response.Listener<String> listener, Response.ErrorListener errorListener) { + public void getText(Context context, final Listener<String> listener) { String passage = ""; if (start_chap == end_chap) { - if (start_verse == end_verse) { + if (start_verse == -1) { + passage = book + " " + start_chap; + } else if (start_verse == end_verse) { passage = book + " " + start_chap + ":" + start_verse; } else { passage = book + " " + start_chap + ":" + start_verse + "-" + end_verse; @@ -81,7 +98,17 @@ public class BibleText { passage = passageBuilder.toString(); } - Bible.getPassage(context, passage, listener, errorListener); + Bible.getPassage(context, passage, new Response.Listener<String>() { + @Override + public void onResponse(String s) { + listener.success(s); + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError volleyError) { + listener.failure(); + } + }); } } |