From ff9f2ac7b3e7883d3077befd8b4fb906ba362088 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sun, 12 Oct 2014 22:34:17 -0400 Subject: [PATCH] Slight refactor Tried to refactor all the way to Kotlin, but ran into some casting issues ultimately after trying to work around Dagger. --- .../viewer/ExpListNavDrawerFragment.java | 39 +++++-------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/ExpListNavDrawerFragment.java b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/ExpListNavDrawerFragment.java index 9bc3419..8b8af8c 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/viewer/ExpListNavDrawerFragment.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/viewer/ExpListNavDrawerFragment.java @@ -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> chapterMap; + // This isn't a totally functional style map-reduce, but the reduce step is + // unnecessarily verbose. Like this comment. + final Map> chapterMap = new HashMap>(); if (mainBook != null) { - chapterMap = vUtil.getBooks(mainBook).map(new Func1>>() { + vUtil.getBooks(mainBook).forEach(new Action1() { @Override - public Map> call(BibleBook bibleBook) { - // These lines are important + public void call(BibleBook bibleBook) { int bookCount = vUtil.getChapterCount(mainBook, bibleBook); List chapterList = new ArrayList(bookCount); for (int i = 0; i < bookCount; i++) { chapterList.add(i + 1); // Index to chapter number } - // - Map> bookListMap = - new HashMap>(1); - bookListMap.put(vUtil.getBookName(mainBook, bibleBook), chapterList); - return bookListMap; + chapterMap.put(vUtil.getBookName(mainBook, bibleBook), chapterList); } - }) - .reduce(new Func2>, - Map>, - Map>>() { - @Override - public Map> - call(Map> acc, - Map> value) { - // These lines are important - acc.putAll(value); - return acc; - // - } - }) - .toBlocking() - .first(); + }); ExpListNavAdapter adapter = new ExpListNavAdapter(bibleBooks, chapterMap);