[broken] BookListFragment to Rx

This commit is contained in:
Bradlee Speice 2014-06-10 22:56:52 -04:00
parent 6eb5f66dcc
commit fb0c5fdaaa
2 changed files with 16 additions and 15 deletions

View File

@ -24,6 +24,7 @@ import org.crosswire.jsword.book.BookComparators;
import org.crosswire.jsword.book.BookFilter; import org.crosswire.jsword.book.BookFilter;
import org.crosswire.jsword.book.FilterUtil; import org.crosswire.jsword.book.FilterUtil;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -31,6 +32,7 @@ import javax.inject.Inject;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.InjectView; import butterknife.InjectView;
import rx.android.schedulers.AndroidSchedulers;
/** /**
* A placeholder fragment containing a simple view. * A placeholder fragment containing a simple view.
@ -118,28 +120,23 @@ public class BookListFragment extends BaseFragment {
*/ */
private void refreshModules() { private void refreshModules() {
// Check if the downloadManager has already refreshed everything // Check if the downloadManager has already refreshed everything
List<Book> bookList = refreshManager.getBookList(); if (!refreshManager.isRefreshComplete()) {
if (bookList == null) {
// downloadManager is in progress of refreshing // downloadManager is in progress of refreshing
downloadManager.getDownloadBus().register(this);
refreshDialog = new ProgressDialog(getActivity()); refreshDialog = new ProgressDialog(getActivity());
refreshDialog.setMessage("Refreshing available modules..."); refreshDialog.setMessage("Refreshing available modules...");
refreshDialog.setCancelable(false); refreshDialog.setCancelable(false);
refreshDialog.show(); refreshDialog.show();
} else {
displayBooks(bookList);
}
} }
/** // Listen for the books!
* Used by GreenRobot for notifying us that the book refresh is complete refreshManager.getAvailableModules().subscribeOn(AndroidSchedulers.mainThread())
*/ .reduce(new ArrayList<Book>(), (books, installerListMap) -> {
@SuppressWarnings("unused") for (List<Book> l : installerListMap.values()) {
public void onEventMainThread(EventBookList event) { books.addAll(l);
if (refreshDialog != null) {
refreshDialog.cancel();
} }
displayBooks(event.getBookList()); return books;
}).take(1)
.subscribe((books) -> displayBooks(books));
} }
/** /**

View File

@ -58,6 +58,10 @@ public class RefreshManager {
} }
} }
public Observable<Map<Installer, List<Book>>> getAvailableModules() {
return getAvailableModules();
}
/** /**
* Get the cached book list * Get the cached book list
* @return The cached book list, or null * @return The cached book list, or null