New design for audio view progress bar.

This commit is contained in:
Anton Chekulaev 2020-10-26 23:14:26 +11:00
parent 82c5df48e7
commit 42b9468c63
3 changed files with 39 additions and 25 deletions

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/circle_tintable"
android:inset="4dp"/>

View File

@ -15,25 +15,28 @@
<org.thoughtcrime.securesms.components.AnimatingToggle
android:id="@+id/control_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:gravity="center">
<com.pnikosis.materialishprogress.ProgressWheel
<ProgressBar
android:id="@+id/download_progress"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:background="@drawable/circle_tintable_4dp_inset"
android:visibility="gone"
android:layout_gravity="center"
app:matProg_barColor="@color/white"
app:matProg_linearProgress="true"
app:matProg_spinSpeed="0.333"
tools:visibility="gone"/>
android:layout_gravity="center_vertical"
android:min="0"
android:max="100"
tools:visibility="gone"
tools:backgroundTint="@android:color/black"
tools:indeterminateTint="@android:color/white"/>
<ImageView android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:clickable="true"
@ -45,8 +48,8 @@
tools:visibility="visible"/>
<ImageView android:id="@+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:clickable="true"
@ -58,8 +61,8 @@
tools:visibility="gone"/>
<ImageView android:id="@+id/download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:clickable="true"
android:visibility="gone"

View File

@ -11,11 +11,11 @@ import android.view.View.OnTouchListener
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import com.pnikosis.materialishprogress.ProgressWheel
import kotlinx.coroutines.*
import network.loki.messenger.R
import org.greenrobot.eventbus.EventBus
@ -47,7 +47,7 @@ class MessageAudioView: FrameLayout, AudioSlidePlayer.Listener {
private val playButton: ImageView
private val pauseButton: ImageView
private val downloadButton: ImageView
private val downloadProgress: ProgressWheel
private val downloadProgress: ProgressBar
private val seekBar: WaveformSeekBar
private val totalDuration: TextView
@ -147,20 +147,22 @@ class MessageAudioView: FrameLayout, AudioSlidePlayer.Listener {
controlToggle.displayQuick(downloadButton)
seekBar.isEnabled = false
downloadButton.setOnClickListener { v -> downloadListener?.onClick(v, audio) }
if (downloadProgress.isSpinning) {
downloadProgress.stopSpinning()
if (downloadProgress.isIndeterminate) {
downloadProgress.isIndeterminate = false
downloadProgress.progress = 0
}
}
(showControls && audio.transferState == AttachmentDatabase.TRANSFER_PROGRESS_STARTED) -> {
controlToggle.displayQuick(downloadProgress)
seekBar.isEnabled = false
downloadProgress.spin()
downloadProgress.isIndeterminate = true
}
else -> {
controlToggle.displayQuick(playButton)
seekBar.isEnabled = true
if (downloadProgress.isSpinning) {
downloadProgress.stopSpinning()
if (downloadProgress.isIndeterminate) {
downloadProgress.isIndeterminate = false
downloadProgress.progress = 100
}
// Post to make sure it executes only when the view is attached to a window.
@ -187,7 +189,11 @@ class MessageAudioView: FrameLayout, AudioSlidePlayer.Listener {
pauseButton.imageTintList = ColorStateList.valueOf(backgroundTint)
downloadButton.setColorFilter(foregroundTint, PorterDuff.Mode.SRC_IN)
downloadProgress.barColor = foregroundTint
downloadProgress.backgroundTintList = ColorStateList.valueOf(foregroundTint)
downloadProgress.progressTintList = ColorStateList.valueOf(backgroundTint)
downloadProgress.indeterminateTintList = ColorStateList.valueOf(backgroundTint)
totalDuration.setTextColor(foregroundTint)
// Seek bar's progress color is set from the XML template. Whereas the background is computed.
@ -284,7 +290,8 @@ class MessageAudioView: FrameLayout, AudioSlidePlayer.Listener {
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
fun onEvent(event: PartProgressEvent) {
if (audioSlidePlayer != null && event.attachment == audioSlidePlayer!!.audioSlide.asAttachment()) {
downloadProgress.setInstantProgress(event.progress.toFloat() / event.total)
val progress = ((event.progress.toFloat() / event.total) * 100f).toInt()
downloadProgress.progress = progress
}
}