From 0e274043934ac385961d80300352b5038aa0c8d7 Mon Sep 17 00:00:00 2001 From: rapterjet2004 Date: Wed, 27 Nov 2024 13:24:34 -0600 Subject: [PATCH] Themed the PlaybackSpeedControl + Work around onBind bug Signed-off-by: rapterjet2004 --- .../IncomingVoiceMessageViewHolder.kt | 50 ++++++++++++------- .../OutcomingVoiceMessageViewHolder.kt | 11 ++-- .../nextcloud/talk/ui/PlaybackSpeedControl.kt | 10 ++++ 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt index acdc894477..91ee660fca 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt @@ -70,10 +70,16 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : lateinit var voiceMessageInterface: VoiceMessageInterface lateinit var commonMessageInterface: CommonMessageInterface + private var isBound = false @SuppressLint("SetTextI18n") override fun onBind(message: ChatMessage) { super.onBind(message) + if (isBound) { + handleIsPlayingVoiceMessageState(message) + return + } + this.message = message sharedApplication!!.componentApplication.inject(this) @@ -102,25 +108,6 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : viewThemeUtils.talk.themeWaveFormSeekBar(binding.seekbar) viewThemeUtils.platform.colorCircularProgressBar(binding.progressBar, ColorRole.ON_SURFACE_VARIANT) - if (message.isPlayingVoiceMessage) { - showPlayButton() - binding.playPauseBtn.icon = ContextCompat.getDrawable( - context!!, - R.drawable.ic_baseline_pause_voice_message_24 - ) - val d = message.voiceMessageDuration.toLong() - val t = message.voiceMessagePlayedSeconds.toLong() - binding.voiceMessageDuration.text = android.text.format.DateUtils.formatElapsedTime(d - t) - binding.voiceMessageDuration.visibility = View.VISIBLE - binding.seekbar.progress = message.voiceMessageSeekbarProgress - } else { - binding.playPauseBtn.visibility = View.VISIBLE - binding.playPauseBtn.icon = ContextCompat.getDrawable( - context!!, - R.drawable.ic_baseline_play_arrow_voice_message_24 - ) - } - if (message.isDownloadingVoiceMessage) { showVoiceMessageLoading() } else { @@ -173,6 +160,8 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : false, viewThemeUtils ) + + isBound = true } private fun longClickOnReaction(chatMessage: ChatMessage) { @@ -183,6 +172,29 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : commonMessageInterface.onClickReaction(chatMessage, emoji) } + private fun handleIsPlayingVoiceMessageState(message: ChatMessage) { + if (message.isPlayingVoiceMessage) { + showPlayButton() + binding.playPauseBtn.icon = ContextCompat.getDrawable( + context!!, + R.drawable.ic_baseline_pause_voice_message_24 + ) + + val d = message.voiceMessageDuration.toLong() + val t = message.voiceMessagePlayedSeconds.toLong() + binding.voiceMessageDuration.text = android.text.format.DateUtils.formatElapsedTime(d - t) + binding.voiceMessageDuration.visibility = View.VISIBLE + binding.seekbar.max = message.voiceMessageDuration * ONE_SEC + binding.seekbar.progress = message.voiceMessageSeekbarProgress + } else { + binding.playPauseBtn.visibility = View.VISIBLE + binding.playPauseBtn.icon = ContextCompat.getDrawable( + context!!, + R.drawable.ic_baseline_play_arrow_voice_message_24 + ) + } + } + private fun updateDownloadState(message: ChatMessage) { // check if download worker is already running val fileId = message.selectedIndividualHashMap!!["id"] diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingVoiceMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingVoiceMessageViewHolder.kt index 48bc28bdee..b9cd436298 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingVoiceMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingVoiceMessageViewHolder.kt @@ -74,10 +74,16 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : lateinit var voiceMessageInterface: VoiceMessageInterface lateinit var commonMessageInterface: CommonMessageInterface + private var isBound = false @SuppressLint("SetTextI18n") override fun onBind(message: ChatMessage) { super.onBind(message) + if (isBound) { + handleIsPlayingVoiceMessageState(message) + return + } + this.message = message sharedApplication!!.componentApplication.inject(this) viewThemeUtils.platform.colorTextView(binding.messageTime, ColorRole.ON_SURFACE_VARIANT) @@ -102,12 +108,9 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : setParentMessageDataOnMessageItem(message) updateDownloadState(message) - binding.seekbar.max = message.voiceMessageDuration * ONE_SEC viewThemeUtils.talk.themeWaveFormSeekBar(binding.seekbar) viewThemeUtils.platform.colorCircularProgressBar(binding.progressBar, ColorRole.ON_SURFACE_VARIANT) - handleIsPlayingVoiceMessageState(message) - handleIsDownloadingVoiceMessageState(message) handleResetVoiceMessageState(message) @@ -162,6 +165,7 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : true, viewThemeUtils ) + isBound = true } private fun longClickOnReaction(chatMessage: ChatMessage) { @@ -211,6 +215,7 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : val t = message.voiceMessagePlayedSeconds.toLong() binding.voiceMessageDuration.text = android.text.format.DateUtils.formatElapsedTime(d - t) binding.voiceMessageDuration.visibility = View.VISIBLE + binding.seekbar.max = message.voiceMessageDuration * ONE_SEC binding.seekbar.progress = message.voiceMessageSeekbarProgress } else { binding.playPauseBtn.visibility = View.VISIBLE diff --git a/app/src/main/java/com/nextcloud/talk/ui/PlaybackSpeedControl.kt b/app/src/main/java/com/nextcloud/talk/ui/PlaybackSpeedControl.kt index 82b9f4f08b..4c4b61877e 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/PlaybackSpeedControl.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/PlaybackSpeedControl.kt @@ -9,23 +9,33 @@ package com.nextcloud.talk.ui import android.content.Context import android.util.AttributeSet +import autodagger.AutoInjector import com.google.android.material.button.MaterialButton +import com.nextcloud.talk.application.NextcloudTalkApplication +import com.nextcloud.talk.ui.theme.ViewThemeUtils +import javax.inject.Inject internal const val SPEED_FACTOR_SLOW = 0.8f internal const val SPEED_FACTOR_NORMAL = 1.0f internal const val SPEED_FACTOR_FASTER = 1.5f internal const val SPEED_FACTOR_FASTEST = 2.0f +@AutoInjector(NextcloudTalkApplication::class) class PlaybackSpeedControl @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : MaterialButton(context, attrs, defStyleAttr) { + @Inject + lateinit var viewThemeUtils: ViewThemeUtils + private var currentSpeed = PlaybackSpeed.NORMAL init { + NextcloudTalkApplication.sharedApplication?.componentApplication?.inject(this) text = currentSpeed.label + viewThemeUtils.material.colorMaterialButtonText(this) } fun setSpeed(newSpeed: PlaybackSpeed) {