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 2eb294bf6..98523ab27 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 @@ -189,25 +189,7 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders showVoiceMessageLoading() WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id) .observeForever { info: WorkInfo? -> - if (info != null) { - - when (info.state) { - WorkInfo.State.RUNNING -> { - Log.d(TAG, "WorkInfo.State.RUNNING in ViewHolder") - showVoiceMessageLoading() - } - WorkInfo.State.SUCCEEDED -> { - Log.d(TAG, "WorkInfo.State.SUCCEEDED in ViewHolder") - showPlayButton() - } - WorkInfo.State.FAILED -> { - Log.d(TAG, "WorkInfo.State.FAILED in ViewHolder") - showPlayButton() - } - else -> { - } - } - } + updateDownloadState(info) } } } @@ -218,6 +200,28 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders } } + private fun updateDownloadState(info: WorkInfo?) { + if (info != null) { + when (info.state) { + WorkInfo.State.RUNNING -> { + Log.d(TAG, "WorkInfo.State.RUNNING in ViewHolder") + showVoiceMessageLoading() + } + WorkInfo.State.SUCCEEDED -> { + Log.d(TAG, "WorkInfo.State.SUCCEEDED in ViewHolder") + showPlayButton() + } + WorkInfo.State.FAILED -> { + Log.d(TAG, "WorkInfo.State.FAILED in ViewHolder") + showPlayButton() + } + else -> { + Log.d(TAG, "WorkInfo.State unused in ViewHolder") + } + } + } + } + private fun showPlayButton() { binding.playPauseBtn.visibility = View.VISIBLE binding.progressBar.visibility = View.GONE