extract method to reduce complexity

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-04-19 18:14:18 +02:00
parent c93041d402
commit 300e7da172
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B

View file

@ -189,25 +189,7 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
showVoiceMessageLoading() showVoiceMessageLoading()
WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id) WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id)
.observeForever { info: WorkInfo? -> .observeForever { info: WorkInfo? ->
if (info != null) { updateDownloadState(info)
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 -> {
}
}
}
} }
} }
} }
@ -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() { private fun showPlayButton() {
binding.playPauseBtn.visibility = View.VISIBLE binding.playPauseBtn.visibility = View.VISIBLE
binding.progressBar.visibility = View.GONE binding.progressBar.visibility = View.GONE