feat:初步完成首页下拉动画
This commit is contained in:
BIN
app/src/main/assets/svga/refresh_header.svga
Normal file
BIN
app/src/main/assets/svga/refresh_header.svga
Normal file
Binary file not shown.
@@ -0,0 +1,102 @@
|
|||||||
|
package com.nnbc123.app.home.refresh
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.Gravity
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.FrameLayout
|
||||||
|
import com.chuhai.utils.UiUtils
|
||||||
|
import com.nnbc123.app.ui.utils.loadFromAssets
|
||||||
|
import com.opensource.svgaplayer.SVGADrawable
|
||||||
|
import com.opensource.svgaplayer.SVGAImageView
|
||||||
|
import com.scwang.smartrefresh.layout.api.RefreshHeader
|
||||||
|
import com.scwang.smartrefresh.layout.api.RefreshKernel
|
||||||
|
import com.scwang.smartrefresh.layout.api.RefreshLayout
|
||||||
|
import com.scwang.smartrefresh.layout.constant.RefreshState
|
||||||
|
import com.scwang.smartrefresh.layout.constant.SpinnerStyle
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Max on 2023/12/26 19:35
|
||||||
|
* Desc:
|
||||||
|
**/
|
||||||
|
class HomeRefreshHeader : FrameLayout, RefreshHeader {
|
||||||
|
|
||||||
|
private var svgaView: SVGAImageView? = null
|
||||||
|
|
||||||
|
constructor(context: Context) : super(context)
|
||||||
|
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||||
|
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
|
||||||
|
context,
|
||||||
|
attrs,
|
||||||
|
defStyleAttr
|
||||||
|
)
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet?,
|
||||||
|
defStyleAttr: Int,
|
||||||
|
defStyleRes: Int
|
||||||
|
) : super(context, attrs, defStyleAttr, defStyleRes)
|
||||||
|
|
||||||
|
init {
|
||||||
|
svgaView = SVGAImageView(context)
|
||||||
|
svgaView?.loadFromAssets("svga/refresh_header.svga", false)
|
||||||
|
val size = UiUtils.dip2px(48f)
|
||||||
|
val layoutParams = LayoutParams(size, size)
|
||||||
|
layoutParams.gravity = Gravity.CENTER
|
||||||
|
addView(svgaView, layoutParams)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStateChanged(
|
||||||
|
refreshLayout: RefreshLayout?,
|
||||||
|
oldState: RefreshState?,
|
||||||
|
newState: RefreshState?
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getView(): View {
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getSpinnerStyle(): SpinnerStyle {
|
||||||
|
return SpinnerStyle.Translate
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setPrimaryColors(vararg colors: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onInitialized(kernel: RefreshKernel?, height: Int, extendHeight: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onHorizontalDrag(percentX: Float, offsetX: Int, offsetMax: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartAnimator(layout: RefreshLayout?, height: Int, extendHeight: Int) {
|
||||||
|
svgaView?.startAnimation()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFinish(layout: RefreshLayout?, success: Boolean): Int {
|
||||||
|
svgaView?.stopAnimation()
|
||||||
|
return 500
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSupportHorizontalDrag(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPullingDown(
|
||||||
|
percent: Float,
|
||||||
|
offset: Int,
|
||||||
|
headerHeight: Int,
|
||||||
|
extendHeight: Int
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onReleasing(
|
||||||
|
percent: Float,
|
||||||
|
offset: Int,
|
||||||
|
headerHeight: Int,
|
||||||
|
extendHeight: Int
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
@@ -215,7 +215,7 @@ public class UserInfoActivity extends BaseBindingActivity<ActivityUserInfoBindin
|
|||||||
private void setWhereVisible() {
|
private void setWhereVisible() {
|
||||||
if (viewModel.getMRoomUid() != 0) {
|
if (viewModel.getMRoomUid() != 0) {
|
||||||
mBinding.flLiving.setVisibility(View.VISIBLE);
|
mBinding.flLiving.setVisibility(View.VISIBLE);
|
||||||
ImageLoadKt.loadFromAssets(mBinding.svgaLiving, "svga/living_black.svga");
|
ImageLoadKt.loadFromAssets(mBinding.svgaLiving, "svga/living_black.svga", true);
|
||||||
mBinding.ivAvatar.setBorderColor(Color.parseColor("#FFE710"));
|
mBinding.ivAvatar.setBorderColor(Color.parseColor("#FFE710"));
|
||||||
} else {
|
} else {
|
||||||
mBinding.flLiving.setVisibility(View.GONE);
|
mBinding.flLiving.setVisibility(View.GONE);
|
||||||
|
@@ -133,14 +133,16 @@ fun SVGAImageView.loadFromUrl(svgaUrl: String?) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun SVGAImageView.loadFromAssets(name: String) {
|
fun SVGAImageView.loadFromAssets(name: String, autoPlay: Boolean = true) {
|
||||||
try {
|
try {
|
||||||
SVGAParser.shareParser()
|
SVGAParser.shareParser()
|
||||||
.decodeFromAssets(name, object : SVGAParser.ParseCompletion {
|
.decodeFromAssets(name, object : SVGAParser.ParseCompletion {
|
||||||
override fun onComplete(videoItem: SVGAVideoEntity) {
|
override fun onComplete(videoItem: SVGAVideoEntity) {
|
||||||
val drawable = SVGADrawable(videoItem)
|
val drawable = SVGADrawable(videoItem)
|
||||||
setImageDrawable(drawable)
|
setImageDrawable(drawable)
|
||||||
startAnimation()
|
if (autoPlay) {
|
||||||
|
startAnimation()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onError() {
|
override fun onError() {
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
@@ -8,10 +8,15 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<com.scwang.smartrefresh.layout.header.ClassicsHeader
|
<com.nnbc123.app.home.refresh.HomeRefreshHeader
|
||||||
android:id="@+id/refresh_header"
|
android:id="@+id/refresh_header"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="94dp" />
|
||||||
|
|
||||||
|
<!-- <com.scwang.smartrefresh.layout.header.ClassicsHeader-->
|
||||||
|
<!-- android:id="@+id/refresh_header"-->
|
||||||
|
<!-- android:layout_width="match_parent"-->
|
||||||
|
<!-- android:layout_height="wrap_content" />-->
|
||||||
|
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
android:id="@+id/coordinator_layout"
|
android:id="@+id/coordinator_layout"
|
||||||
|
Reference in New Issue
Block a user