Browse Source

Check navigation. Fixes https://github.com/austinhuang0131/barinsta/issues/380

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
7005527150
  1. 10
      app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java

10
app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java

@ -83,9 +83,12 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
new FeedStoriesAdapter.OnFeedStoryClickListener() {
@Override
public void onFeedStoryClick(FeedStoryModel model, int position) {
final NavController navController = NavHostFragment.findNavController(FeedFragment.this);
if (isSafeToNavigate(navController)) {
final NavDirections action = FeedFragmentDirections
.actionFeedFragmentToStoryViewerFragment(StoryViewerOptions.forFeedStoryPosition(position));
NavHostFragment.findNavController(FeedFragment.this).navigate(action);
navController.navigate(action);
}
}
@Override
@ -437,4 +440,9 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
binding.feedRecyclerView.smoothScrollToPosition(0);
// binding.storiesContainer.setExpanded(true);
}
private boolean isSafeToNavigate(final NavController navController) {
return navController.getCurrentDestination() != null
&& navController.getCurrentDestination().getId() == R.id.feedFragment;
}
}
Loading…
Cancel
Save