mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-22 07:58:20 -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.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import rx.functions.Func1;
|
import rx.functions.Action1;
|
||||||
import rx.functions.Func2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ExpandableListView for managing books of the Bible.
|
* ExpandableListView for managing books of the Bible.
|
||||||
* We extend from @link{BaseNavigationDrawerFragment} so we can inherit some of the lifecycle
|
* We extend from @link{BaseNavigationDrawerFragment} so we can inherit some of the lifecycle
|
||||||
* pieces, but the actual view inflation is done by us.
|
* 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?
|
* TODO: Extend BaseExpNavigationDrawerFragment?
|
||||||
*/
|
*/
|
||||||
public class ExpListNavDrawerFragment extends NavDrawerFragment {
|
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.
|
// 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
|
// This isn't a totally functional style map-reduce, but the reduce step is
|
||||||
// folds nicely.
|
// unnecessarily verbose. Like this comment.
|
||||||
Map<String, List<Integer>> chapterMap;
|
final Map<String, List<Integer>> chapterMap = new HashMap<String, List<Integer>>();
|
||||||
if (mainBook != null) {
|
if (mainBook != null) {
|
||||||
chapterMap = vUtil.getBooks(mainBook).map(new Func1<BibleBook, Map<String, List<Integer>>>() {
|
vUtil.getBooks(mainBook).forEach(new Action1<BibleBook>() {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<Integer>> call(BibleBook bibleBook) {
|
public void call(BibleBook bibleBook) {
|
||||||
// These lines are important
|
|
||||||
int bookCount = vUtil.getChapterCount(mainBook, bibleBook);
|
int bookCount = vUtil.getChapterCount(mainBook, bibleBook);
|
||||||
List<Integer> chapterList = new ArrayList<Integer>(bookCount);
|
List<Integer> chapterList = new ArrayList<Integer>(bookCount);
|
||||||
for (int i = 0; i < bookCount; i++) {
|
for (int i = 0; i < bookCount; i++) {
|
||||||
chapterList.add(i + 1); // Index to chapter number
|
chapterList.add(i + 1); // Index to chapter number
|
||||||
}
|
}
|
||||||
// </important>
|
chapterMap.put(vUtil.getBookName(mainBook, bibleBook), chapterList);
|
||||||
Map<String, List<Integer>> bookListMap =
|
|
||||||
new HashMap<String, List<Integer>>(1);
|
|
||||||
bookListMap.put(vUtil.getBookName(mainBook, bibleBook), chapterList);
|
|
||||||
return bookListMap;
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
.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 =
|
ExpListNavAdapter<String, Integer> adapter =
|
||||||
new ExpListNavAdapter<String, Integer>(bibleBooks, chapterMap);
|
new ExpListNavAdapter<String, Integer>(bibleBooks, chapterMap);
|
||||||
|
Loading…
Reference in New Issue
Block a user