mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-21 15:38:35 -05:00
Slight refactor
Tried to refactor all the way to Kotlin, but ran into some casting issues ultimately after trying to work around Dagger.
This commit is contained in:
parent
bfde7d5839
commit
ff9f2ac7b3
@ -22,13 +22,14 @@ import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import rx.functions.Func1;
|
||||
import rx.functions.Func2;
|
||||
import rx.functions.Action1;
|
||||
|
||||
/**
|
||||
* ExpandableListView for managing books of the Bible.
|
||||
* We extend from @link{BaseNavigationDrawerFragment} so we can inherit some of the lifecycle
|
||||
* pieces, but the actual view inflation is done by us.
|
||||
* I tried to refactor this into Kotlin, but I need to inject the vUtil and mainBook,
|
||||
* and trying to getActivity() as BibleViewer yielded TypeCastException
|
||||
* TODO: Extend BaseExpNavigationDrawerFragment?
|
||||
*/
|
||||
public class ExpListNavDrawerFragment extends NavDrawerFragment {
|
||||
@ -68,41 +69,21 @@ public class ExpListNavDrawerFragment extends NavDrawerFragment {
|
||||
|
||||
|
||||
// I really don't like how we build the chapters, but I'm not adding Guava just for Range.
|
||||
// RXJava does get ridiculous with the angle brackets, you have me there. But Intellij
|
||||
// folds nicely.
|
||||
Map<String, List<Integer>> chapterMap;
|
||||
// This isn't a totally functional style map-reduce, but the reduce step is
|
||||
// unnecessarily verbose. Like this comment.
|
||||
final Map<String, List<Integer>> chapterMap = new HashMap<String, List<Integer>>();
|
||||
if (mainBook != null) {
|
||||
chapterMap = vUtil.getBooks(mainBook).map(new Func1<BibleBook, Map<String, List<Integer>>>() {
|
||||
vUtil.getBooks(mainBook).forEach(new Action1<BibleBook>() {
|
||||
@Override
|
||||
public Map<String, List<Integer>> call(BibleBook bibleBook) {
|
||||
// These lines are important
|
||||
public void call(BibleBook bibleBook) {
|
||||
int bookCount = vUtil.getChapterCount(mainBook, bibleBook);
|
||||
List<Integer> chapterList = new ArrayList<Integer>(bookCount);
|
||||
for (int i = 0; i < bookCount; i++) {
|
||||
chapterList.add(i + 1); // Index to chapter number
|
||||
}
|
||||
// </important>
|
||||
Map<String, List<Integer>> bookListMap =
|
||||
new HashMap<String, List<Integer>>(1);
|
||||
bookListMap.put(vUtil.getBookName(mainBook, bibleBook), chapterList);
|
||||
return bookListMap;
|
||||
chapterMap.put(vUtil.getBookName(mainBook, bibleBook), chapterList);
|
||||
}
|
||||
})
|
||||
.reduce(new Func2<Map<String, List<Integer>>,
|
||||
Map<String, List<Integer>>,
|
||||
Map<String, List<Integer>>>() {
|
||||
@Override
|
||||
public Map<String, List<Integer>>
|
||||
call(Map<String, List<Integer>> acc,
|
||||
Map<String, List<Integer>> value) {
|
||||
// These lines are important
|
||||
acc.putAll(value);
|
||||
return acc;
|
||||
// </important>
|
||||
}
|
||||
})
|
||||
.toBlocking()
|
||||
.first();
|
||||
});
|
||||
|
||||
ExpListNavAdapter<String, Integer> adapter =
|
||||
new ExpListNavAdapter<String, Integer>(bibleBooks, chapterMap);
|
||||
|
Loading…
Reference in New Issue
Block a user