Skip to content

Commit

Permalink
@Unstable LyricAdapter: Split ViewHolders (1/?)
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsummer233 committed Dec 21, 2024
1 parent 4a88bb2 commit a872c7e
Show file tree
Hide file tree
Showing 11 changed files with 820 additions and 415 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,9 @@ inline fun mayThrowForegroundServiceStartNotAllowed(): Boolean =
Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2

inline fun Sequence<View>.getTextViews(
crossinline action: (TextView) -> Unit
crossinline action: (CustomTextView) -> Unit
) {
this.forEach {
if (it is TextView) action.invoke(it)
if (it is CustomTextView) action.invoke(it)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class CustomTextView @JvmOverloads constructor(
}

override fun onDraw(canvas: Canvas) {
paint.setShader(gradient)
paint.shader = gradient
super.onDraw(canvas)
paint.setShader(null)
paint.shader = null
}

override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ import androidx.core.view.doOnLayout
import org.akanework.gramophone.R
import kotlin.math.min

class FadingVerticalEdgeLayout : FrameLayout {
class FadingVerticalEdgeLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

init {
init(attrs)
}

private var fadeTop = false
private var fadeBottom = false
private var gradientSizeTop = 0
Expand All @@ -40,22 +49,6 @@ class FadingVerticalEdgeLayout : FrameLayout {

private val overlayColorFilter = ColorMatrixColorFilter(colorMatrix)

constructor(context: Context?) : super(context!!) {
init(null)
}

constructor(context: Context?, attrs: AttributeSet?) : super(
context!!, attrs
) {
init(attrs)
}

constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
context!!, attrs, defStyleAttr
) {
init(attrs)
}

private val overlayPaint = Paint().apply {
xfermode = PorterDuffXfermode(PorterDuff.Mode.OVERLAY)
colorFilter = overlayColorFilter
Expand All @@ -67,15 +60,18 @@ class FadingVerticalEdgeLayout : FrameLayout {
resources.displayMetrics
).toInt()
if (attrs != null) {
val arr =
context.obtainStyledAttributes(attrs, R.styleable.FadingVerticalEdgeLayout, 0, 0)
val arr = context.obtainStyledAttributes(
attrs, R.styleable.FadingVerticalEdgeLayout, 0, 0
)
val flags = arr.getInt(R.styleable.FadingVerticalEdgeLayout_fel_edge, 0)
fadeTop = flags and FADE_EDGE_TOP == FADE_EDGE_TOP
fadeBottom = flags and FADE_EDGE_BOTTOM == FADE_EDGE_BOTTOM
gradientSizeTop =
arr.getDimensionPixelSize(R.styleable.FadingVerticalEdgeLayout_fel_size_top, defaultSize)
gradientSizeBottom =
arr.getDimensionPixelSize(R.styleable.FadingVerticalEdgeLayout_fel_size_bottom, defaultSize)
gradientSizeTop = arr.getDimensionPixelSize(
R.styleable.FadingVerticalEdgeLayout_fel_size_top, defaultSize
)
gradientSizeBottom = arr.getDimensionPixelSize(
R.styleable.FadingVerticalEdgeLayout_fel_size_bottom, defaultSize
)
if (fadeTop && gradientSizeTop > 0) {
gradientDirtyFlags = gradientDirtyFlags or DIRTY_FLAG_TOP
}
Expand All @@ -88,10 +84,12 @@ class FadingVerticalEdgeLayout : FrameLayout {
gradientSizeTop = gradientSizeBottom
}
val mode = PorterDuffXfermode(PorterDuff.Mode.DST_IN)
gradientPaintTop = Paint(Paint.ANTI_ALIAS_FLAG)
gradientPaintTop!!.xfermode = mode
gradientPaintBottom = Paint(Paint.ANTI_ALIAS_FLAG)
gradientPaintBottom!!.xfermode = mode
gradientPaintTop = Paint(Paint.ANTI_ALIAS_FLAG).apply {
xfermode = mode
}
gradientPaintBottom = Paint(Paint.ANTI_ALIAS_FLAG).apply {
xfermode = mode
}
gradientRectTop = Rect()
gradientRectBottom = Rect()
}
Expand Down Expand Up @@ -186,13 +184,14 @@ class FadingVerticalEdgeLayout : FrameLayout {
null,
Shader.TileMode.CLAMP
)
gradientPaintTop!!.setShader(gradient)
gradientPaintTop!!.shader = gradient
}

private fun initBottomGradient() {
val actualHeight = height - paddingTop - paddingBottom
val size =
min(gradientSizeBottom.toDouble(), actualHeight.toDouble()).toInt()
val size = min(
gradientSizeBottom.toDouble(), actualHeight.toDouble()
).toInt()
val l = paddingLeft
val t = paddingTop + actualHeight - size
val r = width - paddingRight
Expand Down
Loading

0 comments on commit a872c7e

Please sign in to comment.