Scroll profile tab views to top when tab is reselected

This commit is contained in:
Grishka 2023-09-20 14:47:25 +03:00
parent 90f84d628a
commit e3fb2cd03c

View file

@ -245,15 +245,23 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
tabbar.setTabTextColors(UiUtils.getThemeColor(getActivity(), R.attr.colorM3OnSurfaceVariant), UiUtils.getThemeColor(getActivity(), R.attr.colorM3Primary)); tabbar.setTabTextColors(UiUtils.getThemeColor(getActivity(), R.attr.colorM3OnSurfaceVariant), UiUtils.getThemeColor(getActivity(), R.attr.colorM3Primary));
tabbar.setTabTextSize(V.dp(14)); tabbar.setTabTextSize(V.dp(14));
tabLayoutMediator=new TabLayoutMediator(tabbar, pager, new TabLayoutMediator.TabConfigurationStrategy(){ tabLayoutMediator=new TabLayoutMediator(tabbar, pager, (tab, position)->tab.setText(switch(position){
case 0 -> R.string.profile_featured;
case 1 -> R.string.profile_timeline;
case 2 -> R.string.profile_about;
default -> throw new IllegalStateException();
}));
tabbar.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){
@Override @Override
public void onConfigureTab(@NonNull TabLayout.Tab tab, int position){ public void onTabSelected(TabLayout.Tab tab){}
tab.setText(switch(position){
case 0 -> R.string.profile_featured; @Override
case 1 -> R.string.profile_timeline; public void onTabUnselected(TabLayout.Tab tab){}
case 2 -> R.string.profile_about;
default -> throw new IllegalStateException(); @Override
}); public void onTabReselected(TabLayout.Tab tab){
if(getFragmentForPage(tab.getPosition()) instanceof ScrollableToTop stt)
stt.scrollToTop();
} }
}); });