浏览代码

extract visibility toggle for play/pause Vs. loading-animation

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger 4 年之前
父节点
当前提交
195bdfb05a

+ 16 - 12
app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt

@@ -95,8 +95,7 @@ class IncomingVoiceMessageViewHolder(incomingView: View) : MessageHolders
         binding.seekbar.max = message.voiceMessageDuration
         binding.seekbar.max = message.voiceMessageDuration
 
 
         if (message.isPlayingVoiceMessage) {
         if (message.isPlayingVoiceMessage) {
-            binding.progressBar.visibility = View.GONE
-            binding.playPauseBtn.visibility = View.VISIBLE
+            showPlayButton()
             binding.playPauseBtn.icon = ContextCompat.getDrawable(
             binding.playPauseBtn.icon = ContextCompat.getDrawable(
                 context!!,
                 context!!,
                 R.drawable.ic_baseline_pause_voice_message_24
                 R.drawable.ic_baseline_pause_voice_message_24
@@ -111,8 +110,7 @@ class IncomingVoiceMessageViewHolder(incomingView: View) : MessageHolders
         }
         }
 
 
         if (message.isDownloadingVoiceMessage) {
         if (message.isDownloadingVoiceMessage) {
-            binding.playPauseBtn.visibility = View.GONE
-            binding.progressBar.visibility = View.VISIBLE
+            showVoiceMessageLoading()
         } else {
         } else {
             binding.progressBar.visibility = View.GONE
             binding.progressBar.visibility = View.GONE
         }
         }
@@ -152,26 +150,22 @@ class IncomingVoiceMessageViewHolder(incomingView: View) : MessageHolders
         try {
         try {
             for (workInfo in workers.get()) {
             for (workInfo in workers.get()) {
                 if (workInfo.state == WorkInfo.State.RUNNING || workInfo.state == WorkInfo.State.ENQUEUED) {
                 if (workInfo.state == WorkInfo.State.RUNNING || workInfo.state == WorkInfo.State.ENQUEUED) {
-                    binding.progressBar.visibility = View.VISIBLE
-                    binding.playPauseBtn.visibility = View.GONE
+                    showVoiceMessageLoading()
                     WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id)
                     WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id)
                         .observeForever { info: WorkInfo? ->
                         .observeForever { info: WorkInfo? ->
                             if (info != null) {
                             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")
-                                        binding.playPauseBtn.visibility = View.GONE
-                                        binding.progressBar.visibility = View.VISIBLE
+                                        showVoiceMessageLoading()
                                     }
                                     }
                                     WorkInfo.State.SUCCEEDED -> {
                                     WorkInfo.State.SUCCEEDED -> {
                                         Log.d(TAG, "WorkInfo.State.SUCCEEDED in ViewHolder")
                                         Log.d(TAG, "WorkInfo.State.SUCCEEDED in ViewHolder")
-                                        binding.playPauseBtn.visibility = View.VISIBLE
-                                        binding.progressBar.visibility = View.GONE
+                                        showPlayButton()
                                     }
                                     }
                                     WorkInfo.State.FAILED -> {
                                     WorkInfo.State.FAILED -> {
                                         Log.d(TAG, "WorkInfo.State.FAILED in ViewHolder")
                                         Log.d(TAG, "WorkInfo.State.FAILED in ViewHolder")
-                                        binding.playPauseBtn.visibility = View.VISIBLE
-                                        binding.progressBar.visibility = View.GONE
+                                        showPlayButton()
                                     }
                                     }
                                     else -> {
                                     else -> {
                                     }
                                     }
@@ -187,6 +181,16 @@ class IncomingVoiceMessageViewHolder(incomingView: View) : MessageHolders
         }
         }
     }
     }
 
 
+    private fun showPlayButton() {
+        binding.playPauseBtn.visibility = View.VISIBLE
+        binding.progressBar.visibility = View.GONE
+    }
+
+    private fun showVoiceMessageLoading() {
+        binding.playPauseBtn.visibility = View.GONE
+        binding.progressBar.visibility = View.VISIBLE
+    }
+
     private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) {
     private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) {
         val author: String = message.actorDisplayName
         val author: String = message.actorDisplayName
         if (!TextUtils.isEmpty(author)) {
         if (!TextUtils.isEmpty(author)) {

+ 16 - 12
app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingVoiceMessageViewHolder.kt

@@ -94,8 +94,7 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
         binding.seekbar.max = message.voiceMessageDuration
         binding.seekbar.max = message.voiceMessageDuration
 
 
         if (message.isPlayingVoiceMessage) {
         if (message.isPlayingVoiceMessage) {
-            binding.progressBar.visibility = View.GONE
-            binding.playPauseBtn.visibility = View.VISIBLE
+            showPlayButton()
             binding.playPauseBtn.icon = ContextCompat.getDrawable(
             binding.playPauseBtn.icon = ContextCompat.getDrawable(
                 context!!,
                 context!!,
                 R.drawable.ic_baseline_pause_voice_message_24
                 R.drawable.ic_baseline_pause_voice_message_24
@@ -110,8 +109,7 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
         }
         }
 
 
         if (message.isDownloadingVoiceMessage) {
         if (message.isDownloadingVoiceMessage) {
-            binding.playPauseBtn.visibility = View.GONE
-            binding.progressBar.visibility = View.VISIBLE
+            showVoiceMessageLoading()
         } else {
         } else {
             binding.progressBar.visibility = View.GONE
             binding.progressBar.visibility = View.GONE
         }
         }
@@ -172,8 +170,7 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
         try {
         try {
             for (workInfo in workers.get()) {
             for (workInfo in workers.get()) {
                 if (workInfo.state == WorkInfo.State.RUNNING || workInfo.state == WorkInfo.State.ENQUEUED) {
                 if (workInfo.state == WorkInfo.State.RUNNING || workInfo.state == WorkInfo.State.ENQUEUED) {
-                    binding.progressBar.visibility = View.VISIBLE
-                    binding.playPauseBtn.visibility = View.GONE
+                    showVoiceMessageLoading()
                     WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id)
                     WorkManager.getInstance(context!!).getWorkInfoByIdLiveData(workInfo.id)
                         .observeForever { info: WorkInfo? ->
                         .observeForever { info: WorkInfo? ->
                             if (info != null) {
                             if (info != null) {
@@ -181,18 +178,15 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
                                 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")
-                                        binding.playPauseBtn.visibility = View.GONE
-                                        binding.progressBar.visibility = View.VISIBLE
+                                        showVoiceMessageLoading()
                                     }
                                     }
                                     WorkInfo.State.SUCCEEDED -> {
                                     WorkInfo.State.SUCCEEDED -> {
                                         Log.d(TAG, "WorkInfo.State.SUCCEEDED in ViewHolder")
                                         Log.d(TAG, "WorkInfo.State.SUCCEEDED in ViewHolder")
-                                        binding.playPauseBtn.visibility = View.VISIBLE
-                                        binding.progressBar.visibility = View.GONE
+                                        showPlayButton()
                                     }
                                     }
                                     WorkInfo.State.FAILED -> {
                                     WorkInfo.State.FAILED -> {
                                         Log.d(TAG, "WorkInfo.State.FAILED in ViewHolder")
                                         Log.d(TAG, "WorkInfo.State.FAILED in ViewHolder")
-                                        binding.playPauseBtn.visibility = View.VISIBLE
-                                        binding.progressBar.visibility = View.GONE
+                                        showPlayButton()
                                     }
                                     }
                                     else -> {
                                     else -> {
                                     }
                                     }
@@ -208,6 +202,16 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
         }
         }
     }
     }
 
 
+    private fun showPlayButton() {
+        binding.playPauseBtn.visibility = View.VISIBLE
+        binding.progressBar.visibility = View.GONE
+    }
+
+    private fun showVoiceMessageLoading() {
+        binding.playPauseBtn.visibility = View.GONE
+        binding.progressBar.visibility = View.VISIBLE
+    }
+
     private fun setParentMessageDataOnMessageItem(message: ChatMessage) {
     private fun setParentMessageDataOnMessageItem(message: ChatMessage) {
         if (!message.isDeleted && message.parentMessage != null) {
         if (!message.isDeleted && message.parentMessage != null) {
             val parentChatMessage = message.parentMessage
             val parentChatMessage = message.parentMessage