Browse Source

ConversationItem: theme unread message bubbles

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 years ago
parent
commit
3283e5b4f6

+ 4 - 15
app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.java

@@ -168,29 +168,18 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
             int lightBubbleTextColor = ContextCompat.getColor(
                 context,
                 R.color.conversation_unread_bubble_text);
-            ColorStateList lightBubbleStrokeColor = ColorStateList.valueOf(
-                ContextCompat.getColor(context,
-                                       R.color.colorPrimary));
 
             if (conversation.getType() == Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL) {
-                holder.binding.dialogUnreadBubble.setChipBackgroundColorResource(R.color.colorPrimary);
-                holder.binding.dialogUnreadBubble.setTextColor(Color.WHITE);
+                viewThemeUtils.colorChipBackground(holder.binding.dialogUnreadBubble);
             } else if (conversation.getUnreadMention()) {
                 if (CapabilitiesUtilNew.hasSpreedFeatureCapability(user, "direct-mention-flag")) {
                     if (conversation.getUnreadMentionDirect()) {
-                        holder.binding.dialogUnreadBubble.setChipBackgroundColorResource(R.color.colorPrimary);
-                        holder.binding.dialogUnreadBubble.setTextColor(Color.WHITE);
+                        viewThemeUtils.colorChipBackground(holder.binding.dialogUnreadBubble);
                     } else {
-                        holder.binding.dialogUnreadBubble.setChipBackgroundColorResource(R.color.bg_default);
-                        holder.binding.dialogUnreadBubble.setTextColor(ContextCompat.getColor(
-                            context,
-                            R.color.colorPrimary));
-                        holder.binding.dialogUnreadBubble.setChipStrokeWidth(6.0f);
-                        holder.binding.dialogUnreadBubble.setChipStrokeColor(lightBubbleStrokeColor);
+                        viewThemeUtils.colorChipOutlined(holder.binding.dialogUnreadBubble, 6.0f);
                     }
                 } else {
-                    holder.binding.dialogUnreadBubble.setChipBackgroundColorResource(R.color.colorPrimary);
-                    holder.binding.dialogUnreadBubble.setTextColor(Color.WHITE);
+                    viewThemeUtils.colorChipBackground(holder.binding.dialogUnreadBubble);
                 }
             } else {
                 holder.binding.dialogUnreadBubble.setChipBackgroundColor(lightBubbleFillColor);

+ 17 - 0
app/src/main/java/com/nextcloud/talk/ui/theme/ViewThemeUtils.kt

@@ -37,6 +37,7 @@ import androidx.core.view.children
 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
 import com.google.android.material.button.MaterialButton
 import com.google.android.material.card.MaterialCardView
+import com.google.android.material.chip.Chip
 import com.google.android.material.floatingactionbutton.FloatingActionButton
 import com.google.android.material.tabs.TabLayout
 import com.google.android.material.textfield.TextInputLayout
@@ -219,6 +220,22 @@ class ViewThemeUtils @Inject constructor(val theme: ServerTheme) {
         return drawable
     }
 
+    fun colorChipBackground(chip: Chip) {
+        withElementColor(chip) { color ->
+            chip.chipBackgroundColor = ColorStateList.valueOf(color)
+            chip.setTextColor(theme.colorText)
+        }
+    }
+
+    fun colorChipOutlined(chip: Chip, strokeWidth: Float) {
+        withElementColor(chip) { color ->
+            chip.chipBackgroundColor = ColorStateList.valueOf(Color.TRANSPARENT)
+            chip.chipStrokeWidth = strokeWidth
+            chip.chipStrokeColor = ColorStateList.valueOf(color)
+            chip.setTextColor(color)
+        }
+    }
+
     companion object {
         private val THEMEABLE_PLACEHOLDER_IDS = listOf(
             R.drawable.ic_mimetype_package_x_generic,