diff --git a/MinimalBible/build.gradle b/MinimalBible/build.gradle index acfd8f7..7df2a72 100644 --- a/MinimalBible/build.gradle +++ b/MinimalBible/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'android' apply plugin: 'android-apt' -apply plugin: 'retrolambda' +//apply plugin: 'retrolambda' buildscript { repositories { @@ -8,7 +8,7 @@ buildscript { } dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.3' - classpath 'me.tatarka:gradle-retrolambda:1.3.2' + //classpath 'me.tatarka:gradle-retrolambda:1.3.2' } } @@ -75,10 +75,14 @@ android { lintOptions { abortOnError false } + + /* compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + */ + defaultConfig {} productFlavors { } diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java index 5b5a469..ff38604 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java @@ -21,6 +21,8 @@ import butterknife.InjectView; import butterknife.OnClick; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; +import rx.functions.Action1; +import rx.functions.Func1; /** * Created by bspeice on 5/20/14. @@ -59,8 +61,18 @@ public class BookItemHolder { //TODO: Refactor subscription = bookDownloadManager.getDownloadEvents() .observeOn(AndroidSchedulers.mainThread()) - .filter((event) -> event.getB().getInitials().equals(b.getInitials())) - .subscribe((event) -> displayProgress((int) event.toCircular())); + .filter(new Func1() { + @Override + public Boolean call(DLProgressEvent event) { + return event.getB().getInitials().equals(b.getInitials()); + } + }) + .subscribe(new Action1() { + @Override + public void call(DLProgressEvent event) { + BookItemHolder.this.displayProgress((int) event.toCircular()); + } + }); } private void displayInstalled() { diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java index bf2942d..90c875e 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListFragment.java @@ -15,15 +15,21 @@ import org.bspeice.minimalbible.MinimalBible; import org.bspeice.minimalbible.R; import org.bspeice.minimalbible.activities.BaseFragment; import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager; +import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.BookCategory; import org.crosswire.jsword.book.BookComparators; +import java.util.List; + import javax.inject.Inject; import butterknife.ButterKnife; import butterknife.InjectView; import rx.Observable; import rx.android.schedulers.AndroidSchedulers; +import rx.functions.Action1; +import rx.functions.Func1; +import rx.functions.Func2; /** * A placeholder fragment containing a simple view. @@ -119,22 +125,35 @@ public class BookListFragment extends BaseFragment { // Listen for the books! refreshManager.getAvailableModulesFlattened() - .filter((book) -> book.getBookCategory() == - BookCategory.fromString(getArguments().getString(ARG_BOOK_CATEGORY))) - // Repack all the books - .toSortedList((book1, book2) -> - BookComparators.getInitialComparator().compare(book1, book2)) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe((books) -> { - downloadsAvailable.setAdapter(new BookListAdapter(inflater, books)); - if (getActivity() != null) { - // On a screen rotate, getActivity() will be null. But, the activity will - // already have been set up correctly, so we don't need to worry about it. - // If not null, we need to set it up now. - setInsets(getActivity(), downloadsAvailable); + .filter(new Func1() { + @Override + public Boolean call(Book book) { + return book.getBookCategory() == + BookCategory.fromString(BookListFragment.this.getArguments() + .getString(ARG_BOOK_CATEGORY)); } - if (refreshDialog != null) { - refreshDialog.cancel(); + }) + // Repack all the books + .toSortedList(new Func2() { + @Override + public Integer call(Book book1, Book book2) { + return BookComparators.getInitialComparator().compare(book1, book2); + } + }) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Action1>() { + @Override + public void call(List books) { + downloadsAvailable.setAdapter(new BookListAdapter(inflater, books)); + if (BookListFragment.this.getActivity() != null) { + // On a screen rotate, getActivity() will be null. But, the activity will + // already have been set up correctly, so we don't need to worry about it. + // If not null, we need to set it up now. + setInsets(BookListFragment.this.getActivity(), downloadsAvailable); + } + if (refreshDialog != null) { + refreshDialog.cancel(); + } } }); } diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadThread.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadThread.java index 6fe9da5..477d61f 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadThread.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadThread.java @@ -5,9 +5,11 @@ import android.util.Log; import org.bspeice.minimalbible.MinimalBible; import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.install.InstallException; +import org.crosswire.jsword.book.install.Installer; import javax.inject.Inject; +import rx.functions.Action1; import rx.schedulers.Schedulers; /** @@ -33,14 +35,18 @@ public class BookDownloadThread { // First, look up where the Book came from refreshManager.installerFromBook(b) .subscribeOn(Schedulers.io()) - .subscribe((installer) -> { - try { - installer.install(b); - } catch (InstallException e) { - Log.d(TAG, e.getMessage()); - } + .subscribe(new Action1() { + @Override + public void call(Installer installer) { + try { + installer.install(b); + } catch (InstallException e) { + Log.d(TAG, e.getMessage()); + } - bookDownloadManager.getDownloadEvents().onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_BEGINNING, b)); + bookDownloadManager.getDownloadEvents() + .onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_BEGINNING, b)); + } }); } diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/InstalledManager.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/InstalledManager.java index dd9d4ec..505f00b 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/InstalledManager.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/InstalledManager.java @@ -66,13 +66,16 @@ public class InstalledManager implements BooksListener { if (installedBooks == null) { initialize(); } - try { - // This worked in the past, but isn't now... - // installedBooks.remove(b); - Book realBook = installedBooks.getBook(b.getInitials()); - b.getDriver().delete(realBook); - } catch (BookException e) { - Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage()); + // Not sure why we need to call this multiple times, but... + while (Books.installed().getBooks().contains(b)) { + try { + // This worked in the past, but isn't now... + // installedBooks.remove(b); + Book realBook = installedBooks.getBook(b.getInitials()); + b.getDriver().delete(realBook); + } catch (BookException e) { + Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage()); + } } } } diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java index b4abeb9..bf8c197 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java @@ -14,6 +14,10 @@ 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.functions.Func2; import rx.schedulers.Schedulers; /** @@ -44,16 +48,30 @@ public class RefreshManager { private void refreshModules() { if (availableModules == null) { availableModules = Observable.from(downloadManager.getInstallers().values()) - .map(installer -> { - Map> map = new HashMap>(); - map.put(installer, installer.getBooks()); - return map; + .map(new Func1>>() { + @Override + public Map> call(Installer installer) { + Map> map = new HashMap>(); + map.put(installer, installer.getBooks()); + return map; + } }).subscribeOn(Schedulers.io()) .cache(); // Set refresh complete when it is. availableModules.observeOn(Schedulers.io()) - .subscribe((onNext) -> {}, (onError) -> {}, () -> refreshComplete.set(true)); + .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); + } + }); } } @@ -64,9 +82,19 @@ public class RefreshManager { public Observable getAvailableModulesFlattened() { return availableModules // First flatten the Map to its lists - .flatMap((books) -> Observable.from(books.values())) + .flatMap(new Func1>, Observable>>() { + @Override + public Observable> call(Map> books) { + return Observable.from(books.values()); + } + }) // Then flatten the lists - .flatMap(Observable::from); + .flatMap(new Func1, Observable>() { + @Override + public Observable call(List t1) { + return Observable.from(t1); + } + }); } /** @@ -74,12 +102,16 @@ public class RefreshManager { * @return The cached book list, or null */ public List getBookList() { - List availableList = new ArrayList<>(); - availableModules.reduce(availableList, (books, installerListMap) -> { - for (List l : installerListMap.values()) { - books.addAll(l); + List availableList = new ArrayList(); + availableModules.reduce(availableList, + new Func2, Map>, List>() { + @Override + public List call(List books, Map> installerListMap) { + for (List l : installerListMap.values()) { + books.addAll(l); + } + return books; } - return books; }); return availableList; } @@ -89,17 +121,25 @@ public class RefreshManager { * @param b The book to search for * @return The Installer that should be used for this book. */ - public Observable installerFromBook(Book b) { - return availableModules.filter(installerListMap -> { - for (List element : installerListMap.values()) { - if (element.contains(b)) { - return true; + public Observable installerFromBook(final Book b) { + return availableModules.filter(new Func1>, Boolean>() { + @Override + public Boolean call(Map> installerListMap) { + for (List element : installerListMap.values()) { + if (element.contains(b)) { + return true; + } } + return false; } - return false; }) .first() - .map(element -> element.entrySet().iterator().next().getKey()); + .map(new Func1>, Installer>() { + @Override + public Installer call(Map> element) { + return element.entrySet().iterator().next().getKey(); + } + }); } public boolean isRefreshComplete() { diff --git a/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java b/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java index 09d06d7..990cd11 100644 --- a/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java +++ b/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java @@ -67,7 +67,12 @@ public class DownloadActivityTest extends InstrumentationTestCase { final Book testBook = i.getBooks().get(0); bdm.installBook(testBook); await().atMost(30, TimeUnit.SECONDS) - .until(() -> Books.installed().getBooks().contains(testBook)); + .until(new Callable() { + @Override + public Boolean call() throws Exception { + return Books.installed().getBooks().contains(testBook); + } + }); // Validate that we can actually do something with the book // TODO: Validate that the book exists on the filesystem too @@ -83,7 +88,12 @@ public class DownloadActivityTest extends InstrumentationTestCase { // TODO: Validate that the book is off the filesystem im.removeBook(testBook); await().atMost(10, TimeUnit.SECONDS) - .until(() -> !Books.installed().getBooks().contains(testBook)); + .until(new Callable() { + @Override + public Boolean call() throws Exception { + return !Books.installed().getBooks().contains(testBook); + } + }); } }