81 lines
2.9 KiB
Kotlin
81 lines
2.9 KiB
Kotlin
package com.gh.common.view
|
|
|
|
import android.content.Context
|
|
import android.text.TextUtils
|
|
import android.util.AttributeSet
|
|
import android.view.View
|
|
import androidx.constraintlayout.widget.ConstraintLayout
|
|
import androidx.core.content.ContextCompat
|
|
import com.facebook.drawee.generic.RoundingParams
|
|
import com.facebook.drawee.view.SimpleDraweeView
|
|
import com.gh.common.util.DisplayUtils
|
|
import com.gh.common.util.ImageUtils
|
|
import com.gh.common.util.goneIf
|
|
import com.gh.gamecenter.R
|
|
import com.gh.gamecenter.entity.GameEntity
|
|
import kotlinx.android.synthetic.main.layout_game_icon.view.*
|
|
|
|
class GameIconView : ConstraintLayout {
|
|
|
|
private var mCornerRadius = 10
|
|
private var mBorderColor = 0
|
|
private var mGameIconOverlayColor = 0
|
|
private var mBorderWidth = 1
|
|
private var mFadeDuration = -1
|
|
|
|
constructor(context: Context) : super(context, null)
|
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs, 0) {
|
|
initView(attrs)
|
|
}
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
|
initView(attrs)
|
|
}
|
|
|
|
fun initView(attrs: AttributeSet) {
|
|
View.inflate(context, R.layout.layout_game_icon, this)
|
|
|
|
val ta = context.obtainStyledAttributes(attrs, R.styleable.GameIconView)
|
|
mCornerRadius = ta.getDimensionPixelSize(R.styleable.GameIconView_gameIconCornerRadius, DisplayUtils.dip2px(10F))
|
|
mBorderColor = ta.getColor(R.styleable.GameIconView_gameIconBorderColor, 0)
|
|
mGameIconOverlayColor = ta.getColor(R.styleable.GameIconView_gameIconOverlayColor, 0)
|
|
mBorderWidth = ta.getDimensionPixelSize(R.styleable.GameIconView_gameIconBorderWidth, 1)
|
|
mFadeDuration = ta.getInt(R.styleable.GameIconView_gameIconFadeDuration, -1)
|
|
ta.recycle()
|
|
|
|
val roundingParams = RoundingParams.fromCornersRadius(mCornerRadius.toFloat())
|
|
if (mGameIconOverlayColor != 0) {
|
|
roundingParams.overlayColor = mGameIconOverlayColor
|
|
}
|
|
|
|
if (mBorderColor != 0) {
|
|
roundingParams.setBorder(mBorderColor, mBorderWidth.toFloat())
|
|
}
|
|
gameIconIv.hierarchy.roundingParams = roundingParams
|
|
gameIconDecoratorIv.hierarchy.roundingParams = roundingParams
|
|
|
|
if (mFadeDuration != -1) {
|
|
gameIconIv.hierarchy.fadeDuration = mFadeDuration
|
|
}
|
|
}
|
|
|
|
fun displayGameIcon(game: GameEntity) {
|
|
if (!TextUtils.isEmpty(game.rawIcon)) {
|
|
displayGameIcon(game.rawIcon ?: "", game.iconSubscript)
|
|
} else {
|
|
displayGameIcon(game.icon ?: "", null)
|
|
}
|
|
}
|
|
|
|
fun displayGameIcon(icon: String?, iconSubscript: String?) {
|
|
ImageUtils.display(gameIconIv, icon)
|
|
ImageUtils.display(gameIconDecoratorIv, iconSubscript)
|
|
gameIconDecoratorIv.goneIf(TextUtils.isEmpty(iconSubscript))
|
|
}
|
|
|
|
fun getIconIv(): SimpleDraweeView = gameIconIv
|
|
|
|
fun getIconDecoratorIv(): SimpleDraweeView = gameIconDecoratorIv
|
|
|
|
}
|