feat:初步完成首页下拉动画

This commit is contained in:
Max
2023-12-26 20:20:31 +08:00
parent b41a2e0376
commit 802383b9e8
6 changed files with 114 additions and 5 deletions

Binary file not shown.

View File

@@ -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
) {
}
}

View File

@@ -215,7 +215,7 @@ public class UserInfoActivity extends BaseBindingActivity<ActivityUserInfoBindin
private void setWhereVisible() {
if (viewModel.getMRoomUid() != 0) {
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"));
} else {
mBinding.flLiving.setVisibility(View.GONE);

View File

@@ -133,15 +133,17 @@ fun SVGAImageView.loadFromUrl(svgaUrl: String?) {
}
}
fun SVGAImageView.loadFromAssets(name: String) {
fun SVGAImageView.loadFromAssets(name: String, autoPlay: Boolean = true) {
try {
SVGAParser.shareParser()
.decodeFromAssets(name, object : SVGAParser.ParseCompletion {
override fun onComplete(videoItem: SVGAVideoEntity) {
val drawable = SVGADrawable(videoItem)
setImageDrawable(drawable)
if (autoPlay) {
startAnimation()
}
}
override fun onError() {
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -8,10 +8,15 @@
android:layout_width="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: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
android:id="@+id/coordinator_layout"