|
@@ -2,13 +2,21 @@ package eu.kanade.tachiyomi.ui.reader.viewer
|
|
|
|
|
|
import android.content.Context
|
|
import android.content.Context
|
|
import android.util.AttributeSet
|
|
import android.util.AttributeSet
|
|
|
|
+import android.view.Gravity
|
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
|
-import android.view.animation.Animation
|
|
|
|
-import android.view.animation.LinearInterpolator
|
|
|
|
-import android.view.animation.RotateAnimation
|
|
|
|
import android.widget.FrameLayout
|
|
import android.widget.FrameLayout
|
|
import androidx.annotation.IntRange
|
|
import androidx.annotation.IntRange
|
|
|
|
+import androidx.compose.material3.CircularProgressIndicator
|
|
|
|
+import androidx.compose.runtime.Composable
|
|
|
|
+import androidx.compose.runtime.getValue
|
|
|
|
+import androidx.compose.runtime.mutableFloatStateOf
|
|
|
|
+import androidx.compose.runtime.setValue
|
|
|
|
+import androidx.compose.ui.platform.AbstractComposeView
|
|
|
|
+import androidx.compose.ui.platform.ViewCompositionStrategy
|
|
|
|
+import androidx.core.view.isVisible
|
|
import com.google.android.material.progressindicator.CircularProgressIndicator
|
|
import com.google.android.material.progressindicator.CircularProgressIndicator
|
|
|
|
+import eu.kanade.presentation.theme.TachiyomiTheme
|
|
|
|
+import tachiyomi.presentation.core.components.CombinedCircularProgressIndicator
|
|
|
|
|
|
/**
|
|
/**
|
|
* A wrapper for [CircularProgressIndicator] that always rotates.
|
|
* A wrapper for [CircularProgressIndicator] that always rotates.
|
|
@@ -19,76 +27,31 @@ class ReaderProgressIndicator @JvmOverloads constructor(
|
|
context: Context,
|
|
context: Context,
|
|
attrs: AttributeSet? = null,
|
|
attrs: AttributeSet? = null,
|
|
defStyleAttr: Int = 0,
|
|
defStyleAttr: Int = 0,
|
|
-) : FrameLayout(context, attrs, defStyleAttr) {
|
|
|
|
-
|
|
|
|
- private val indicator: CircularProgressIndicator
|
|
|
|
-
|
|
|
|
- private val rotateAnimation by lazy {
|
|
|
|
- RotateAnimation(
|
|
|
|
- 0F,
|
|
|
|
- 360F,
|
|
|
|
- Animation.RELATIVE_TO_SELF,
|
|
|
|
- 0.5F,
|
|
|
|
- Animation.RELATIVE_TO_SELF,
|
|
|
|
- 0.5F,
|
|
|
|
- ).apply {
|
|
|
|
- interpolator = LinearInterpolator()
|
|
|
|
- repeatCount = Animation.INFINITE
|
|
|
|
- duration = 4000
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+) : AbstractComposeView(context, attrs, defStyleAttr) {
|
|
|
|
|
|
init {
|
|
init {
|
|
- layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
|
|
|
|
- indicator = CircularProgressIndicator(context)
|
|
|
|
- indicator.max = 100
|
|
|
|
- indicator.isIndeterminate = true
|
|
|
|
- addView(indicator)
|
|
|
|
|
|
+ layoutParams = FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER)
|
|
|
|
+ setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindowOrReleasedFromPool)
|
|
}
|
|
}
|
|
|
|
|
|
- override fun onAttachedToWindow() {
|
|
|
|
- super.onAttachedToWindow()
|
|
|
|
- updateRotateAnimation()
|
|
|
|
- }
|
|
|
|
|
|
+ private var progress by mutableFloatStateOf(0f)
|
|
|
|
|
|
- override fun onDetachedFromWindow() {
|
|
|
|
- super.onDetachedFromWindow()
|
|
|
|
- updateRotateAnimation()
|
|
|
|
|
|
+ @Composable
|
|
|
|
+ override fun Content() {
|
|
|
|
+ TachiyomiTheme {
|
|
|
|
+ CombinedCircularProgressIndicator(progress = progress)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
fun show() {
|
|
fun show() {
|
|
- indicator.show()
|
|
|
|
- updateRotateAnimation()
|
|
|
|
|
|
+ isVisible = true
|
|
}
|
|
}
|
|
|
|
|
|
fun hide() {
|
|
fun hide() {
|
|
- indicator.hide()
|
|
|
|
- updateRotateAnimation()
|
|
|
|
|
|
+ isVisible = false
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Sets the current indicator progress to the specified value.
|
|
|
|
- *
|
|
|
|
- * @param progress Indicator will be set indeterminate if this value is 0
|
|
|
|
- */
|
|
|
|
- fun setProgress(@IntRange(from = 0, to = 100) progress: Int, animated: Boolean = true) {
|
|
|
|
- if (progress > 0) {
|
|
|
|
- indicator.setProgressCompat(progress, animated)
|
|
|
|
- } else if (!indicator.isIndeterminate) {
|
|
|
|
- indicator.hide()
|
|
|
|
- indicator.isIndeterminate = true
|
|
|
|
- indicator.show()
|
|
|
|
- }
|
|
|
|
- updateRotateAnimation()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private fun updateRotateAnimation() {
|
|
|
|
- if (isAttachedToWindow && indicator.isShown && !indicator.isIndeterminate) {
|
|
|
|
- if (animation == null) {
|
|
|
|
- startAnimation(rotateAnimation)
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- clearAnimation()
|
|
|
|
- }
|
|
|
|
|
|
+ fun setProgress(@IntRange(from = 0, to = 100) progress: Int) {
|
|
|
|
+ this.progress = progress / 100f
|
|
}
|
|
}
|
|
}
|
|
}
|