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,8 +189,19 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
showVoiceMessageLoading()
WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id)
.observeForever { info: WorkInfo? ->
if (info != null) {
updateDownloadState(info)
}
}
}
} catch (e: ExecutionException) {
Log.e(TAG, "Error when checking if worker already exists", e)
} catch (e: InterruptedException) {
Log.e(TAG, "Error when checking if worker already exists", e)
}
}
private fun updateDownloadState(info: WorkInfo?) {
if (info != null) {
when (info.state) {
WorkInfo.State.RUNNING -> {
Log.d(TAG, "WorkInfo.State.RUNNING in ViewHolder")
@ -205,18 +216,11 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
showPlayButton()
}
else -> {
Log.d(TAG, "WorkInfo.State unused in ViewHolder")
}
}
}
}
}
}
} catch (e: ExecutionException) {
Log.e(TAG, "Error when checking if worker already exists", e)
} catch (e: InterruptedException) {
Log.e(TAG, "Error when checking if worker already exists", e)
}
}
private fun showPlayButton() {
binding.playPauseBtn.visibility = View.VISIBLE