From 24a384d30e26d6c14774428677f5a5799ade6a1c Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 8 Sep 2014 23:45:20 -0400 Subject: [PATCH] Revert "The kotlin migration continues..." I like my DI annotations too much... This reverts commit 540426a0a26254b04ff20a6e688a2cb86c1c8534. --- .../activity/viewer/BibleViewerModules.java | 1 - .../activity/viewer/BookFragment.java | 1 - .../viewer/bookutil/VersificationUtil.java | 62 +++++++++++++++++++ .../activity/viewer/VersificationUtil.kt | 53 ---------------- 4 files changed, 62 insertions(+), 55 deletions(-) create mode 100644 app/src/main/java/org/bspeice/minimalbible/activity/viewer/bookutil/VersificationUtil.java delete mode 100644 app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/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 94d0e0a..62190dd 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 @@ -98,7 +98,6 @@ public class BibleViewerModules { return new BookManager(); } - // If this is ever injected by more than one person, switch to extension functions in Kotlin @Provides VersificationUtil provideVersificationUtil() { return new VersificationUtil(); 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 92b132c..e868a55 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 @@ -40,7 +40,6 @@ public class BookFragment extends BaseFragment { @Inject @Named("MainBook") Lazy mBook; - // TODO: Once @Inject VersificationUtil vUtil; // TODO: Factory? 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 new file mode 100644 index 0000000..ae2787e --- /dev/null +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/bookutil/VersificationUtil.java @@ -0,0 +1,62 @@ +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/kotlin/org/bspeice/minimalbible/activity/viewer/VersificationUtil.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/VersificationUtil.kt deleted file mode 100644 index 6c7c049..0000000 --- a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/VersificationUtil.kt +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Created by bspeice on 9/8/14. - */ -package org.bspeice.minimalbible.activity.viewer.bookutil - -import org.crosswire.jsword.versification.BibleBook -import java.util.ArrayList -import org.crosswire.jsword.versification.Versification -import org.crosswire.jsword.book.Book -import org.crosswire.jsword.versification.system.Versifications -import org.crosswire.jsword.book.BookMetaData -import rx.Observable - -class VersificationUtil() { - - val INTROS: Array = array( - BibleBook.INTRO_BIBLE, - BibleBook.INTRO_OT, - BibleBook.INTRO_NT) - - public fun getVersification(b: Book): Versification { - return Versifications.instance()!!.getVersification( - b.getBookMetaData()!!.getProperty(BookMetaData.KEY_VERSIFICATION) as String - ) as Versification - } - - public fun getBookName(book: Book, bibleBook: BibleBook): String { - return getVersification(book).getLongName(bibleBook) as String - } - - public fun getChapterCount(book: Book, bibleBook: BibleBook): Int { - return getVersification(book).getLastChapter(bibleBook) - } - - public fun getBooks(b: Book): Observable { - return Observable.from(getVersification(b).getBookIterator()!!.copyIterator()) - ?.filter { INTROS.contains(it) } as Observable - } - - public fun getBookNames(b: Book): Observable { - return getBooks(b).map { getBookName(b, it as BibleBook) } - as Observable - } - -} - -fun Iterator.copyIterator(): List { - var list: MutableList = ArrayList() // Must be mutable - while (this.hasNext()) { - list.add(this.next()) - } - return list -} \ No newline at end of file