From 2ae714a935fdd0fb3d990b7e5f3ec47f16136e28 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Wed, 10 Sep 2014 23:31:16 -0400 Subject: [PATCH] Kotlin migration continues... --- .../activity/viewer/BibleViewerModules.java | 2 +- .../activity/viewer/BookFragment.java | 11 +-- .../viewer/ExpListNavDrawerFragment.java | 2 +- .../viewer/bookutil/VersificationUtil.java | 62 ---------------- .../minimalbible/util/IteratorUtil.java | 17 ----- .../bspeice/minimalbible/util/StringUtil.java | 23 ------ .../jsword/versification/VersificationUtil.kt | 70 +++++++++++++++++++ 7 files changed, 73 insertions(+), 114 deletions(-) delete mode 100644 app/src/main/java/org/bspeice/minimalbible/activity/viewer/bookutil/VersificationUtil.java delete mode 100644 app/src/main/java/org/bspeice/minimalbible/util/IteratorUtil.java delete mode 100644 app/src/main/java/org/bspeice/minimalbible/util/StringUtil.java create mode 100644 app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java index 62190dd..76eb24c 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BibleViewerModules.java @@ -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; diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java index 2f4908b..6b18680 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/BookFragment.java @@ -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 args) { - mainContent.loadUrl("javascript:" + function + "(" + joinString(",", args.toArray()) + ")"); - } } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/ExpListNavDrawerFragment.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/ExpListNavDrawerFragment.java index 272e963..c8e8e8e 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/ExpListNavDrawerFragment.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/ExpListNavDrawerFragment.java @@ -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; diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/bookutil/VersificationUtil.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/bookutil/VersificationUtil.java deleted file mode 100644 index ae2787e..0000000 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/bookutil/VersificationUtil.java +++ /dev/null @@ -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 INTROS = new ArrayList() {{ - 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 getBooks(Book b) { - Versification v = getVersification(b); - return Observable.from(IteratorUtil.copyIterator(v.getBookIterator())) - .filter(new Func1() { - @Override - public Boolean call(BibleBook bibleBook) { - return !INTROS.contains(bibleBook); - } - }); - } - - public Observable getBookNames(final Book b) { - return getBooks(b) - .map(new Func1() { - @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); - } -} diff --git a/app/src/main/java/org/bspeice/minimalbible/util/IteratorUtil.java b/app/src/main/java/org/bspeice/minimalbible/util/IteratorUtil.java deleted file mode 100644 index f8603f5..0000000 --- a/app/src/main/java/org/bspeice/minimalbible/util/IteratorUtil.java +++ /dev/null @@ -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 List copyIterator(Iterator iter) { - List copy = new ArrayList(); - while (iter.hasNext()) - copy.add(iter.next()); - return copy; - } -} diff --git a/app/src/main/java/org/bspeice/minimalbible/util/StringUtil.java b/app/src/main/java/org/bspeice/minimalbible/util/StringUtil.java deleted file mode 100644 index c969b2c..0000000 --- a/app/src/main/java/org/bspeice/minimalbible/util/StringUtil.java +++ /dev/null @@ -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(); - } - } -} diff --git a/app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt b/app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt new file mode 100644 index 0000000..6964b56 --- /dev/null +++ b/app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt @@ -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 { + return Observable.from(b.getVersification().getBookNames(b)) as Observable + } + + fun getBooks(b: Book): Observable { + 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 Iterator.iterable(): Iterable { + val list: MutableList = ArrayList() + while (this.hasNext()) { + list.add(this.next()) + } + + return list +} + +fun Versification.getBooks(b: Book): List { + return this.getBookIterator()!!.iterable() + .filter { VersificationUtil.INTROS.contains(it) } +} + +fun Versification.getBookNames(b: Book): List { + 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 +} \ No newline at end of file