Skip to content

Commit

Permalink
[bug] NPE in DiscoveryFragment (#241)
Browse files Browse the repository at this point in the history
* attempting to fix bug where the discoveryfragment.viewmodel is null
* just checking if viewmodel is null vs ondetached because that only gets called when .detach is called
  • Loading branch information
eoji committed Apr 23, 2018
1 parent 7ea0861 commit 77d2d90
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public CharSequence getPageTitle(final int position) {
public void takeCategoriesForPosition(final @NonNull List<Category> categories, final int position) {
Observable.from(this.fragments)
.filter(DiscoveryFragment::isInstantiated)
.filter(DiscoveryFragment::isAttached)
.filter(frag -> {
final int fragmentPosition = frag.getArguments().getInt(ArgumentsKey.DISCOVERY_SORT_POSITION);
return fragmentPosition == position;
Expand All @@ -81,6 +82,7 @@ public void takeCategoriesForPosition(final @NonNull List<Category> categories,
public void takeParams(final @NonNull DiscoveryParams params) {
Observable.from(this.fragments)
.filter(DiscoveryFragment::isInstantiated)
.filter(DiscoveryFragment::isAttached)
.filter(frag -> {
final int fragmentPosition = frag.getArguments().getInt(ArgumentsKey.DISCOVERY_SORT_POSITION);
return DiscoveryUtils.positionFromSort(params.sort()) == fragmentPosition;
Expand All @@ -94,6 +96,7 @@ public void takeParams(final @NonNull DiscoveryParams params) {
public void clearPages(final @NonNull List<Integer> pages) {
Observable.from(this.fragments)
.filter(DiscoveryFragment::isInstantiated)
.filter(DiscoveryFragment::isAttached)
.filter(frag -> {
final int fragmentPosition = frag.getArguments().getInt(ArgumentsKey.DISCOVERY_SORT_POSITION);
return pages.contains(fragmentPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public void onDetach() {
}
}

public boolean isAttached() {
return this.viewModel != null;
}

public boolean isInstantiated() {
return this.recyclerView != null;
}
Expand Down

0 comments on commit 77d2d90

Please sign in to comment.