pref: 吧页面顶栏隐藏时沉浸
This commit is contained in:
parent
6468b8c711
commit
dfe98587bf
|
|
@ -10,6 +10,7 @@ import android.content.res.ColorStateList
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
|
import android.graphics.drawable.GradientDrawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
|
@ -93,7 +94,10 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
|
||||||
@BindView(R.id.toolbar_btn_right)
|
@BindView(R.id.toolbar_btn_right)
|
||||||
lateinit var toolbarEndBtn: MaterialButton
|
lateinit var toolbarEndBtn: MaterialButton
|
||||||
|
|
||||||
@BindView(R.id.header_view_parent)
|
@BindView(R.id.forum_info_parent)
|
||||||
|
lateinit var forumInfoView: View
|
||||||
|
|
||||||
|
@BindView(R.id.forum_header)
|
||||||
lateinit var headerView: View
|
lateinit var headerView: View
|
||||||
|
|
||||||
@BindView(R.id.forum_header_stat_title)
|
@BindView(R.id.forum_header_stat_title)
|
||||||
|
|
@ -126,6 +130,9 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
|
||||||
@BindView(R.id.forum_tab)
|
@BindView(R.id.forum_tab)
|
||||||
lateinit var headerTabView: TabLayout
|
lateinit var headerTabView: TabLayout
|
||||||
|
|
||||||
|
@BindView(R.id.forum_tab_background)
|
||||||
|
lateinit var headerTabBackground: View
|
||||||
|
|
||||||
@BindView(R.id.forum_header_progress)
|
@BindView(R.id.forum_header_progress)
|
||||||
lateinit var progressBar: ProgressBar
|
lateinit var progressBar: ProgressBar
|
||||||
|
|
||||||
|
|
@ -135,7 +142,14 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
|
||||||
@BindView(R.id.collapsing_toolbar)
|
@BindView(R.id.collapsing_toolbar)
|
||||||
lateinit var collapsingToolbar: CollapsingToolbarLayout
|
lateinit var collapsingToolbar: CollapsingToolbarLayout
|
||||||
|
|
||||||
var toolbarColor: Int = Color.TRANSPARENT
|
var toolbarColor: Int = -1
|
||||||
|
var customToolbarColorEnable = true
|
||||||
|
set(value) {
|
||||||
|
if (field != value) {
|
||||||
|
setCustomStatusColor(if (value) toolbarColor else -1)
|
||||||
|
}
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
override fun getLayoutId(): Int {
|
override fun getLayoutId(): Int {
|
||||||
return R.layout.activity_forum
|
return R.layout.activity_forum
|
||||||
|
|
@ -204,10 +218,32 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initView() {
|
private fun initView() {
|
||||||
appbar.addOnOffsetChangedListener(OnOffsetChangedListener { _, verticalOffset: Int ->
|
appbar.addOnOffsetChangedListener(OnOffsetChangedListener { _, verticalOffset ->
|
||||||
val titleVisible = mDataBean != null && forumName != null && abs(verticalOffset) >= headerView.height
|
val toolbarScrollOffset = 0 - (verticalOffset + headerView.height)
|
||||||
val percent: Float = if (abs(verticalOffset) <= headerView.height) {
|
if (toolbarScrollOffset >= 0) {
|
||||||
abs(verticalOffset.toFloat()) / headerView.height.toFloat()
|
val toolbarScrollPercent = toolbarScrollOffset.toFloat() / toolbar.height
|
||||||
|
var radius = resources.getDimensionPixelSize(R.dimen.radius).toFloat()
|
||||||
|
radius -= radius * toolbarScrollPercent
|
||||||
|
if (headerTabBackground.background is GradientDrawable) {
|
||||||
|
(headerTabBackground.background as GradientDrawable).cornerRadii = floatArrayOf(
|
||||||
|
radius, radius,
|
||||||
|
radius, radius,
|
||||||
|
0f, 0f,
|
||||||
|
0f, 0f
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
headerTabBackground.background = getRadiusDrawable(
|
||||||
|
topLeftPx = radius,
|
||||||
|
topRightPx = radius
|
||||||
|
)
|
||||||
|
}
|
||||||
|
customToolbarColorEnable = toolbarScrollPercent < 1f
|
||||||
|
} else {
|
||||||
|
customToolbarColorEnable = true
|
||||||
|
}
|
||||||
|
val titleVisible = mDataBean != null && forumName != null && abs(verticalOffset) >= forumInfoView.height
|
||||||
|
val percent: Float = if (abs(verticalOffset) <= forumInfoView.height) {
|
||||||
|
abs(verticalOffset.toFloat()) / forumInfoView.height.toFloat()
|
||||||
} else {
|
} else {
|
||||||
1f
|
1f
|
||||||
}
|
}
|
||||||
|
|
@ -215,14 +251,14 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
|
||||||
toolbarEndBtn.visibility = if (titleVisible) View.VISIBLE else View.GONE
|
toolbarEndBtn.visibility = if (titleVisible) View.VISIBLE else View.GONE
|
||||||
toolbar.backgroundTintList = ColorStateList.valueOf(Util.changeAlpha(toolbarColor, percent))
|
toolbar.backgroundTintList = ColorStateList.valueOf(Util.changeAlpha(toolbarColor, percent))
|
||||||
if (animated && ThemeUtil.THEME_TRANSLUCENT == ThemeUtil.getTheme(this)) {
|
if (animated && ThemeUtil.THEME_TRANSLUCENT == ThemeUtil.getTheme(this)) {
|
||||||
if (abs(verticalOffset) > headerView.height) {
|
if (abs(verticalOffset) > forumInfoView.height) {
|
||||||
AnimUtil.alphaOut(headerView).setListener(object : AnimatorListenerAdapter() {
|
AnimUtil.alphaOut(forumInfoView).setListener(object : AnimatorListenerAdapter() {
|
||||||
override fun onAnimationEnd(animation: Animator) {
|
override fun onAnimationEnd(animation: Animator) {
|
||||||
headerView.visibility = View.INVISIBLE
|
forumInfoView.visibility = View.INVISIBLE
|
||||||
}
|
}
|
||||||
}).start()
|
}).start()
|
||||||
} else {
|
} else {
|
||||||
AnimUtil.alphaIn(headerView).start()
|
AnimUtil.alphaIn(forumInfoView).start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -400,7 +436,7 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
|
||||||
|
|
||||||
private fun refreshHeaderView() {
|
private fun refreshHeaderView() {
|
||||||
if (mDataBean != null && mDataBean!!.forum != null) {
|
if (mDataBean != null && mDataBean!!.forum != null) {
|
||||||
headerView.visibility = View.VISIBLE
|
forumInfoView.visibility = View.VISIBLE
|
||||||
try {
|
try {
|
||||||
val color = getDarkerColor(greifyColor(Color.parseColor("#${mDataBean?.forum?.themeColor?.day?.commonColor ?: ThemeUtils.getColorById(this, R.color.default_color_primary)}"), 0.15f), 0.1f)
|
val color = getDarkerColor(greifyColor(Color.parseColor("#${mDataBean?.forum?.themeColor?.day?.commonColor ?: ThemeUtils.getColorById(this, R.color.default_color_primary)}"), 0.15f), 0.1f)
|
||||||
toolbarColor = color
|
toolbarColor = color
|
||||||
|
|
@ -472,7 +508,7 @@ class ForumActivity : BaseActivity(), View.OnClickListener, OnRefreshedListener,
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
} else {
|
} else {
|
||||||
headerView.visibility = View.INVISIBLE
|
forumInfoView.visibility = View.INVISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,17 +25,17 @@
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/forum_header"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:layout_marginTop="?attr/actionBarSize">
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/header_view_parent"
|
android:id="@+id/forum_info_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="?attr/actionBarSize"
|
android:padding="16dp">
|
||||||
android:padding="16dp"
|
|
||||||
android:paddingTop="120dp">
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/forum_header_avatar"
|
android:id="@+id/forum_header_avatar"
|
||||||
|
|
@ -291,6 +291,7 @@
|
||||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||||
|
|
||||||
<com.huanchengfly.tieba.post.widgets.theme.TintFrameLayout
|
<com.huanchengfly.tieba.post.widgets.theme.TintFrameLayout
|
||||||
|
android:id="@+id/forum_tab_background"
|
||||||
app:backgroundTint="@color/default_color_background"
|
app:backgroundTint="@color/default_color_background"
|
||||||
android:background="@drawable/bg_top_radius_8dp"
|
android:background="@drawable/bg_top_radius_8dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue