removed additional hardcoding

This commit is contained in:
Kai DeLorenzo 2024-06-05 18:57:43 -05:00
commit 4cf3aabe89
No known key found for this signature in database
3 changed files with 16 additions and 5 deletions

View file

@ -95,8 +95,8 @@ class ChannelFragment : MainFragment() {
_view = null _view = null
} }
fun selectTab(selectedTabIndex: Int) { fun selectTab(tab: ChannelTab) {
_view?.selectTab(selectedTabIndex) _view?.selectTab(tab)
} }
@SuppressLint("ViewConstructor") @SuppressLint("ViewConstructor")
@ -268,6 +268,10 @@ class ChannelFragment : MainFragment() {
setLoading(true) setLoading(true)
} }
fun selectTab(tab: ChannelTab) {
(_viewPager.adapter as ChannelViewPagerAdapter).getTabPosition(tab)
}
fun cleanup() { fun cleanup() {
_taskLoadPolycentricProfile.cancel() _taskLoadPolycentricProfile.cancel()
_taskGetChannel.cancel() _taskGetChannel.cancel()
@ -560,18 +564,20 @@ class ChannelFragment : MainFragment() {
(fragment as IChannelTabFragment).setPolycentricProfile(profile) (fragment as IChannelTabFragment).setPolycentricProfile(profile)
} }
val insertPosition = 2
//TODO only add channels and support if its setup on the polycentric profile //TODO only add channels and support if its setup on the polycentric profile
if (profile != null && !(_viewPager.adapter as ChannelViewPagerAdapter).containsItem( if (profile != null && !(_viewPager.adapter as ChannelViewPagerAdapter).containsItem(
ChannelTab.SUPPORT.ordinal.toLong() ChannelTab.SUPPORT.ordinal.toLong()
) )
) { ) {
(_viewPager.adapter as ChannelViewPagerAdapter).insert(2, ChannelTab.SUPPORT) (_viewPager.adapter as ChannelViewPagerAdapter).insert(insertPosition, ChannelTab.SUPPORT)
} }
if (profile != null && !(_viewPager.adapter as ChannelViewPagerAdapter).containsItem( if (profile != null && !(_viewPager.adapter as ChannelViewPagerAdapter).containsItem(
ChannelTab.CHANNELS.ordinal.toLong() ChannelTab.CHANNELS.ordinal.toLong()
) )
) { ) {
(_viewPager.adapter as ChannelViewPagerAdapter).insert(2, ChannelTab.CHANNELS) (_viewPager.adapter as ChannelViewPagerAdapter).insert(insertPosition, ChannelTab.CHANNELS)
} }
(_viewPager.adapter as ChannelViewPagerAdapter).profile = profile (_viewPager.adapter as ChannelViewPagerAdapter).profile = profile
_viewPager.adapter!!.notifyDataSetChanged() _viewPager.adapter!!.notifyDataSetChanged()

View file

@ -41,6 +41,7 @@ import com.futo.platformplayer.states.StatePlatform
import com.futo.platformplayer.states.StatePolycentric import com.futo.platformplayer.states.StatePolycentric
import com.futo.platformplayer.toHumanNowDiffString import com.futo.platformplayer.toHumanNowDiffString
import com.futo.platformplayer.toHumanNumber import com.futo.platformplayer.toHumanNumber
import com.futo.platformplayer.views.adapters.ChannelTab
import com.futo.platformplayer.views.adapters.feedtypes.PreviewPostView import com.futo.platformplayer.views.adapters.feedtypes.PreviewPostView
import com.futo.platformplayer.views.comments.AddCommentView import com.futo.platformplayer.views.comments.AddCommentView
import com.futo.platformplayer.views.others.CreatorThumbnail import com.futo.platformplayer.views.others.CreatorThumbnail
@ -264,7 +265,7 @@ class PostDetailFragment : MainFragment {
_buttonSupport.setOnClickListener { _buttonSupport.setOnClickListener {
val author = _post?.author ?: _postOverview?.author; val author = _post?.author ?: _postOverview?.author;
author?.let { _fragment.navigate<ChannelFragment>(it).selectTab(2); }; author?.let { _fragment.navigate<ChannelFragment>(it).selectTab(ChannelTab.SUPPORT); };
}; };
_buttonStore.setOnClickListener { _buttonStore.setOnClickListener {

View file

@ -55,6 +55,10 @@ class ChannelViewPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifec
return _supportedFragments.size return _supportedFragments.size
} }
fun getTabPosition(tab: ChannelTab): Int {
return _tabs.indexOf(tab)
}
fun getTabNames(tab: TabLayout.Tab, position: Int) { fun getTabNames(tab: TabLayout.Tab, position: Int) {
tab.text = _tabs[position].name tab.text = _tabs[position].name
} }