diff --git a/src/main/java/eu/siacs/conversations/ui/Activities.java b/src/main/java/eu/siacs/conversations/ui/Activities.java index e0753c0ce..d95d6b4ac 100644 --- a/src/main/java/eu/siacs/conversations/ui/Activities.java +++ b/src/main/java/eu/siacs/conversations/ui/Activities.java @@ -44,4 +44,9 @@ public final class Activities { context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; return nightModeFlags != Configuration.UI_MODE_NIGHT_YES; } + + public static boolean isNightMode(final Context context) { + return (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) + == Configuration.UI_MODE_NIGHT_YES; + } } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index c0f1c3fa6..df45657c7 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -55,6 +55,7 @@ import eu.siacs.conversations.entities.Transferable; import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.services.MessageArchiveService; import eu.siacs.conversations.services.NotificationService; +import eu.siacs.conversations.ui.Activities; import eu.siacs.conversations.ui.ConversationFragment; import eu.siacs.conversations.ui.ConversationsActivity; import eu.siacs.conversations.ui.XmppActivity; @@ -204,7 +205,8 @@ public class MessageAdapter extends ArrayAdapter { error = message.getStatus() == Message.STATUS_SEND_FAILED; } if (type == SENT) { - final @DrawableRes Integer receivedIndicator = getMessageStatusAsDrawable(message, mergedStatus); + final @DrawableRes Integer receivedIndicator = + getMessageStatusAsDrawable(message, mergedStatus); if (receivedIndicator == null) { viewHolder.indicatorReceived.setVisibility(View.INVISIBLE); } else { @@ -291,7 +293,8 @@ public class MessageAdapter extends ArrayAdapter { if (fileSize != null) { timeInfoBuilder.add(fileSize); } - // for space reasons we display only 'additional status info' (send progress or concrete failure reason) or the time + // for space reasons we display only 'additional status info' (send progress or concrete + // failure reason) or the time if (additionalStatusInfo != null) { timeInfoBuilder.add(additionalStatusInfo); } else { @@ -302,16 +305,14 @@ public class MessageAdapter extends ArrayAdapter { viewHolder.time.setText(Joiner.on(" \u00B7 ").join(timeInfo)); } - public static @DrawableRes Integer getMessageStatusAsDrawable(final Message message, final int status) { + public static @DrawableRes Integer getMessageStatusAsDrawable( + final Message message, final int status) { final var transferable = message.getTransferable(); return switch (status) { case Message.STATUS_WAITING -> R.drawable.ic_more_horiz_24dp; - case Message.STATUS_UNSEND -> transferable == null - ? null - : R.drawable.ic_upload_24dp; + case Message.STATUS_UNSEND -> transferable == null ? null : R.drawable.ic_upload_24dp; case Message.STATUS_SEND -> R.drawable.ic_done_24dp; - case Message.STATUS_SEND_RECEIVED, Message.STATUS_SEND_DISPLAYED -> R - .drawable + case Message.STATUS_SEND_RECEIVED, Message.STATUS_SEND_DISPLAYED -> R.drawable .ic_done_all_24dp; case Message.STATUS_SEND_FAILED -> { final String errorMessage = message.getErrorMessage(); @@ -812,7 +813,7 @@ public class MessageAdapter extends ArrayAdapter { bubbleColor = BubbleColor.WARNING; } } else { - bubbleColor = colorfulBackground ? BubbleColor.TERTIARY : BubbleColor.SURFACE; + bubbleColor = colorfulBackground ? BubbleColor.TERTIARY : BubbleColor.SURFACE_HIGH; } if (type == DATE_SEPARATOR) { @@ -831,8 +832,8 @@ public class MessageAdapter extends ArrayAdapter { setBackgroundTint(viewHolder.message_box, BubbleColor.PRIMARY); setTextColor(viewHolder.status_message, BubbleColor.PRIMARY); } else { - setBackgroundTint(viewHolder.message_box, BubbleColor.SURFACE); - setTextColor(viewHolder.status_message, BubbleColor.SURFACE); + setBackgroundTint(viewHolder.message_box, BubbleColor.SURFACE_HIGH); + setTextColor(viewHolder.status_message, BubbleColor.SURFACE_HIGH); } return view; } else if (type == RTP_SESSION) { @@ -877,9 +878,9 @@ public class MessageAdapter extends ArrayAdapter { setTextColor(viewHolder.status_message, BubbleColor.SECONDARY); setImageTint(viewHolder.indicatorReceived, BubbleColor.SECONDARY); } else { - setBackgroundTint(viewHolder.message_box, BubbleColor.SURFACE); - setTextColor(viewHolder.status_message, BubbleColor.SURFACE); - setImageTint(viewHolder.indicatorReceived, BubbleColor.SURFACE); + setBackgroundTint(viewHolder.message_box, BubbleColor.SURFACE_HIGH); + setTextColor(viewHolder.status_message, BubbleColor.SURFACE_HIGH); + setImageTint(viewHolder.indicatorReceived, BubbleColor.SURFACE_HIGH); } viewHolder.indicatorReceived.setImageResource( RtpSessionStatus.getDrawable(received, rtpSessionStatus.successful)); @@ -1141,7 +1142,12 @@ public class MessageAdapter extends ArrayAdapter { final View view, final BubbleColor bubbleColor) { final @AttrRes int colorAttributeResId = switch (bubbleColor) { - case SURFACE -> com.google.android.material.R.attr.colorSurfaceContainerHigh; + case SURFACE -> Activities.isNightMode(view.getContext()) + ? com.google.android.material.R.attr.colorSurfaceContainerHigh + : com.google.android.material.R.attr.colorSurfaceContainerLow; + case SURFACE_HIGH -> Activities.isNightMode(view.getContext()) + ? com.google.android.material.R.attr.colorSurfaceContainerHighest + : com.google.android.material.R.attr.colorSurfaceContainerHigh; case PRIMARY -> com.google.android.material.R.attr.colorPrimaryContainer; case SECONDARY -> com.google.android.material.R.attr.colorSecondaryContainer; case TERTIARY -> com.google.android.material.R.attr.colorTertiaryContainer; @@ -1170,7 +1176,7 @@ public class MessageAdapter extends ArrayAdapter { private static @ColorInt int bubbleToOnSurfaceVariant( final View view, final BubbleColor bubbleColor) { final @AttrRes int colorAttributeResId; - if (bubbleColor == BubbleColor.SURFACE) { + if (bubbleColor == BubbleColor.SURFACE_HIGH || bubbleColor == BubbleColor.SURFACE) { colorAttributeResId = com.google.android.material.R.attr.colorOnSurfaceVariant; } else { colorAttributeResId = bubbleToOnSurface(bubbleColor); @@ -1190,7 +1196,7 @@ public class MessageAdapter extends ArrayAdapter { private static @AttrRes int bubbleToOnSurface(final BubbleColor bubbleColor) { return switch (bubbleColor) { - case SURFACE -> com.google.android.material.R.attr.colorOnSurface; + case SURFACE, SURFACE_HIGH -> com.google.android.material.R.attr.colorOnSurface; case PRIMARY -> com.google.android.material.R.attr.colorOnPrimaryContainer; case SECONDARY -> com.google.android.material.R.attr.colorOnSecondaryContainer; case TERTIARY -> com.google.android.material.R.attr.colorOnTertiaryContainer; @@ -1200,6 +1206,7 @@ public class MessageAdapter extends ArrayAdapter { public enum BubbleColor { SURFACE, + SURFACE_HIGH, PRIMARY, SECONDARY, TERTIARY,