| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package com.adealink.weparty.profile
- import android.os.Bundle
- 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.getCompatDimension
- 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.recycleview.adapter.BaseActivityTabFragmentStateAdapter
- import com.adealink.weparty.commonui.widget.EmptyFragment
- import com.adealink.weparty.module.profile.Profile
- import com.adealink.weparty.module.profile.data.TAB_INDEX_PERSONAL
- import com.adealink.weparty.profile.comp.ProfileBottomComp
- import com.adealink.weparty.profile.comp.ProfileHeaderComp
- import com.adealink.weparty.profile.comp.ProfileToolBarViewComp
- import com.adealink.weparty.profile.databinding.ActivityUserProfileBinding
- import com.adealink.weparty.profile.viewmodel.ProfileViewModel
- import com.adealink.weparty.profile.viewmodel.ProfileViewModelFactory
- @RouterUri(
- path = [Profile.UserProfile.PATH],
- desc = "用户个人页"
- )
- class UserProfileActivity : BaseActivity() {
- @BindExtra(name = Profile.Common.EXTRA_UID)
- var userUid: String = ""
- private val binding by viewBinding(ActivityUserProfileBinding::inflate)
- private val profileViewModel by viewModels<ProfileViewModel> { ProfileViewModelFactory() }
- private lateinit var profilePageAdapter: ProfilePageAdapter
- override fun onBeforeCreate() {
- super.onBeforeCreate()
- Router.bind(this)
- }
- override fun initViews() {
- super.initViews()
- setContentView(binding.root)
- binding.profileHeaderLayout.ivBg.updateLayoutParams<ConstraintLayout.LayoutParams> {
- height =
- getCompatDimension(R.dimen.profile_header_height).toInt() + this@UserProfileActivity.statusBarHeight()
- }
- profilePageAdapter = ProfilePageAdapter()
- binding.profileVp.adapter = profilePageAdapter
- binding.tabLayout.createMediatorAndAttach(
- binding.profileVp,
- profilePageAdapter,
- TAB_INDEX_PERSONAL
- )
- }
- override fun initComponents() {
- super.initComponents()
- ProfileToolBarViewComp(this, userUid, binding).attach()
- ProfileHeaderComp(this, userUid, binding.profileHeaderLayout).attach()
- ProfileBottomComp(this, userUid, binding.vBottom).attach()
- }
- override fun onResume() {
- super.onResume()
- profileViewModel.pullUserInfoBy(userUid, false)
- }
- internal inner class ProfilePageAdapter : BaseActivityTabFragmentStateAdapter(this) {
- override fun getTabName(pos: Int): String {
- return PROFILE_TABS.getOrNull(pos)?.name?.invoke() ?: ""
- }
- override fun getItemCount(): Int {
- return PROFILE_TABS.size
- }
- override fun createFragment(position: Int): Fragment {
- val profileTab = PROFILE_TABS.getOrNull(position) ?: return EmptyFragment()
- return when (profileTab.type) {
- ProfileTab.PROFILE -> {
- profileTab.fragmentBuilder().apply {
- arguments = Bundle().apply {
- putString(Profile.Common.EXTRA_UID, userUid)
- }
- }
- }
- ProfileTab.PHOTO_WALL -> {
- profileTab.fragmentBuilder().apply {
- arguments = Bundle().apply {
- putString(Profile.Common.EXTRA_UID, userUid)
- }
- }
- }
- }
- }
- }
- }
|