Skip to content

Commit

Permalink
fix: wrong articled selected
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Jun 25, 2024
1 parent 8c5903d commit a7a46d4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/itkach/aard2/ArticleCollectionActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,8 @@ public void run() {
}

}});
viewPager.setCurrentItem(position);

// PagerTitleStrip titleStrip = (PagerTitleStrip)findViewById(R.id.pager_title_strip);
// titleStrip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
updateTitle(position);

articleCollectionPagerAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
Expand All @@ -212,6 +209,19 @@ public void onChanged() {
}
}
});
// setCurrentItem is bugged and wont siwtch correctly
// so we use another solution found here https://stackoverflow.com/questions/70736007/viewpager2-setcurrentitem-bug-workaround
tabs.post(()->{
tabs.selectTab(tabs.getTabAt(position));
viewPager.post(()->{
viewPager.setCurrentItem(position);
//I noticed on older devices like API 19
//the viewPager wouldn't complete transformations
//so we call this.
viewPager.requestTransform();
});
});
updateTitle(position);
}
};

Expand Down

0 comments on commit a7a46d4

Please sign in to comment.