FakeSingleRoomFragment优化
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.yizhuan.erban.avroom.fragment
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.view.View
|
||||
import com.opensource.svgaplayer.SVGADrawable
|
||||
import com.opensource.svgaplayer.SVGAImageView
|
||||
import com.opensource.svgaplayer.SVGAParser
|
||||
@@ -19,10 +18,10 @@ class FakeSingleRoomFragment : BaseViewBindingFragment<FragmentFakeSingleRoomBin
|
||||
private var preRoomInfo: RoomInfo? = null
|
||||
private var needJump = false
|
||||
private var lastRequestTime = 0L
|
||||
private var index = 1
|
||||
private val minRequestTime = 60 * 1000
|
||||
private val bgPicture = arrayOf("")
|
||||
private var requesting = false
|
||||
private var initBg = false
|
||||
private val stopRunnable = {
|
||||
if (!isDestroyView) {
|
||||
binding.svgaImageViewBg.stopAnimation()
|
||||
@@ -30,22 +29,24 @@ class FakeSingleRoomFragment : BaseViewBindingFragment<FragmentFakeSingleRoomBin
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
playSvgaBg(binding.svgaImageViewBg, "svga/single_back.svga")
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
fun requestPreRoomInfo() {
|
||||
if (!initBg) {
|
||||
playSvgaBg(binding.svgaImageViewBg, "svga/single_back.svga")
|
||||
initBg = true
|
||||
}
|
||||
if (!binding.svgaImageViewBg.isAnimating) {
|
||||
binding.svgaImageViewBg.removeCallbacks(stopRunnable)
|
||||
binding.svgaImageViewBg.startAnimation()
|
||||
}
|
||||
if (CurrentTimeUtils.getCurrentTime() - lastRequestTime < minRequestTime) {
|
||||
if (requesting || CurrentTimeUtils.getCurrentTime() - lastRequestTime < minRequestTime) {
|
||||
return
|
||||
}
|
||||
preRoomInfo = null
|
||||
lastRequestTime = CurrentTimeUtils.getCurrentTime()
|
||||
requesting = true
|
||||
index++
|
||||
AvRoomModel.get()
|
||||
.nextSingleRoomInfo
|
||||
.subscribe({
|
||||
@@ -84,19 +85,14 @@ class FakeSingleRoomFragment : BaseViewBindingFragment<FragmentFakeSingleRoomBin
|
||||
}
|
||||
|
||||
private fun playSvgaBg(svgaRoomBg: SVGAImageView, assets: String) {
|
||||
svgaRoomBg.clearAnimation()
|
||||
svgaRoomBg.visibility = View.VISIBLE
|
||||
val mSVGAParser = SVGAParser(svgaRoomBg.context)
|
||||
mSVGAParser.decodeFromAssets(assets, object : SVGAParser.ParseCompletion {
|
||||
SVGAParser.shareParser().decodeFromAssets(assets, object : SVGAParser.ParseCompletion {
|
||||
override fun onComplete(videoItem: SVGAVideoEntity) {
|
||||
svgaRoomBg.visibility = View.VISIBLE
|
||||
val drawable = SVGADrawable(videoItem)
|
||||
svgaRoomBg.setImageDrawable(drawable)
|
||||
svgaRoomBg.startAnimation()
|
||||
}
|
||||
|
||||
override fun onError() {
|
||||
svgaRoomBg.visibility = View.GONE
|
||||
}
|
||||
|
||||
}, null)
|
||||
|
@@ -10,8 +10,7 @@
|
||||
android:id="@+id/svga_image_view_bg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
app:autoPlay="true" />
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
Reference in New Issue
Block a user