improved user profile toolbar elevation
This commit is contained in:
parent
dde08de7cd
commit
0d05f50a7c
|
@ -27,6 +27,7 @@ import android.support.v7.widget.Toolbar
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import kotlinx.android.synthetic.main.fragment_user.view.*
|
import kotlinx.android.synthetic.main.fragment_user.view.*
|
||||||
|
import kotlinx.android.synthetic.main.header_user.view.*
|
||||||
import org.mariotaku.twidere.R
|
import org.mariotaku.twidere.R
|
||||||
import org.mariotaku.twidere.graphic.drawable.userprofile.ActionBarDrawable
|
import org.mariotaku.twidere.graphic.drawable.userprofile.ActionBarDrawable
|
||||||
import org.mariotaku.twidere.util.ThemeUtils
|
import org.mariotaku.twidere.util.ThemeUtils
|
||||||
|
@ -44,15 +45,24 @@ internal class ToolbarBehavior(context: Context?, attrs: AttributeSet? = null) :
|
||||||
override fun onDependentViewChanged(parent: CoordinatorLayout, child: Toolbar, dependency: View): Boolean {
|
override fun onDependentViewChanged(parent: CoordinatorLayout, child: Toolbar, dependency: View): Boolean {
|
||||||
val actionBarBackground = child.background as? ActionBarDrawable ?: return false
|
val actionBarBackground = child.background as? ActionBarDrawable ?: return false
|
||||||
val bannerContainer = parent.profileBannerContainer
|
val bannerContainer = parent.profileBannerContainer
|
||||||
val bannerBottom = dependency.top + bannerContainer.height
|
val detailsBackground = parent.profileHeaderBackground
|
||||||
|
val bannerBottom = dependency.top + bannerContainer.bottom
|
||||||
|
val detailsBottom = dependency.top + detailsBackground.bottom
|
||||||
val currentOffset = bannerBottom - child.bottom
|
val currentOffset = bannerBottom - child.bottom
|
||||||
val maxOffset = (bannerContainer.height - child.bottom).toFloat()
|
val maxOffset = (bannerContainer.bottom - child.bottom).toFloat()
|
||||||
val factor = (1 - currentOffset / maxOffset).coerceIn(0f, 1f)
|
val colorFactor = (1 - currentOffset / maxOffset).coerceIn(0f, 1f)
|
||||||
actionBarBackground.factor = factor
|
actionBarBackground.factor = colorFactor
|
||||||
actionBarBackground.outlineAlphaFactor = factor
|
|
||||||
|
val outlineFactor = if (colorFactor < 1) {
|
||||||
|
colorFactor
|
||||||
|
} else {
|
||||||
|
((detailsBottom - child.bottom) / detailsBackground.height.toFloat()).coerceIn(0f, 1f)
|
||||||
|
}
|
||||||
|
|
||||||
|
actionBarBackground.outlineAlphaFactor = outlineFactor
|
||||||
|
|
||||||
val colorPrimary = actionBarBackground.color
|
val colorPrimary = actionBarBackground.color
|
||||||
val currentActionBarColor = ArgbEvaluator.getInstance().evaluate(factor, actionBarShadowColor,
|
val currentActionBarColor = ArgbEvaluator.getInstance().evaluate(colorFactor, actionBarShadowColor,
|
||||||
colorPrimary) as Int
|
colorPrimary) as Int
|
||||||
val actionItemIsDark = if (ThemeUtils.isLightColor(currentActionBarColor)) 1 else -1
|
val actionItemIsDark = if (ThemeUtils.isLightColor(currentActionBarColor)) 1 else -1
|
||||||
if (this.actionItemIsDark != actionItemIsDark) {
|
if (this.actionItemIsDark != actionItemIsDark) {
|
||||||
|
|
Loading…
Reference in New Issue