ProgressButton fixes
This commit is contained in:
@@ -2,7 +2,9 @@ package org.koitharu.kotatsu.core.ui.widgets
|
|||||||
|
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.res.ColorStateList
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Color
|
||||||
import android.graphics.Outline
|
import android.graphics.Outline
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@@ -19,6 +21,7 @@ import androidx.core.widget.TextViewCompat
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.util.ext.getAnimationDuration
|
import org.koitharu.kotatsu.core.util.ext.getAnimationDuration
|
||||||
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
import org.koitharu.kotatsu.core.util.ext.getThemeColor
|
||||||
|
import org.koitharu.kotatsu.core.util.ext.getThemeColorStateList
|
||||||
import org.koitharu.kotatsu.core.util.ext.resolveDp
|
import org.koitharu.kotatsu.core.util.ext.resolveDp
|
||||||
import org.koitharu.kotatsu.core.util.ext.setTextAndVisible
|
import org.koitharu.kotatsu.core.util.ext.setTextAndVisible
|
||||||
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
import org.koitharu.kotatsu.core.util.ext.textAndVisible
|
||||||
@@ -35,9 +38,8 @@ class ProgressButton @JvmOverloads constructor(
|
|||||||
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
|
|
||||||
private var progress = 0f
|
private var progress = 0f
|
||||||
private var colorBase = context.getThemeColor(materialR.attr.colorPrimaryContainer)
|
private var colorBase: ColorStateList = ColorStateList.valueOf(Color.TRANSPARENT)
|
||||||
private var colorProgress = context.getThemeColor(materialR.attr.colorPrimary)
|
private var colorProgress: ColorStateList = ColorStateList.valueOf(Color.TRANSPARENT)
|
||||||
private var colorText = context.getThemeColor(materialR.attr.colorOnPrimaryContainer)
|
|
||||||
private var progressAnimator: ValueAnimator? = null
|
private var progressAnimator: ValueAnimator? = null
|
||||||
|
|
||||||
var title: CharSequence?
|
var title: CharSequence?
|
||||||
@@ -69,9 +71,12 @@ class ProgressButton @JvmOverloads constructor(
|
|||||||
)
|
)
|
||||||
textViewTitle.text = getText(R.styleable.ProgressButton_title)
|
textViewTitle.text = getText(R.styleable.ProgressButton_title)
|
||||||
textViewSubtitle.text = getText(R.styleable.ProgressButton_subtitle)
|
textViewSubtitle.text = getText(R.styleable.ProgressButton_subtitle)
|
||||||
colorBase = getColor(R.styleable.ProgressButton_baseColor, colorBase)
|
colorBase = getColorStateList(R.styleable.ProgressButton_baseColor)
|
||||||
colorProgress = getColor(R.styleable.ProgressButton_progressColor, colorProgress)
|
?: context.getThemeColorStateList(materialR.attr.colorPrimaryContainer) ?: colorBase
|
||||||
colorText = getColor(R.styleable.ProgressButton_textColor, colorText)
|
colorProgress = getColorStateList(R.styleable.ProgressButton_progressColor)
|
||||||
|
?: context.getThemeColorStateList(materialR.attr.colorPrimary) ?: colorProgress
|
||||||
|
val colorText = getColorStateList(R.styleable.ProgressButton_android_textColor)
|
||||||
|
?: context.getThemeColorStateList(materialR.attr.colorOnPrimaryContainer) ?: textViewTitle.textColors
|
||||||
textViewTitle.setTextColor(colorText)
|
textViewTitle.setTextColor(colorText)
|
||||||
textViewSubtitle.setTextColor(colorText)
|
textViewSubtitle.setTextColor(colorText)
|
||||||
progress = getInt(R.styleable.ProgressButton_android_progress, 0).toFloat() /
|
progress = getInt(R.styleable.ProgressButton_android_progress, 0).toFloat() /
|
||||||
@@ -87,15 +92,15 @@ class ProgressButton @JvmOverloads constructor(
|
|||||||
)
|
)
|
||||||
|
|
||||||
paint.style = Paint.Style.FILL
|
paint.style = Paint.Style.FILL
|
||||||
paint.color = colorProgress
|
|
||||||
paint.alpha = 84 // 255 * 0.33F
|
|
||||||
applyGravity()
|
applyGravity()
|
||||||
setWillNotDraw(false)
|
setWillNotDraw(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDraw(canvas: Canvas) {
|
override fun onDraw(canvas: Canvas) {
|
||||||
super.onDraw(canvas)
|
super.onDraw(canvas)
|
||||||
canvas.drawColor(colorBase)
|
canvas.drawColor(colorBase.getColorForState(drawableState, colorBase.defaultColor))
|
||||||
|
paint.color = colorProgress.getColorForState(drawableState, colorProgress.defaultColor)
|
||||||
|
paint.alpha = 84 // 255 * 0.33F
|
||||||
canvas.drawRect(0f, 0f, width * progress, height.toFloat(), paint)
|
canvas.drawRect(0f, 0f, width * progress, height.toFloat(), paint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,8 +105,8 @@
|
|||||||
android:id="@+id/imageView_state"
|
android:id="@+id/imageView_state"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_marginVertical="0.5dp"
|
android:layout_marginVertical="0.5dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
app:layout_constraintBottom_toBottomOf="@id/textView_state"
|
app:layout_constraintBottom_toBottomOf="@id/textView_state"
|
||||||
app:layout_constraintDimensionRatio="1"
|
app:layout_constraintDimensionRatio="1"
|
||||||
app:layout_constraintStart_toEndOf="@id/imageView_cover"
|
app:layout_constraintStart_toEndOf="@id/imageView_cover"
|
||||||
@@ -180,12 +180,13 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:paddingHorizontal="6dp"
|
android:paddingHorizontal="6dp"
|
||||||
android:paddingVertical="8dp"
|
android:paddingVertical="8dp"
|
||||||
|
android:textColor="?colorOnPrimaryContainer"
|
||||||
|
app:baseColor="?colorSecondaryContainer"
|
||||||
app:layout_constraintEnd_toStartOf="@id/button_chapters"
|
app:layout_constraintEnd_toStartOf="@id/button_chapters"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/info_layout"
|
app:layout_constraintTop_toBottomOf="@id/info_layout"
|
||||||
app:progressColor="?colorPrimary"
|
app:progressColor="?colorPrimary"
|
||||||
app:subtitleTextAppearance="?textAppearanceBodySmall"
|
app:subtitleTextAppearance="?textAppearanceBodySmall"
|
||||||
app:textColor="?colorOnPrimaryContainer"
|
|
||||||
app:titleTextAppearance="?textAppearanceButton"
|
app:titleTextAppearance="?textAppearanceButton"
|
||||||
tools:max="100"
|
tools:max="100"
|
||||||
tools:progress="40"
|
tools:progress="40"
|
||||||
|
|||||||
@@ -153,7 +153,7 @@
|
|||||||
<attr name="subtitleTextAppearance" />
|
<attr name="subtitleTextAppearance" />
|
||||||
<attr name="title" />
|
<attr name="title" />
|
||||||
<attr name="subtitle" />
|
<attr name="subtitle" />
|
||||||
<attr name="textColor" format="color" />
|
<attr name="android:textColor" />
|
||||||
<attr name="android:max" />
|
<attr name="android:max" />
|
||||||
<attr name="android:progress" />
|
<attr name="android:progress" />
|
||||||
<attr name="baseColor" format="color" />
|
<attr name="baseColor" format="color" />
|
||||||
|
|||||||
Reference in New Issue
Block a user