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() showVoiceMessageLoading()
WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id) WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id)
.observeForever { info: WorkInfo? -> .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) { when (info.state) {
WorkInfo.State.RUNNING -> { WorkInfo.State.RUNNING -> {
Log.d(TAG, "WorkInfo.State.RUNNING in ViewHolder") Log.d(TAG, "WorkInfo.State.RUNNING in ViewHolder")
@ -205,18 +216,11 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
showPlayButton() showPlayButton()
} }
else -> { 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() { private fun showPlayButton() {
binding.playPauseBtn.visibility = View.VISIBLE binding.playPauseBtn.visibility = View.VISIBLE