|
|
@@ -1,24 +1,33 @@
|
|
|
package com.adealink.weparty.profile.relation
|
|
|
|
|
|
import android.os.Bundle
|
|
|
+import android.util.TypedValue
|
|
|
import androidx.activity.viewModels
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout
|
|
|
import androidx.core.view.updateLayoutParams
|
|
|
import androidx.fragment.app.Fragment
|
|
|
+import com.adealink.frame.aab.util.getCompatColor
|
|
|
+import com.adealink.frame.aab.util.getCompatString
|
|
|
import com.adealink.frame.mvvm.view.viewBinding
|
|
|
import com.adealink.frame.router.Router
|
|
|
import com.adealink.frame.router.annotation.BindExtra
|
|
|
import com.adealink.frame.router.annotation.RouterUri
|
|
|
import com.adealink.frame.util.statusBarHeight
|
|
|
import com.adealink.weparty.commonui.BaseActivity
|
|
|
+import com.adealink.weparty.commonui.ext.gone
|
|
|
+import com.adealink.weparty.commonui.ext.show
|
|
|
import com.adealink.weparty.commonui.recycleview.adapter.BaseActivityTabFragmentStateAdapter
|
|
|
import com.adealink.weparty.commonui.widget.EmptyFragment
|
|
|
+import com.adealink.weparty.databinding.LayoutHomeTabBinding
|
|
|
import com.adealink.weparty.module.profile.Profile
|
|
|
+import com.adealink.weparty.profile.R
|
|
|
import com.adealink.weparty.profile.databinding.ActivityProfileRelationshipBinding
|
|
|
import com.adealink.weparty.profile.relation.viewmodel.FollowViewModel
|
|
|
import com.adealink.weparty.profile.relation.viewmodel.RELATIONSHIP_TABS
|
|
|
import com.adealink.weparty.profile.relation.viewmodel.RelationShipTab
|
|
|
import com.adealink.weparty.profile.viewmodel.ProfileViewModelFactory
|
|
|
+import com.google.android.material.tabs.TabLayout
|
|
|
+import com.google.android.material.tabs.TabLayoutMediator
|
|
|
|
|
|
@RouterUri(
|
|
|
path = [Profile.RelationShip.PATH],
|
|
|
@@ -33,6 +42,9 @@ class RelationShipActivity : BaseActivity() {
|
|
|
private val viewModel by viewModels<FollowViewModel> { ProfileViewModelFactory() }
|
|
|
private lateinit var pageAdapter: PageAdapter
|
|
|
|
|
|
+ private var followCount: Int? = null
|
|
|
+ private var fansCount: Int? = null
|
|
|
+
|
|
|
override fun onBeforeCreate() {
|
|
|
super.onBeforeCreate()
|
|
|
Router.bind(this)
|
|
|
@@ -46,24 +58,85 @@ class RelationShipActivity : BaseActivity() {
|
|
|
}
|
|
|
|
|
|
pageAdapter = PageAdapter()
|
|
|
+ binding.vpContent.offscreenPageLimit = 1
|
|
|
binding.vpContent.adapter = pageAdapter
|
|
|
- binding.vTab.createMediatorAndAttach(
|
|
|
+ binding.vpContent.isSaveEnabled = false
|
|
|
+ TabLayoutMediator(
|
|
|
+ binding.tlTab,
|
|
|
binding.vpContent,
|
|
|
- pageAdapter,
|
|
|
- tabIndex.coerceIn(0, RELATIONSHIP_TABS.size - 1)
|
|
|
- )
|
|
|
+ true,
|
|
|
+ false
|
|
|
+ ) { tabLayout, position ->
|
|
|
+ tabLayout.setCustomView(com.adealink.weparty.R.layout.layout_home_tab)
|
|
|
+ tabLayout.customView?.let { tabView ->
|
|
|
+ val tabViewBinding = LayoutHomeTabBinding.bind(tabView)
|
|
|
+ onConfigureTab(tabViewBinding, position)
|
|
|
+ updateTabView(
|
|
|
+ tabLayout,
|
|
|
+ 0 == position
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }.attach()
|
|
|
+ binding.tlTab.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
|
|
+
|
|
|
+ override fun onTabSelected(tab: TabLayout.Tab?) {
|
|
|
+ updateTabView(tab, true)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onTabUnselected(tab: TabLayout.Tab?) {
|
|
|
+ updateTabView(tab, false)
|
|
|
+ }
|
|
|
|
|
|
+ override fun onTabReselected(tab: TabLayout.Tab?) {
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ binding.vpContent.currentItem = tabIndex
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun onConfigureTab(binding: LayoutHomeTabBinding, position: Int) {
|
|
|
+ binding.tvTab.text = pageAdapter.getTabName(position)
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun updateTabView(
|
|
|
+ tabView: TabLayout.Tab?,
|
|
|
+ isSelected: Boolean
|
|
|
+ ) {
|
|
|
+ tabView?.customView?.let { tabView ->
|
|
|
+ val tabViewBinding = LayoutHomeTabBinding.bind(tabView)
|
|
|
+ if (isSelected) {
|
|
|
+ tabViewBinding.ivTabBg.show()
|
|
|
+ tabViewBinding.tvTab.setTextColor(getCompatColor(com.adealink.weparty.R.color.color_FF1D2129))
|
|
|
+ tabViewBinding.tvTab.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22f)
|
|
|
+ } else {
|
|
|
+ tabViewBinding.ivTabBg.gone()
|
|
|
+ tabViewBinding.tvTab.setTextColor(getCompatColor(com.adealink.weparty.R.color.color_FF4E5969))
|
|
|
+ tabViewBinding.tvTab.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun observeViewModel() {
|
|
|
super.observeViewModel()
|
|
|
- viewModel
|
|
|
+
|
|
|
}
|
|
|
|
|
|
internal inner class PageAdapter : BaseActivityTabFragmentStateAdapter(this) {
|
|
|
|
|
|
override fun getTabName(pos: Int): String {
|
|
|
- return ""
|
|
|
+ val tab = RELATIONSHIP_TABS.getOrNull(pos) ?: return ""
|
|
|
+ return when (tab.type) {
|
|
|
+ RelationShipTab.FANS -> {
|
|
|
+ getCompatString(
|
|
|
+ R.string.profile_follow_list_title,
|
|
|
+ followCount?.toString() ?: ""
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ RelationShipTab.FOLLOW -> {
|
|
|
+ getCompatString(R.string.profile_fans_list_title, fansCount?.toString() ?: "")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun getItemCount(): Int {
|