mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-11-23 15:47:20 +00:00
Fix tab sync: use title-hash IDs, live chat as 2nd tab, auto-select on live
This commit is contained in:
1 parent
55eb1f7dc7
commit
1bd0fd3e06
2 files changed
+22
-5
No files matched your search
@@ -24,6 +24,14 @@ public class TabAdapter extends FragmentPagerAdapter {
|
||||
this.fragmentManager = fm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(final int position) {
|
||||
// Use the fragment title hash as ID instead of position.
|
||||
// This allows inserting fragments in the middle without breaking
|
||||
// FragmentPagerAdapter's internal fragment cache.
|
||||
return mFragmentTitleList.get(position).hashCode();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(final int position) {
|
||||
|
||||
@@ -929,17 +929,26 @@ class VideoDetailFragment :
|
||||
return
|
||||
}
|
||||
|
||||
// Append live chat tab at the end to avoid FragmentPagerAdapter
|
||||
// position synchronization issues when inserting in the middle
|
||||
val commentsPosition = pageAdapter.getItemPositionByTitle(COMMENTS_TAB_TAG)
|
||||
val insertPosition = if (commentsPosition >= 0) commentsPosition + 1 else pageAdapter.count
|
||||
|
||||
pageAdapter.addFragment(
|
||||
LiveChatFragment.getInstance(serviceId, url, continuation),
|
||||
LIVE_CHAT_TAB_TAG
|
||||
LIVE_CHAT_TAB_TAG,
|
||||
insertPosition
|
||||
)
|
||||
tabIcons.add(R.drawable.ic_live_tv)
|
||||
tabContentDescriptions.add(R.string.live_chat_tab_description)
|
||||
tabIcons.add(insertPosition, R.drawable.ic_live_tv)
|
||||
tabContentDescriptions.add(insertPosition, R.string.live_chat_tab_description)
|
||||
pageAdapter.notifyDataSetUpdate()
|
||||
updateTabIconsAndContentDescriptions()
|
||||
updateTabLayoutVisibility()
|
||||
|
||||
// Select live chat tab by default for live streams
|
||||
if (streamInfo.streamType == StreamType.LIVE_STREAM ||
|
||||
streamInfo.streamType == StreamType.AUDIO_LIVE_STREAM
|
||||
) {
|
||||
binding.viewPager.setCurrentItem(insertPosition, false)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateTabLayoutVisibility() {
|
||||
|
||||
Reference in new issue
Block a user