mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-22 07:58:20 -05:00
Revert "The kotlin migration continues..."
I like my DI annotations too much...
This reverts commit 540426a0a2
.
This commit is contained in:
parent
540426a0a2
commit
24a384d30e
@ -98,7 +98,6 @@ public class BibleViewerModules {
|
|||||||
return new BookManager();
|
return new BookManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is ever injected by more than one person, switch to extension functions in Kotlin
|
|
||||||
@Provides
|
@Provides
|
||||||
VersificationUtil provideVersificationUtil() {
|
VersificationUtil provideVersificationUtil() {
|
||||||
return new VersificationUtil();
|
return new VersificationUtil();
|
||||||
|
@ -40,7 +40,6 @@ public class BookFragment extends BaseFragment {
|
|||||||
@Inject
|
@Inject
|
||||||
@Named("MainBook")
|
@Named("MainBook")
|
||||||
Lazy<Book> mBook;
|
Lazy<Book> mBook;
|
||||||
// TODO: Once
|
|
||||||
@Inject
|
@Inject
|
||||||
VersificationUtil vUtil;
|
VersificationUtil vUtil;
|
||||||
// TODO: Factory?
|
// TODO: Factory?
|
||||||
|
@ -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<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,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<BibleBook> = 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<BibleBook> {
|
|
||||||
return Observable.from(getVersification(b).getBookIterator()!!.copyIterator())
|
|
||||||
?.filter { INTROS.contains(it) } as Observable<BibleBook>
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getBookNames(b: Book): Observable<String> {
|
|
||||||
return getBooks(b).map { getBookName(b, it as BibleBook) }
|
|
||||||
as Observable<String>
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> Iterator<T>.copyIterator(): List<T> {
|
|
||||||
var list: MutableList<T> = ArrayList() // Must be mutable
|
|
||||||
while (this.hasNext()) {
|
|
||||||
list.add(this.next())
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user