Code review fixes.

This commit is contained in:
Onuray Sahin 2022-03-22 17:04:35 +03:00
parent 6fef2f6d4e
commit 24bdad3ae1

View file

@ -24,6 +24,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.TextView
import androidx.core.view.doOnLayout
import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
@ -85,12 +86,25 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
holder.progressLayout.isVisible = false
}
holder.voicePlaybackWaveform.doOnLayout {
onWaveformViewReady(holder)
}
val backgroundTint = if (attributes.informationData.messageLayout is TimelineMessageLayout.Bubble) {
Color.TRANSPARENT
} else {
ThemeUtils.getColor(holder.view.context, R.attr.vctr_content_quinary)
}
holder.voicePlaybackLayout.backgroundTintList = ColorStateList.valueOf(backgroundTint)
holder.voicePlaybackControlButton.setOnClickListener { playbackControlButtonClickListener?.invoke(it) }
}
private fun onWaveformViewReady(holder: Holder) {
holder.voicePlaybackWaveform.setOnLongClickListener(attributes.itemLongClickListener)
val waveformColorIdle = ThemeUtils.getColor(holder.view.context, R.attr.vctr_content_quaternary)
val waveformColorPlayed = ThemeUtils.getColor(holder.view.context, R.attr.vctr_content_secondary)
holder.voicePlaybackWaveform.post {
holder.voicePlaybackWaveform.clear()
waveform.forEach { amplitude ->
holder.voicePlaybackWaveform.add(AudioWaveformView.FFT(amplitude.toFloat(), waveformColorIdle))
@ -110,18 +124,7 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
}
true
}
}
val backgroundTint = if (attributes.informationData.messageLayout is TimelineMessageLayout.Bubble) {
Color.TRANSPARENT
} else {
ThemeUtils.getColor(holder.view.context, R.attr.vctr_content_quinary)
}
holder.voicePlaybackLayout.backgroundTintList = ColorStateList.valueOf(backgroundTint)
holder.voicePlaybackControlButton.setOnClickListener { playbackControlButtonClickListener?.invoke(it) }
// Don't track and don't try to update UI before view is present
holder.view.post {
voiceMessagePlaybackTracker.track(attributes.informationData.eventId, object : VoiceMessagePlaybackTracker.Listener {
override fun onUpdate(state: VoiceMessagePlaybackTracker.Listener.State) {
when (state) {
@ -132,7 +135,6 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
}
})
}
}
private fun getTouchedPositionPercentage(motionEvent: MotionEvent, view: View) = (motionEvent.x / view.width).coerceIn(0f, 1f)