1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
package com.camilstaps.taize;
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
*
* @author Camil Staps
*/
public class BibleText {
private String book;
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
* @param verse
*/
public BibleText(String book, int chapter, int verse) {
this.book = book;
start_chap = end_chap = chapter;
start_verse = end_verse = verse;
}
/**
* Constructor for a bible text consisting of a "verse range"
* @param book
* @param start_chap
* @param start_verse
* @param end_chap
* @param end_verse
*/
public BibleText(String book, int start_chap, int start_verse, int end_chap, int end_verse) {
this.book = book;
this.start_chap = start_chap;
this.end_chap = end_chap;
this.start_verse = start_verse;
this.end_verse = end_verse;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(book);
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));
}
}
return sb.toString();
}
/**
* Get the text (without verse numbers, line breaks, etc.) of this passage
* @param context
* @param listener
*/
public void getText(Context context, final Listener<String> listener) {
String passage = "";
if (start_chap == end_chap) {
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;
}
} else {
StringBuilder passageBuilder = new StringBuilder();
passageBuilder.append(book + " " + start_chap + ":" + start_verse);
for (int i = start_chap + 1; i <= end_chap; i++)
passageBuilder.append(";" + i);
passageBuilder.append("-" + end_verse);
passage = passageBuilder.toString();
}
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();
}
});
}
}
|