Skip to content

Commit

Permalink
#103 [FIX] : fix offset listener binding error
Browse files Browse the repository at this point in the history
  • Loading branch information
sohyun127 committed Oct 29, 2024
1 parent aebe93e commit 43a9707
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.ViewGroup
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.google.android.material.appbar.AppBarLayout
import com.teamwable.model.Profile
import com.teamwable.profile.R
import com.teamwable.profile.databinding.FragmentProfileBinding
Expand All @@ -23,6 +24,8 @@ abstract class BindingProfileFragment : Fragment() {
protected val binding: FragmentProfileBinding
get() = requireNotNull(_binding) { "ViewBinding is not initialized" }

private lateinit var offsetChangedListener: AppBarLayout.OnOffsetChangedListener

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -34,6 +37,7 @@ abstract class BindingProfileFragment : Fragment() {

override fun onDestroyView() {
super.onDestroyView()
binding.appbarProfileInfo.removeOnOffsetChangedListener(offsetChangedListener)
_binding = null
}

Expand All @@ -43,9 +47,17 @@ abstract class BindingProfileFragment : Fragment() {
tvProfileNickname.text = data.nickName
tvProfileInfo.text = getString(R.string.label_profile_info, data.teamTag.ifBlank { TeamTag.LCK.name }, data.lckYears)
tvProfileGhostPercentage.text = getString(R.string.label_ghost_percentage, data.ghost)
setSwipeLayout()
setGhostProgress(data.ghost)
}

private fun setSwipeLayout() {
offsetChangedListener = AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
binding.layoutProfileSwipe.isEnabled = verticalOffset == 0
}
binding.appbarProfileInfo.addOnOffsetChangedListener(offsetChangedListener)
}

private fun setGhostProgress(percentage: Int) {
animateProgress(abs(100 + percentage))
if (percentage < -50) setGhostProgressColor(com.teamwable.ui.R.color.sky_50) else setGhostProgressColor(com.teamwable.ui.R.color.purple_50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.fragment.app.setFragmentResultListener
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.navigation.fragment.findNavController
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.teamwable.model.Profile
import com.teamwable.model.profile.MemberInfoEditModel
Expand Down Expand Up @@ -81,12 +80,6 @@ class ProfileAuthFragment : BindingProfileFragment() {
}

private fun setSwipeLayout() {
binding.appbarProfileInfo.addOnOffsetChangedListener(
AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
binding.layoutProfileSwipe.isEnabled = verticalOffset == 0
},
)

binding.layoutProfileSwipe.setOnRefreshListener {
binding.layoutProfileSwipe.isRefreshing = false
viewModel.fetchAuthId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.view.View
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.navigation.fragment.findNavController
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.teamwable.model.Profile
import com.teamwable.profile.profiletabs.ProfilePagerStateAdapter
Expand Down Expand Up @@ -63,12 +62,6 @@ class ProfileMemberFragment : BindingProfileFragment() {
}

private fun setSwipeLayout() {
binding.appbarProfileInfo.addOnOffsetChangedListener(
AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
binding.layoutProfileSwipe.isEnabled = verticalOffset == 0
},
)

binding.layoutProfileSwipe.setOnRefreshListener {
binding.layoutProfileSwipe.isRefreshing = false
viewModel.fetchProfileInfo(userId)
Expand Down

0 comments on commit 43a9707

Please sign in to comment.