Skip to content

Commit

Permalink
Themed the PlaybackSpeedControl + Work around onBind bug
Browse files Browse the repository at this point in the history
Signed-off-by: rapterjet2004 <[email protected]>
  • Loading branch information
rapterjet2004 committed Nov 27, 2024
1 parent c5c716b commit 0e27404
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -173,6 +160,8 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) :
false,
viewThemeUtils
)

isBound = true
}

private fun longClickOnReaction(chatMessage: ChatMessage) {
Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -162,6 +165,7 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) :
true,
viewThemeUtils
)
isBound = true
}

private fun longClickOnReaction(chatMessage: ChatMessage) {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/nextcloud/talk/ui/PlaybackSpeedControl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0e27404

Please sign in to comment.