From 22fd32b26d37dd193067f3b5af8dcd2462a69e08 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Wed, 22 Oct 2014 22:21:42 -0400 Subject: [PATCH] RefreshManager going functional! --- .../manager/BookDownloadManagerTest.java | 72 +++++---- .../manager/InstalledManagerTest.java | 80 +++++----- .../manager/RefreshManagerTest.java | 68 ++++----- .../activity/downloader/BookListFragment.java | 16 +- .../downloader/DownloadActivityModules.java | 7 +- .../manager/BookDownloadManager.java | 42 +++--- .../downloader/manager/RefreshManager.java | 137 ------------------ .../downloader/manager/RefreshManager.kt | 46 ++++++ .../activity/viewer/BibleViewClient.kt | 2 +- .../service/format/osisparser/OsisParser.kt | 2 +- .../service/format/osisparser/VerseContent.kt | 2 +- .../jsword/versification/VersificationUtil.kt | 10 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 13 files changed, 205 insertions(+), 281 deletions(-) delete mode 100644 app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.java create mode 100644 app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.kt diff --git a/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/BookDownloadManagerTest.java b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/BookDownloadManagerTest.java index 8c5f633..f036bfd 100644 --- a/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/BookDownloadManagerTest.java +++ b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/BookDownloadManagerTest.java @@ -35,37 +35,6 @@ import static com.jayway.awaitility.Awaitility.await; public class BookDownloadManagerTest extends TestCase implements Injector { ObjectGraph mObjectGraph; - - /** - * Modules needed for this test case - */ - @Module(injects = {BookDownloadManager.class, - RefreshManager.class, - BookDownloadManagerTest.class}) - public static class BookDownloadManagerTestModules { - Injector i; - - BookDownloadManagerTestModules(Injector i) { - this.i = i; - } - - @Provides - @Singleton - Injector provideInjector() { - return i; - } - - @Provides @Singleton - Books provideBooks() { - return Books.installed(); - } - - @Provides @Singleton - Collection provideInstallers() { - return new InstallManager().getInstallers().values(); - } - } - @Inject BookDownloadManager bookDownloadManager; @Inject RefreshManager refreshManager; @Inject Books installedBooks; @@ -82,7 +51,7 @@ public class BookDownloadManagerTest extends TestCase implements Injector { } Observable installableBooks() { - return refreshManager.getAvailableModulesFlattened() + return refreshManager.getAvailableModulesFlat() .filter(new Func1() { @Override public Boolean call(Book book) { @@ -135,4 +104,43 @@ public class BookDownloadManagerTest extends TestCase implements Injector { await().atMost(1, TimeUnit.SECONDS) .untilTrue(jobNameMatch); } + + /** + * Modules needed for this test case + */ + @Module(injects = {BookDownloadManager.class, + RefreshManager.class, + BookDownloadManagerTest.class}) + @SuppressWarnings("unused") + public static class BookDownloadManagerTestModules { + Injector i; + + BookDownloadManagerTestModules(Injector i) { + this.i = i; + } + + @Provides + @Singleton + Injector provideInjector() { + return i; + } + + @Provides + @Singleton + Books provideBooks() { + return Books.installed(); + } + + @Provides + @Singleton + Collection provideInstallers() { + return new InstallManager().getInstallers().values(); + } + + @Provides + @Singleton + RefreshManager refreshManager(Collection installers) { + return new RefreshManager(installers); + } + } } \ No newline at end of file diff --git a/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/InstalledManagerTest.java b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/InstalledManagerTest.java index 0e42f29..323a87e 100644 --- a/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/InstalledManagerTest.java +++ b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/InstalledManagerTest.java @@ -36,40 +36,10 @@ import rx.functions.Func1; */ public class InstalledManagerTest extends TestCase implements Injector { ObjectGraph mObjectGraph; - - @Module(injects = {InstalledManager.class, - InstalledManagerTest.class, - RefreshManager.class, - BookDownloadManager.class}) - static class IMTestModules { - Injector i; - public IMTestModules(Injector i) { - this.i = i; - } - - @Provides @Singleton - Injector provideInjector() { - return this.i; - } - - @Provides @Singleton - Books provideInstalledBooks() { - return Books.installed(); - } - - @Provides - List provideInstalledBooksList(Books b) { - return b.getBooks(); - } - - @Provides @Singleton - Collection provideInstallers() { - return new InstallManager().getInstallers().values(); - } - } - - @Inject InstalledManager iM; - @Inject Books installedBooks; + @Inject + InstalledManager iM; + @Inject + Books installedBooks; @Override public void inject(Object o) { @@ -121,4 +91,46 @@ public class InstalledManagerTest extends TestCase implements Injector { }); assertFalse(foundMismatch.get()); } + + @Module(injects = {InstalledManager.class, + InstalledManagerTest.class, + RefreshManager.class, + BookDownloadManager.class}) + @SuppressWarnings("unused") + static class IMTestModules { + Injector i; + + public IMTestModules(Injector i) { + this.i = i; + } + + @Provides + @Singleton + Injector provideInjector() { + return this.i; + } + + @Provides + @Singleton + Books provideInstalledBooks() { + return Books.installed(); + } + + @Provides + List provideInstalledBooksList(Books b) { + return b.getBooks(); + } + + @Provides + @Singleton + Collection provideInstallers() { + return new InstallManager().getInstallers().values(); + } + + @Provides + @Singleton + RefreshManager refreshManager(Collection installers) { + return new RefreshManager(installers); + } + } } \ No newline at end of file diff --git a/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/RefreshManagerTest.java b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/RefreshManagerTest.java index 73c30f4..a1569a9 100644 --- a/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/RefreshManagerTest.java +++ b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/RefreshManagerTest.java @@ -1,7 +1,5 @@ package org.bspeice.minimalbible.test.activity.downloader.manager; -import com.jayway.awaitility.Awaitility; - import junit.framework.TestCase; import org.bspeice.minimalbible.Injector; @@ -26,7 +24,9 @@ import dagger.Provides; import rx.functions.Action1; import static com.jayway.awaitility.Awaitility.await; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class RefreshManagerTest extends TestCase implements Injector { @@ -35,34 +35,14 @@ public class RefreshManagerTest extends TestCase implements Injector { * for setting their own ObjectGraph. */ ObjectGraph mObjectGraph; + @Inject + RefreshManager rM; @Override public void inject(Object o) { mObjectGraph.inject(o); } - @Inject RefreshManager rM; - - @Module (injects = {RefreshManagerTest.class, RefreshManager.class}) - class RMTModules { - Injector i; - Collection installers; - - RMTModules(Injector i, Collection installers) { - this.i = i; - this.installers = installers; - } - - @Provides @Singleton - Injector provideInjector() { - return i; - } - - @Provides @Singleton - Collection provideInstallers() { - return this.installers; - } - } public void testGetAvailableModulesFlattened() throws Exception { // Environment setup final String mockBookName = "MockBook"; @@ -78,13 +58,13 @@ public class RefreshManagerTest extends TestCase implements Injector { Collection mockInstallers = new ArrayList(); mockInstallers.add(mockInstaller); - RMTModules modules = new RMTModules(this, mockInstallers); + RMTModules modules = new RMTModules(mockInstallers); mObjectGraph = ObjectGraph.create(modules); // Now the actual test mObjectGraph.inject(this); // Get the RefreshManager - rM.getAvailableModulesFlattened() + rM.getAvailableModulesFlat() .toBlocking() .forEach(new Action1() { @Override @@ -109,12 +89,12 @@ public class RefreshManagerTest extends TestCase implements Injector { Collection mockInstallers = new ArrayList(); mockInstallers.add(mockInstaller); - RMTModules modules = new RMTModules(this, mockInstallers); + RMTModules modules = new RMTModules(mockInstallers); mObjectGraph = ObjectGraph.create(modules); // And the actual test mObjectGraph.inject(this); - Installer i = rM.installerFromBook(mockBook); + Installer i = rM.installerFromBook(mockBook).toBlocking().first(); assertSame(mockInstaller, i); verify(mockInstaller).getBooks(); @@ -127,7 +107,7 @@ public class RefreshManagerTest extends TestCase implements Injector { @Override public List answer(InvocationOnMock invocationOnMock) throws Throwable { Thread.sleep(1000); // Just long enough to give us a gap between - // refresh start and complete + // refresh start and complete return bookList; } }); @@ -135,21 +115,43 @@ public class RefreshManagerTest extends TestCase implements Injector { Collection mockInstallers = new ArrayList(); mockInstallers.add(mockInstaller); - RMTModules modules = new RMTModules(this, mockInstallers); + RMTModules modules = new RMTModules(mockInstallers); mObjectGraph = ObjectGraph.create(modules); // And the actual test mObjectGraph.inject(this); // So the refresh should be kicked off at the constructor, meaning that it's not "complete" - assertFalse(rM.isRefreshComplete()); + assertFalse(rM.getRefreshComplete().get()); // But, if it's on another thread, it should finish up eventually, right? await().atMost(5, TimeUnit.SECONDS).until(new Callable() { @Override public Boolean call() throws Exception { - return rM.isRefreshComplete(); + return rM.getRefreshComplete().get(); } }); } + + @Module(injects = {RefreshManagerTest.class, RefreshManager.class}) + @SuppressWarnings("unused") + class RMTModules { + Collection installers; + + RMTModules(Collection installers) { + this.installers = installers; + } + + @Provides + @Singleton + Collection provideInstallers() { + return this.installers; + } + + @Provides + @Singleton + RefreshManager refreshManager(Collection installers) { + return new RefreshManager(installers); + } + } } \ No newline at end of file diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/BookListFragment.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/BookListFragment.java index 4957b2b..9450144 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/BookListFragment.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/BookListFragment.java @@ -18,6 +18,7 @@ import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager; import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.BookCategory; import org.crosswire.jsword.book.BookComparators; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -41,15 +42,12 @@ public class BookListFragment extends BaseFragment { */ protected static final String ARG_BOOK_CATEGORY = "book_category"; - private final String TAG = "BookListFragment"; - + @Inject + protected DownloadPrefs downloadPrefs; + protected ProgressDialog refreshDialog; @InjectView(R.id.lst_download_available) ListView downloadsAvailable; - @Inject RefreshManager refreshManager; - @Inject protected DownloadPrefs downloadPrefs; - - protected ProgressDialog refreshDialog; private LayoutInflater inflater; /** @@ -114,7 +112,7 @@ public class BookListFragment extends BaseFragment { */ private void refreshModules() { // Check if the downloadManager has already refreshed everything - if (!refreshManager.isRefreshComplete()) { + if (!refreshManager.getRefreshComplete().get()) { // downloadManager is in progress of refreshing refreshDialog = new ProgressDialog(getActivity()); refreshDialog.setMessage("Refreshing available modules..."); @@ -123,7 +121,7 @@ public class BookListFragment extends BaseFragment { } // Listen for the books! - refreshManager.getAvailableModulesFlattened() + refreshManager.getAvailableModulesFlat() .filter(new Func1() { @Override public Boolean call(Book book) { @@ -162,7 +160,7 @@ public class BookListFragment extends BaseFragment { private class DownloadDialogListener implements DialogInterface.OnClickListener { @Override - public void onClick(DialogInterface dialog, int which) { + public void onClick(@NotNull DialogInterface dialog, int which) { downloadPrefs.hasShownDownloadDialog(true); switch (which) { diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java index cef842a..46dafd6 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/DownloadActivityModules.java @@ -40,6 +40,7 @@ import de.devland.esperandro.Esperandro; addsTo = MinimalBibleModules.class, library = true ) +@SuppressWarnings("unused") public class DownloadActivityModules { DownloadActivity activity; @@ -65,7 +66,7 @@ public class DownloadActivityModules { /** * Provide the context for the DownloadActivity. We name it so that we don't have to * \@Provides a specific class, but can keep track of what exactly we mean by "Context" - * @return + * @return The DownloadActivity Context */ @Provides @Singleton @Named("DownloadActivityContext") Context provideActivityContext() { @@ -105,7 +106,7 @@ public class DownloadActivityModules { } @Provides @Singleton - RefreshManager provideRefreshManager() { - return new RefreshManager(activity); + RefreshManager provideRefreshManager(Collection installers) { + return new RefreshManager(installers); } } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/BookDownloadManager.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/BookDownloadManager.java index d2c4ef5..fd2cdac 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/BookDownloadManager.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/BookDownloadManager.java @@ -32,20 +32,15 @@ import rx.subjects.PublishSubject; //TODO: Install indexes for Bibles @Singleton public class BookDownloadManager implements WorkListener, BooksListener { - private String TAG = "BookDownloadManager"; - /** * Mapping of Job ID to the EventBus we should trigger progress on */ private final Map bookMappings; - /** * Cached copy of downloads in progress so views displaying this info can get it quickly. */ private final Map inProgressDownloads; - private final PublishSubject downloadEvents = PublishSubject.create(); - @Inject Books installedBooks; @Inject RefreshManager refreshManager; @@ -58,6 +53,18 @@ public class BookDownloadManager implements WorkListener, BooksListener { installedBooks.addBooksListener(this); } + /** + * Build what the installer creates the job name as. + * Likely prone to be brittle. + * + * @param b The book to predict the download job name of + * @return The name of the job that will/is download/ing this book + */ + + public static String getJobId(Book b) { + return "INSTALL_BOOK-" + b.getInitials(); + } + public void installBook(Book b) { downloadBook(b); addJob(getJobId(b), b); @@ -74,32 +81,19 @@ public class BookDownloadManager implements WorkListener, BooksListener { // First, look up where the Book came from Observable.just(refreshManager.installerFromBook(b)) .subscribeOn(Schedulers.io()) - .subscribe(new Action1() { + .subscribe(new Action1>() { @Override - public void call(Installer installer) { + public void call(Observable installerObservable) { try { - installer.install(b); + installerObservable.toBlocking().first().install(b); } catch (InstallException e) { - Log.d(TAG, e.getMessage()); + e.printStackTrace(); } - - getDownloadEvents() - .onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_BEGINNING, b)); } }); - } - /** - * Build what the installer creates the job name as. - * Likely prone to be brittle. - * TODO: Make sure to test that this is an accurate job name - * - * @param b The book to predict the download job name of - * @return The name of the job that will/is download/ing this book - */ - - public static String getJobId(Book b) { - return "INSTALL_BOOK-" + b.getInitials(); + getDownloadEvents() + .onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_BEGINNING, b)); } @Override diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.java deleted file mode 100644 index e6fd5d6..0000000 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.java +++ /dev/null @@ -1,137 +0,0 @@ -package org.bspeice.minimalbible.activity.downloader.manager; - -import org.bspeice.minimalbible.Injector; -import org.crosswire.jsword.book.Book; -import org.crosswire.jsword.book.install.InstallException; -import org.crosswire.jsword.book.install.Installer; - -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import rx.Observable; -import rx.functions.Action0; -import rx.functions.Action1; -import rx.functions.Func1; -import rx.schedulers.Schedulers; - -/** - * Handle refreshing the list of books available as needed - * Note that we don't refactor this class out since we need somewhere - * to track whether the refresh is done. - */ -@Singleton -public class RefreshManager { - - /** - * Cached copy of modules that are available so we don't refresh for everyone who requests it. - */ - private Observable>> availableModules; - private final AtomicBoolean refreshComplete = new AtomicBoolean(); - - @Inject - Collection installers; - - @Inject - public RefreshManager(Injector injector) { - injector.inject(this); - refreshModules(); - } - - /** - * Do the work of kicking off the AsyncTask to refresh books, and make sure we know - * when it's done. - * NOTE: This code assigns its own thread. This is because we are called privately, and - * don't want to expose this method. I don't like hiding the side effects like this, but - * in this case I'm making an exception. - * TODO: Need logic for when to do reloadBookList() vs. getBooks() - */ - private Observable>> refreshModules() { - if (availableModules == null) { - availableModules = Observable.from(installers) - .map(new Func1>>() { - @Override - public Map> call(Installer installer) { - Map> map = new HashMap>(); - try { - installer.reloadBookList(); - map.put(installer, installer.getBooks()); - } catch (InstallException e) { - e.printStackTrace(); - } - - return map; - } - }).subscribeOn(Schedulers.io()) - .cache(); - - // Set refresh complete when it is. - availableModules.observeOn(Schedulers.io()) - .subscribe(new Action1>>() { - @Override - public void call(Map> onNext) {} - }, new Action1() { - @Override - public void call(Throwable onError) {} - }, new Action0() { - @Override - public void call() { - refreshComplete.set(true); - } - }); - } - return availableModules; - } - - public Observable getAvailableModulesFlattened() { - return availableModules - // First flatten the Map to its lists - .flatMap(new Func1>, Observable>>() { - @Override - public Observable> call(Map> books) { - return Observable.from(books.values()); - } - }) - // Then flatten the lists - .flatMap(new Func1, Observable>() { - @Override - public Observable call(List t1) { - return Observable.from(t1); - } - }); - } - - - /** - * Find the installer that a Book comes from. - * TODO: Should this be @link{Observable} so we don't have to block? - * @param b The book to search for - * @return The Installer that should be used for this book. - */ - public Installer installerFromBook(final Book b) { - Map> element = availableModules - .filter(new Func1>, Boolean>() { - @Override - public Boolean call(Map> installerListMap) { - for (List element : installerListMap.values()) { - if (element.contains(b)) { - return true; - } - } - return false; - } - }) - .toBlocking() - .first(); - return element.entrySet().iterator().next().getKey(); - } - - public boolean isRefreshComplete() { - return refreshComplete.get(); - } -} diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.kt new file mode 100644 index 0000000..47e434f --- /dev/null +++ b/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/RefreshManager.kt @@ -0,0 +1,46 @@ +package org.bspeice.minimalbible.activity.downloader.manager + +import org.crosswire.jsword.book.install.Installer +import java.util.concurrent.atomic.AtomicBoolean +import rx.Observable +import org.crosswire.jsword.book.Book +import rx.schedulers.Schedulers + +/** + * Created by bspeice on 10/22/14. + */ + +class RefreshManager(val installers: Collection) { + val refreshComplete = AtomicBoolean() + val availableModules: Observable>> = + Observable.from(installers) + .map { + if (doReload()) { + it.reloadBookList() + } + mapOf(Pair(it, it.getBooks())) + } + .subscribeOn(Schedulers.io()) + .cache(); + + val availableModulesFlat: Observable + get() = availableModules + // Map -> Lists + .flatMap { Observable.from(it.values()) } + // Lists -> Single list + .flatMap { Observable.from(it) }; + + // Constructor - Split from the value creation because `subscribe` returns + // the subscriber object, not the underlying value + { + availableModules.subscribe({}, {}, { refreshComplete set true }) + } + + fun doReload(): Boolean = true + + fun installerFromBook(b: Book): Observable = Observable.just( + availableModules.filter { + it.flatMap { it.value } contains b + } + .toBlocking().first().entrySet().first().getKey()) +} \ No newline at end of file diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleViewClient.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleViewClient.kt index ebf0a9d..013e439 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleViewClient.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/activity/viewer/BibleViewClient.kt @@ -22,7 +22,7 @@ class BibleViewClient(val b: Book, val lookup: VerseLookupService, val v = Verse(b.getVersification(), ordinal) // TODO: WebView should notify us what verse it's on subject?.onNext(v.getBook().toString() + " " + v.getChapter() + ":" + v.getVerse()) - return lookup.getJsonVerse(v) as String + return lookup.getJsonVerse(v) } JavascriptInterface fun getVerses(first: Int, count: Int): String { diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/OsisParser.kt b/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/OsisParser.kt index e8eaf9a..0155074 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/OsisParser.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/OsisParser.kt @@ -33,7 +33,7 @@ class OsisParser(v: Verse) : DefaultHandler() { doWrite.pop() } override fun characters(ch: CharArray?, start: Int, length: Int) { - if (doWrite.peek() as Boolean) + if (doWrite.peek()) verseContent.appendContent(String(ch as CharArray)) } } \ No newline at end of file diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/VerseContent.kt b/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/VerseContent.kt index c1f5467..e3e6b07 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/VerseContent.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/VerseContent.kt @@ -21,7 +21,7 @@ class VerseContent(v: Verse) { public fun toJson(): String { // Lazy load Gson - not likely that we'll call this method multiple times, so // don't have to worry about a penalty there. - return Gson().toJson(this) as String + return Gson().toJson(this) } public fun appendContent(content: String) { diff --git a/app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt b/app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt index a749bee..33068e2 100644 --- a/app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt +++ b/app/src/main/kotlin/org/crosswire/jsword/versification/VersificationUtil.kt @@ -22,11 +22,11 @@ class VersificationUtil() { } fun getBookNames(b: Book): Observable { - return Observable.from(b.getVersification().getBookNames()) as Observable + return Observable.from(b.getVersification().getBookNames()) } fun getBooks(b: Book): Observable { - return Observable.from(b.getVersification().getBooks()) as Observable + return Observable.from(b.getVersification().getBooks()) } fun getChapterCount(b: Book, bibleBook: BibleBook): Int { @@ -34,7 +34,7 @@ class VersificationUtil() { } fun getBookName(b: Book, bibleBook: BibleBook): String { - return b.getVersification().getLongName(bibleBook) as String + return b.getVersification().getLongName(bibleBook) } fun getVersification(b: Book): Versification { @@ -58,7 +58,7 @@ fun Versification.getBooks(): List { } fun Versification.getBookNames(): List { - return this.getBooks().map { this.getLongName(it) as String } + return this.getBooks().map { this.getLongName(it) } } fun Versification.getChapterCount(b: BibleBook): Int { @@ -70,7 +70,7 @@ fun Book.getVersification(): Versification { this.getBookMetaData()!!.getProperty(BookMetaData.KEY_VERSIFICATION).toString() ) if (v == null) { - Log.e(getClass()!!.getSimpleName(), "Invalid book: " + this.getInitials()) + Log.e(javaClass().getSimpleName(), "Invalid book: " + this.getInitials()) throw InvalidBookException(this.getInitials()) } else return v diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3bb272e..5ace921 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Sat Jul 19 23:18:06 EDT 2014 +#Wed Oct 22 20:42:04 EDT 2014 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME