fix: 优化首页下拉推送背景渐变效果,修复自定义页面部分组件与下拉推送的滑动冲突问题
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
package com.gh.common.iinterface
|
||||
|
||||
import android.view.View
|
||||
|
||||
interface ISmartRefreshContent {
|
||||
/**
|
||||
* 启用/关闭 页面滑动
|
||||
@ -16,6 +14,4 @@ interface ISmartRefreshContent {
|
||||
* @param isSwipeRefreshEnabled 是否启用
|
||||
*/
|
||||
fun setSwipeRefreshEnabled(isSwipeRefreshEnabled: Boolean)
|
||||
|
||||
fun provideSlideBackgroundView(): View?
|
||||
}
|
||||
@ -46,7 +46,6 @@ import com.gh.gamecenter.wrapper.SearchToolbarTabWrapperFragment
|
||||
import com.gh.gamecenter.wrapper.SearchToolbarTabWrapperViewModel
|
||||
import com.lightgame.download.DataWatcher
|
||||
import com.lightgame.download.DownloadEntity
|
||||
import com.scwang.smartrefresh.layout.constant.RefreshState
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
@ -78,8 +77,6 @@ class CustomPageFragment(private val superiorChain: ISuperiorChain? = null) : La
|
||||
private val isInSearchToolbarTabWrapperPage: Boolean
|
||||
get() = parentFragment is SearchToolbarTabWrapperFragment
|
||||
|
||||
private var refreshState: RefreshState? = null
|
||||
|
||||
private val dataWatcher = object : DataWatcher() {
|
||||
override fun onDataChanged(downloadEntity: DownloadEntity) {
|
||||
adapter.notifyDownload(downloadEntity)
|
||||
@ -204,13 +201,11 @@ class CustomPageFragment(private val superiorChain: ISuperiorChain? = null) : La
|
||||
}
|
||||
}
|
||||
|
||||
searchToolbarTabWrapperViewModel?.refreshState?.observe(viewLifecycleOwner) {
|
||||
refreshState = it
|
||||
searchToolbarTabWrapperViewModel?.backgroundAlpha?.observe(viewLifecycleOwner) {
|
||||
val viewHolder = binding.gameList.findViewHolderForAdapterPosition(0)
|
||||
if (viewHolder is OnCustomPageRefreshStateListener) {
|
||||
viewHolder.onRefreshStateChanged(it)
|
||||
viewHolder.onBackgroundAlphaChanged(it)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
viewModel.loadData()
|
||||
@ -471,9 +466,4 @@ class CustomPageFragment(private val superiorChain: ISuperiorChain? = null) : La
|
||||
binding.gameRefresh.isEnabled = isSwipeRefreshEnabled
|
||||
}
|
||||
}
|
||||
|
||||
override fun provideSlideBackgroundView(): View? {
|
||||
val homeSlideView = if (::layoutManager.isInitialized) layoutManager.findViewByPosition(0) else null
|
||||
return homeSlideView?.findViewById(R.id.placeholderView)
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,6 @@
|
||||
package com.gh.gamecenter.home.custom
|
||||
|
||||
import com.scwang.smartrefresh.layout.constant.RefreshState
|
||||
|
||||
interface OnCustomPageRefreshStateListener {
|
||||
|
||||
fun onRefreshStateChanged(state: RefreshState)
|
||||
fun onBackgroundAlphaChanged(alpha: Float)
|
||||
}
|
||||
@ -5,7 +5,10 @@ import com.gh.common.util.NewLogUtils
|
||||
import com.gh.gamecenter.GameDetailActivity
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.common.exposure.ExposureSource
|
||||
import com.gh.gamecenter.common.utils.*
|
||||
import com.gh.gamecenter.common.utils.LeftPagerSnapHelper
|
||||
import com.gh.gamecenter.common.utils.dip2px
|
||||
import com.gh.gamecenter.common.utils.goneIf
|
||||
import com.gh.gamecenter.common.utils.toJson
|
||||
import com.gh.gamecenter.core.runOnIoThread
|
||||
import com.gh.gamecenter.databinding.HomeAmwayListCustomBinding
|
||||
import com.gh.gamecenter.feature.exposure.ExposureEvent
|
||||
@ -77,6 +80,7 @@ class CustomHomeAmwayListViewHolder(
|
||||
|
||||
if (binding.recyclerView.adapter == null) {
|
||||
binding.recyclerView.adapter = adapter
|
||||
binding.recyclerView.isNestedScrollingEnabled = false
|
||||
val snapHelper = LeftPagerSnapHelper(4F.dip2px())
|
||||
snapHelper.attachToRecyclerView(binding.recyclerView)
|
||||
}
|
||||
|
||||
@ -24,7 +24,6 @@ import com.gh.gamecenter.home.custom.adapter.CustomHomeSlideListAdapter
|
||||
import com.gh.gamecenter.home.custom.createExposureEvent
|
||||
import com.gh.gamecenter.home.custom.model.CustomCommonContentCollectionItem
|
||||
import com.gh.gamecenter.home.custom.model.CustomPageItem
|
||||
import com.scwang.smartrefresh.layout.constant.RefreshState
|
||||
import splitties.views.verticalPadding
|
||||
import kotlin.math.abs
|
||||
|
||||
@ -47,7 +46,7 @@ class CustomHomeSlideListViewHolder(
|
||||
private val isFirst: Boolean
|
||||
get() = bindingAdapterPosition == 0
|
||||
|
||||
private var refreshState: RefreshState? = null
|
||||
private var backgroundAlpha: Float = 1F
|
||||
|
||||
private lateinit var _item: CustomCommonContentCollectionItem
|
||||
|
||||
@ -279,27 +278,20 @@ class CustomHomeSlideListViewHolder(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRefreshStateChanged(state: RefreshState) {
|
||||
refreshState = state
|
||||
val selectedPosition = _item.currentPosition
|
||||
if (selectedPosition != -1) {
|
||||
val item = adapter.getItem(selectedPosition)
|
||||
val color = item.placeholderColor.hexStringToIntColor()
|
||||
updateBackground(color)
|
||||
}
|
||||
override fun onBackgroundAlphaChanged(alpha: Float) {
|
||||
backgroundAlpha = alpha
|
||||
binding.backgroundView.alpha = alpha
|
||||
}
|
||||
|
||||
private fun updateBackground(color: Int) {
|
||||
val isShowPlaceholderColor =
|
||||
refreshState != RefreshState.TwoLevel && refreshState != RefreshState.TwoLevelReleased
|
||||
if (isFirst && isShowPlaceholderColor) {
|
||||
if (isFirst) {
|
||||
val gradientDrawable = DrawableView.getGradientDrawable(
|
||||
color,
|
||||
R.color.ui_surface.toColor(binding.root.context), GradientDrawable.Orientation.TOP_BOTTOM, 0f
|
||||
)
|
||||
itemView.background = gradientDrawable
|
||||
binding.backgroundView.background = gradientDrawable
|
||||
} else {
|
||||
itemView.setBackgroundColor(R.color.ui_surface.toColor(itemView.context))
|
||||
binding.backgroundView.setBackgroundColor(R.color.ui_surface.toColor(itemView.context))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -42,7 +42,6 @@ import com.gh.gamecenter.home.custom.adapter.CustomHomeSlideListAdapter
|
||||
import com.gh.gamecenter.home.custom.createExposureEvent
|
||||
import com.gh.gamecenter.home.custom.model.CustomCommonContentCollectionItem
|
||||
import com.gh.gamecenter.home.custom.model.CustomPageItem
|
||||
import com.scwang.smartrefresh.layout.constant.RefreshState
|
||||
import kotlin.math.abs
|
||||
|
||||
/**
|
||||
@ -65,7 +64,7 @@ class CustomHomeSlideWithCardsViewHolder(
|
||||
private val isFirst: Boolean
|
||||
get() = bindingAdapterPosition == 0
|
||||
|
||||
private var refreshState: RefreshState? = null
|
||||
private var backgroundAlpha: Float = 1F
|
||||
|
||||
private lateinit var _item: CustomCommonContentCollectionItem
|
||||
|
||||
@ -601,27 +600,20 @@ class CustomHomeSlideWithCardsViewHolder(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRefreshStateChanged(state: RefreshState) {
|
||||
refreshState = state
|
||||
val selectedPosition = _item.currentPosition
|
||||
if (selectedPosition != -1) {
|
||||
val item = adapter.getItem(selectedPosition)
|
||||
val color = item.placeholderColor.hexStringToIntColor()
|
||||
updateBackground(color)
|
||||
}
|
||||
override fun onBackgroundAlphaChanged(alpha: Float) {
|
||||
backgroundAlpha = alpha
|
||||
binding.backgroundView.alpha = alpha
|
||||
}
|
||||
|
||||
private fun updateBackground(color: Int) {
|
||||
val isShowPlaceholderColor =
|
||||
refreshState != RefreshState.TwoLevel && refreshState != RefreshState.TwoLevelReleased
|
||||
if (isFirst && isShowPlaceholderColor) {
|
||||
if (isFirst) {
|
||||
val gradientDrawable = DrawableView.getGradientDrawable(
|
||||
color,
|
||||
R.color.ui_surface.toColor(binding.root.context), GradientDrawable.Orientation.TOP_BOTTOM, 0f
|
||||
)
|
||||
binding.placeholderView.background = gradientDrawable
|
||||
binding.backgroundView.background = gradientDrawable
|
||||
} else {
|
||||
binding.placeholderView.setBackgroundColor(R.color.ui_surface.toColor(itemView.context))
|
||||
binding.backgroundView.setBackgroundColor(R.color.ui_surface.toColor(itemView.context))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -39,6 +39,7 @@ class CustomNavigationViewHolder(
|
||||
binding.rvNavigation.layoutManager = layoutManager
|
||||
binding.rvNavigation.addItemDecoration(GridSpacingItemDecoration(4, 8f.dip2px(), false, 16f.dip2px()))
|
||||
binding.rvNavigation.adapter = adapter
|
||||
binding.rvNavigation.isNestedScrollingEnabled = false
|
||||
}
|
||||
|
||||
val navigationList = item.data.navigations
|
||||
|
||||
@ -756,8 +756,6 @@ class SearchToolbarTabWrapperFragment : BaseTabWrapperFragment(), ISmartRefresh,
|
||||
}
|
||||
}
|
||||
|
||||
mViewModel.updateRefreshState(newState)
|
||||
|
||||
if (mClipChildren != clipChildren) {
|
||||
mClipChildren = clipChildren
|
||||
wrapperLl.clipChildren = mClipChildren
|
||||
@ -833,7 +831,7 @@ class SearchToolbarTabWrapperFragment : BaseTabWrapperFragment(), ISmartRefresh,
|
||||
1 - (offset - mShowTwoLevelStartOffset) / (mTwoLevelOpenOffset - mShowTwoLevelStartOffset).toFloat()
|
||||
tabBgView.alpha = oneLevelAlpha
|
||||
contentBgView.alpha = oneLevelAlpha
|
||||
getValidSmartRefreshContent()?.provideSlideBackgroundView()?.alpha = oneLevelAlpha
|
||||
mViewModel.updateBackgroundAlpha(oneLevelAlpha)
|
||||
|
||||
if (mViewModel.isTabCustomPage(mLastSelectedPosition)) {
|
||||
refreshStatusBarStyle()
|
||||
@ -872,7 +870,7 @@ class SearchToolbarTabWrapperFragment : BaseTabWrapperFragment(), ISmartRefresh,
|
||||
} else {
|
||||
tabBgView.alpha = 1F
|
||||
contentBgView.alpha = 1F
|
||||
getValidSmartRefreshContent()?.provideSlideBackgroundView()?.alpha = 1F
|
||||
mViewModel.updateBackgroundAlpha(1F)
|
||||
|
||||
if (mViewModel.isTabCustomPage(mLastSelectedPosition)) {
|
||||
refreshStatusBarStyle()
|
||||
|
||||
@ -6,8 +6,9 @@ import com.gh.gamecenter.common.utils.safelyGetInRelease
|
||||
import com.gh.gamecenter.entity.MultiTabNav
|
||||
import com.gh.gamecenter.livedata.Event
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.scwang.smartrefresh.layout.constant.RefreshState
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.coroutines.flow.transformWhile
|
||||
|
||||
class SearchToolbarTabWrapperViewModel(
|
||||
application: Application,
|
||||
@ -18,10 +19,10 @@ class SearchToolbarTabWrapperViewModel(
|
||||
var noTabStyle = MultiTabNav.LinkMultiTabNav.TabStyle()
|
||||
var appBarOffset = 0
|
||||
|
||||
private val _refreshState = MutableLiveData<RefreshState>()
|
||||
val refreshState: LiveData<RefreshState> = _refreshState
|
||||
fun updateRefreshState(state: RefreshState) {
|
||||
_refreshState.value = state
|
||||
private val _backgroundAlpha = MutableLiveData<Float>()
|
||||
val backgroundAlpha: LiveData<Float> = _backgroundAlpha
|
||||
fun updateBackgroundAlpha(alpha: Float) {
|
||||
_backgroundAlpha.value = alpha
|
||||
}
|
||||
|
||||
val tabSelectLiveData =
|
||||
|
||||
@ -98,10 +98,6 @@ class TabWrapperFragment: BaseTabWrapperFragment(), ISmartRefresh, ISmartRefresh
|
||||
getCurrentTabEntity()?.showPullDownPush = !isSwipeRefreshEnabled
|
||||
}
|
||||
|
||||
override fun provideSlideBackgroundView(): View? {
|
||||
return getValidSmartRefreshContent()?.provideSlideBackgroundView()
|
||||
}
|
||||
|
||||
override fun setSmartRefreshEnabled(isEnable: Boolean) {
|
||||
(parentFragment as? ISmartRefresh)?.setSmartRefreshEnabled(isEnable)
|
||||
}
|
||||
|
||||
@ -3,8 +3,17 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
android:background="@color/ui_surface">
|
||||
android:descendantFocusability="blocksDescendants">
|
||||
|
||||
<View
|
||||
android:id="@+id/backgroundView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:background="@color/ui_surface"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipChildren="false"
|
||||
android:descendantFocusability="blocksDescendants">
|
||||
|
||||
<View
|
||||
android:id="@+id/placeholderView"
|
||||
android:id="@+id/backgroundView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:background="@color/ui_surface"
|
||||
|
||||
Reference in New Issue
Block a user