mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-12-22 22:58:16 -05:00
Kotlin migration continues...
This commit is contained in:
parent
f05e50292e
commit
2ae714a935
@ -3,9 +3,9 @@ package org.bspeice.minimalbible.activity.viewer;
|
||||
import android.util.Log;
|
||||
|
||||
import org.bspeice.minimalbible.activity.navigation.ExpListNavAdapter;
|
||||
import org.bspeice.minimalbible.activity.viewer.bookutil.VersificationUtil;
|
||||
import org.bspeice.minimalbible.service.book.VerseLookupModules;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.versification.VersificationUtil;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
@ -14,13 +14,11 @@ import android.webkit.WebViewClient;
|
||||
import org.bspeice.minimalbible.Injector;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activity.BaseFragment;
|
||||
import org.bspeice.minimalbible.activity.viewer.bookutil.VersificationUtil;
|
||||
import org.bspeice.minimalbible.service.book.VerseLookupService;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.passage.Verse;
|
||||
import org.crosswire.jsword.versification.BibleBook;
|
||||
|
||||
import java.util.List;
|
||||
import org.crosswire.jsword.versification.VersificationUtil;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@ -29,8 +27,6 @@ import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import dagger.Lazy;
|
||||
|
||||
import static org.bspeice.minimalbible.util.StringUtil.joinString;
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
@ -160,9 +156,4 @@ public class BookFragment extends BaseFragment {
|
||||
private void invokeJavascript(String function, Object arg) {
|
||||
mainContent.loadUrl("javascript:" + function + "('" + arg.toString() + "')");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void invokeJavascript(String function, List<Object> args) {
|
||||
mainContent.loadUrl("javascript:" + function + "(" + joinString(",", args.toArray()) + ")");
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ import org.bspeice.minimalbible.Injector;
|
||||
import org.bspeice.minimalbible.R;
|
||||
import org.bspeice.minimalbible.activity.navigation.ExpListNavAdapter;
|
||||
import org.bspeice.minimalbible.activity.navigation.NavDrawerFragment;
|
||||
import org.bspeice.minimalbible.activity.viewer.bookutil.VersificationUtil;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.versification.BibleBook;
|
||||
import org.crosswire.jsword.versification.VersificationUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -1,62 +0,0 @@
|
||||
package org.bspeice.minimalbible.activity.viewer.bookutil;
|
||||
|
||||
import org.bspeice.minimalbible.util.IteratorUtil;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.BookMetaData;
|
||||
import org.crosswire.jsword.versification.BibleBook;
|
||||
import org.crosswire.jsword.versification.Versification;
|
||||
import org.crosswire.jsword.versification.system.Versifications;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.functions.Func1;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 7/11/14.
|
||||
*/
|
||||
public class VersificationUtil {
|
||||
|
||||
private static final List<BibleBook> INTROS = new ArrayList<BibleBook>() {{
|
||||
add(BibleBook.INTRO_BIBLE);
|
||||
add(BibleBook.INTRO_OT);
|
||||
add(BibleBook.INTRO_NT);
|
||||
}};
|
||||
|
||||
// TODO: Cache the versification?
|
||||
public Versification getVersification(Book b) {
|
||||
return Versifications.instance().getVersification(
|
||||
(String) b.getBookMetaData().getProperty(BookMetaData.KEY_VERSIFICATION)
|
||||
);
|
||||
}
|
||||
|
||||
public Observable<BibleBook> getBooks(Book b) {
|
||||
Versification v = getVersification(b);
|
||||
return Observable.from(IteratorUtil.copyIterator(v.getBookIterator()))
|
||||
.filter(new Func1<BibleBook, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(BibleBook bibleBook) {
|
||||
return !INTROS.contains(bibleBook);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Observable<String> getBookNames(final Book b) {
|
||||
return getBooks(b)
|
||||
.map(new Func1<BibleBook, String>() {
|
||||
@Override
|
||||
public String call(BibleBook bibleBook) {
|
||||
return getBookName(b, bibleBook);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Integer getChapterCount(Book b, BibleBook bibleBook) {
|
||||
return getVersification(b).getLastChapter(bibleBook);
|
||||
}
|
||||
|
||||
public String getBookName(Book book, BibleBook bibleBook) {
|
||||
return getVersification(book).getLongName(bibleBook);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package org.bspeice.minimalbible.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 7/11/14.
|
||||
*/
|
||||
public class IteratorUtil {
|
||||
public static <T> List<T> copyIterator(Iterator<T> iter) {
|
||||
List<T> copy = new ArrayList<T>();
|
||||
while (iter.hasNext())
|
||||
copy.add(iter.next());
|
||||
return copy;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package org.bspeice.minimalbible.util;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 8/3/14.
|
||||
*/
|
||||
public class StringUtil {
|
||||
|
||||
// Convenience from http://stackoverflow.com/a/17795110/1454178
|
||||
public static String joinString(String join, Object... strings) {
|
||||
if (strings == null || strings.length == 0) {
|
||||
return "";
|
||||
} else if (strings.length == 1) {
|
||||
return strings[0].toString();
|
||||
} else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(strings[0]);
|
||||
for (int i = 1; i < strings.length; i++) {
|
||||
sb.append(join).append(strings[i].toString());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package org.crosswire.jsword.versification
|
||||
|
||||
import org.crosswire.jsword.book.Book
|
||||
import java.util.ArrayList
|
||||
import org.crosswire.jsword.versification.system.Versifications
|
||||
import org.crosswire.jsword.book.BookMetaData
|
||||
import rx.Observable
|
||||
|
||||
/**
|
||||
* Created by bspeice on 9/10/14.
|
||||
*/
|
||||
|
||||
class VersificationUtil() {
|
||||
class object {
|
||||
val INTROS = array(
|
||||
BibleBook.INTRO_BIBLE,
|
||||
BibleBook.INTRO_OT,
|
||||
BibleBook.INTRO_NT
|
||||
)
|
||||
}
|
||||
|
||||
fun getBookNames(b: Book): Observable<String> {
|
||||
return Observable.from(b.getVersification().getBookNames(b)) as Observable
|
||||
}
|
||||
|
||||
fun getBooks(b: Book): Observable<BibleBook> {
|
||||
return Observable.from(b.getVersification().getBooks(b)) as Observable
|
||||
}
|
||||
|
||||
fun getChapterCount(b: Book, bibleBook: BibleBook): Int {
|
||||
return b.getVersification().getChapterCount(bibleBook)
|
||||
}
|
||||
|
||||
fun getBookName(b: Book, bibleBook: BibleBook): String {
|
||||
return b.getVersification().getLongName(bibleBook) as String
|
||||
}
|
||||
|
||||
fun getVersification(b: Book): Versification {
|
||||
return b.getVersification()
|
||||
}
|
||||
}
|
||||
|
||||
// There's probably a better way to do this
|
||||
fun <T> Iterator<T>.iterable(): Iterable<T> {
|
||||
val list: MutableList<T> = ArrayList()
|
||||
while (this.hasNext()) {
|
||||
list.add(this.next())
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
fun Versification.getBooks(b: Book): List<BibleBook> {
|
||||
return this.getBookIterator()!!.iterable()
|
||||
.filter { VersificationUtil.INTROS.contains(it) }
|
||||
}
|
||||
|
||||
fun Versification.getBookNames(b: Book): List<String> {
|
||||
return this.getBooks(b).map { this.getLongName(it) as String }
|
||||
}
|
||||
|
||||
fun Versification.getChapterCount(b: BibleBook): Int {
|
||||
return this.getLastChapter(b)
|
||||
}
|
||||
|
||||
fun Book.getVersification(): Versification {
|
||||
return Versifications.instance()!!.getVersification(
|
||||
this.getBookMetaData()!!.getProperty(BookMetaData.KEY_VERSIFICATION) as String
|
||||
) as Versification
|
||||
}
|
Loading…
Reference in New Issue
Block a user