mirror of
https://github.com/oxen-io/session-android.git
synced 2025-05-03 16:01:12 +00:00
feat: new ThumbnailProgressBar.kt for animating the loading progress
This commit is contained in:
parent
2e48e5f93e
commit
a91cd45b89
@ -42,7 +42,7 @@ open class KThumbnailView: FrameLayout {
|
|||||||
private val image by lazy { thumbnail_image }
|
private val image by lazy { thumbnail_image }
|
||||||
private val playOverlay by lazy { play_overlay }
|
private val playOverlay by lazy { play_overlay }
|
||||||
private val captionIcon by lazy { thumbnail_caption_icon }
|
private val captionIcon by lazy { thumbnail_caption_icon }
|
||||||
val loadIndicator: ProgressBar by lazy { thumbnail_load_indicator }
|
val loadIndicator: View by lazy { thumbnail_load_indicator }
|
||||||
private val transferControls by lazy { ViewUtil.inflateStub<TransferControlView>(this, R.id.transfer_controls_stub) }
|
private val transferControls by lazy { ViewUtil.inflateStub<TransferControlView>(this, R.id.transfer_controls_stub) }
|
||||||
|
|
||||||
private val dimensDelegate = ThumbnailDimensDelegate()
|
private val dimensDelegate = ThumbnailDimensDelegate()
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
package org.thoughtcrime.securesms.conversation.v2.utilities
|
||||||
|
|
||||||
|
import android.animation.ValueAnimator
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Interpolator
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.graphics.Rect
|
||||||
|
import android.os.SystemClock
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.util.Log
|
||||||
|
import android.view.View
|
||||||
|
import android.view.animation.AccelerateDecelerateInterpolator
|
||||||
|
import android.view.animation.Animation
|
||||||
|
import android.view.animation.AnimationSet
|
||||||
|
import android.view.animation.AnimationUtils
|
||||||
|
import androidx.core.content.res.ResourcesCompat
|
||||||
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
|
import network.loki.messenger.R
|
||||||
|
import kotlin.math.sin
|
||||||
|
|
||||||
|
class ThumbnailProgressBar: View, ValueAnimator.AnimatorUpdateListener {
|
||||||
|
|
||||||
|
constructor(context: Context) : super(context)
|
||||||
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
||||||
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
|
||||||
|
|
||||||
|
private val firstX: Double
|
||||||
|
get() = sin(SystemClock.elapsedRealtime() / 300.0) * 1.5
|
||||||
|
|
||||||
|
private val secondX: Double
|
||||||
|
get() = sin(SystemClock.elapsedRealtime() / 300.0 + (Math.PI/4)) * 1.5
|
||||||
|
|
||||||
|
private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||||
|
style = Paint.Style.FILL
|
||||||
|
color = ResourcesCompat.getColor(resources, R.color.accent, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val objectRect = Rect()
|
||||||
|
private val drawingRect = Rect()
|
||||||
|
|
||||||
|
override fun onAnimationUpdate(animation: ValueAnimator?) {
|
||||||
|
if (animation == null || !isAttachedToWindow) return
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dispatchDraw(canvas: Canvas?) {
|
||||||
|
if (canvas == null) return
|
||||||
|
|
||||||
|
getDrawingRect(objectRect)
|
||||||
|
drawingRect.set(objectRect)
|
||||||
|
|
||||||
|
val coercedFX = firstX
|
||||||
|
val coercedSX = secondX
|
||||||
|
|
||||||
|
val firstMeasuredX = objectRect.left + (objectRect.width() * coercedFX)
|
||||||
|
val secondMeasuredX = objectRect.left + (objectRect.width() * coercedSX)
|
||||||
|
|
||||||
|
drawingRect.set(
|
||||||
|
(if (firstMeasuredX < secondMeasuredX) firstMeasuredX else secondMeasuredX).toInt(),
|
||||||
|
objectRect.top,
|
||||||
|
(if (firstMeasuredX < secondMeasuredX) secondMeasuredX else firstMeasuredX).toInt(),
|
||||||
|
objectRect.bottom
|
||||||
|
)
|
||||||
|
|
||||||
|
canvas.drawRect(drawingRect, paint)
|
||||||
|
invalidate()
|
||||||
|
}
|
||||||
|
}
|
@ -35,7 +35,7 @@
|
|||||||
/>
|
/>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/albumCellBodyTextParent"
|
android:id="@+id/albumCellBodyTextParent"
|
||||||
android:padding="@dimen/small_spacing"
|
android:paddingHorizontal="@dimen/small_spacing"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/albumCellBodyTextReadMore"
|
app:layout_constraintBottom_toTopOf="@+id/albumCellBodyTextReadMore"
|
||||||
|
@ -22,14 +22,11 @@
|
|||||||
android:src="@drawable/ic_caption_28"
|
android:src="@drawable/ic_caption_28"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<ProgressBar
|
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailProgressBar
|
||||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
|
||||||
android:id="@+id/thumbnail_load_indicator"
|
android:id="@+id/thumbnail_load_indicator"
|
||||||
android:progressTint="@color/accent"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="@dimen/accent_line_thickness"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
android:indeterminate="true"
|
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user