Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 0f7aef1

Browse files
committed
Change colors in RecyclerMessageAdapter
1 parent 2ea0228 commit 0f7aef1

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

app/src/main/java/com/zulip/android/activities/RecyclerMessageAdapter.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.support.annotation.ColorInt;
99
import android.support.v4.content.ContextCompat;
1010
import android.support.v4.view.ViewCompat;
11+
import android.support.v7.app.AppCompatDelegate;
1112
import android.support.v7.widget.RecyclerView;
1213
import android.util.Log;
1314
import android.text.format.DateUtils;
@@ -56,12 +57,17 @@ public class RecyclerMessageAdapter extends RecyclerView.Adapter<RecyclerView.Vi
5657
int mDefaultStreamHeaderColor;
5758

5859
@ColorInt
59-
private int mDefaultPrivateMessageColor;
60+
private int streamMessageBackground;
61+
62+
@ColorInt
63+
private int privateMessageBackground;
6064
private OnItemClickListener onItemClickListener;
6165
private int contextMenuItemSelectedPosition;
6266
private View footerView;
6367
private View headerView;
6468

69+
private boolean isCurrentThemeNight;
70+
6571
int getContextMenuItemSelectedPosition() {
6672
return contextMenuItemSelectedPosition;
6773
}
@@ -73,8 +79,11 @@ int getContextMenuItemSelectedPosition() {
7379
this.context = context;
7480
narrowListener = (NarrowListener) context;
7581
this.startedFromFilter = startedFromFilter;
82+
isCurrentThemeNight = (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES);
7683
mDefaultStreamHeaderColor = ContextCompat.getColor(context, R.color.stream_header);
77-
mDefaultPrivateMessageColor = ContextCompat.getColor(context, R.color.huddle_body);
84+
privateMessageBackground = ContextCompat.getColor(context, R.color.private_background);
85+
streamMessageBackground = ContextCompat.getColor(context, R.color.stream_background);
86+
7887
privateHuddleText = context.getResources().getString(R.string.huddle_text);
7988
setupHeaderAndFooterViews();
8089
onItemClickListener = new OnItemClickListener() {
@@ -183,7 +192,7 @@ else if (getItem(position) instanceof Integer && (Integer) getItem(position) ==
183192
return VIEWTYPE_FOOTER;
184193
else {
185194
Log.e("ItemError", "object: " + items.get(position).toString());
186-
throw new RuntimeException("MESSAGE TYPE NOT KNOWN & Position:"+position);
195+
throw new RuntimeException("MESSAGE TYPE NOT KNOWN & Position:" + position);
187196
}
188197
}
189198

@@ -254,6 +263,9 @@ public RecyclerView.ViewHolder onCreateViewHolder(final ViewGroup parent, int vi
254263
View messageView = LayoutInflater.from(parent.getContext()).inflate(R.layout.message_tile, parent, false);
255264
MessageHolder messageHolder = new MessageHolder(messageView);
256265
messageHolder.setItemClickListener(onItemClickListener);
266+
if (isCurrentThemeNight) {
267+
messageHolder.leftBar.setVisibility(View.GONE);
268+
}
257269
return messageHolder;
258270
case VIEWTYPE_FOOTER:
259271
footerView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_loading, parent, false);
@@ -278,7 +290,10 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
278290
messageHeaderHolder.streamTextView.setText(messageHeaderParent.getStream());
279291
messageHeaderHolder.topicTextView.setText(messageHeaderParent.getSubject());
280292

281-
ViewCompat.setBackgroundTintList(messageHeaderHolder.arrowHead, ColorStateList.valueOf(messageHeaderParent.getColor()));
293+
if (!isCurrentThemeNight) {
294+
messageHeaderHolder.streamTextView.setBackgroundColor(messageHeaderParent.getColor());
295+
ViewCompat.setBackgroundTintList(messageHeaderHolder.arrowHead, ColorStateList.valueOf(messageHeaderParent.getColor()));
296+
}
282297
messageHeaderHolder.streamTextView.setBackgroundColor(messageHeaderParent.getColor());
283298

284299
if (messageHeaderParent.isMute()) {
@@ -301,12 +316,14 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
301316

302317
if (message.getType() == MessageType.STREAM_MESSAGE) {
303318
messageHolder.senderName.setText(message.getSender().getName());
304-
messageHolder.leftBar.setBackgroundColor(message.getStream().getColor());
305-
messageHolder.messageTile.setBackgroundColor(Color.WHITE);
319+
if (!isCurrentThemeNight)
320+
messageHolder.leftBar.setBackgroundColor(message.getStream().getColor());
321+
messageHolder.messageTile.setBackgroundColor(streamMessageBackground);
306322
} else {
307323
messageHolder.senderName.setText(message.getSender().getName());
308-
messageHolder.leftBar.setBackgroundColor(mDefaultPrivateMessageColor);
309-
messageHolder.messageTile.setBackgroundColor(mDefaultPrivateMessageColor);
324+
if (!isCurrentThemeNight)
325+
messageHolder.leftBar.setBackgroundColor(privateMessageBackground);
326+
messageHolder.messageTile.setBackgroundColor(privateMessageBackground);
310327
}
311328

312329
setUpGravatar(message, messageHolder);

0 commit comments

Comments
 (0)