Fixed displaying wrong menu

This commit is contained in:
ByteHamster 2019-11-15 16:46:26 +01:00
parent 4336c10fb1
commit adcce2b94f
1 changed files with 5 additions and 4 deletions

View File

@ -79,6 +79,8 @@ public class ItemPagerFragment extends Fragment {
ViewPager pager = layout.findViewById(R.id.pager); ViewPager pager = layout.findViewById(R.id.pager);
pager.setAdapter(new ItemPagerAdapter()); pager.setAdapter(new ItemPagerAdapter());
pager.setCurrentItem(feedItemPos);
loadItem(feedItems[feedItemPos]);
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override @Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
@ -87,7 +89,7 @@ public class ItemPagerFragment extends Fragment {
@Override @Override
public void onPageSelected(int position) { public void onPageSelected(int position) {
loadItem(position); loadItem(feedItems[position]);
} }
@Override @Override
@ -95,7 +97,6 @@ public class ItemPagerFragment extends Fragment {
} }
}); });
pager.setCurrentItem(feedItemPos);
return layout; return layout;
} }
@ -108,12 +109,12 @@ public class ItemPagerFragment extends Fragment {
} }
} }
private void loadItem(int position) { private void loadItem(long itemId) {
if (disposable != null) { if (disposable != null) {
disposable.dispose(); disposable.dispose();
} }
disposable = Observable.fromCallable(() -> DBReader.getFeedItem(position)) disposable = Observable.fromCallable(() -> DBReader.getFeedItem(itemId))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> { .subscribe(result -> {