From 3ef4b90a63a55e712babecf1ad9ac8972a255a91 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 6 Jul 2020 17:18:42 +0800 Subject: Set color of received and sent messages, and send message button. --- .../Activity/ViewPrivateMessagesActivity.java | 7 +++--- .../PrivateMessagesDetailRecyclerViewAdapter.java | 25 ++++++++++++++++------ .../infinityforreddit/Utils/Utils.java | 15 +++++++++++++ .../main/res/drawable/private_message_ballon.xml | 7 ++++++ .../drawable/private_message_ballon_received.xml | 11 ---------- .../res/drawable/private_message_ballon_sent.xml | 11 ---------- 6 files changed, 44 insertions(+), 32 deletions(-) create mode 100644 app/src/main/res/drawable/private_message_ballon.xml delete mode 100644 app/src/main/res/drawable/private_message_ballon_received.xml delete mode 100644 app/src/main/res/drawable/private_message_ballon_sent.xml diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java index e78cdc47..3f8835e9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPrivateMessagesActivity.java @@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.view.MenuItem; @@ -40,10 +39,10 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.Event.RepliedToPrivateMessageEvent; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Message.Message; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Message.ReadMessage; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Message.ReplyMessage; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import retrofit2.Retrofit; @@ -294,7 +293,7 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit mEditText.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); mEditText.setHintTextColor(mCustomThemeWrapper.getSecondaryTextColor()); mEditTextLinearLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - mSendImageView.setColorFilter(Color.parseColor("#4185F4"), android.graphics.PorterDuff.Mode.SRC_IN); + mSendImageView.setColorFilter(mCustomThemeWrapper.getSendMessageIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PrivateMessagesDetailRecyclerViewAdapter.java index 1d8abf5c..572db144 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PrivateMessagesDetailRecyclerViewAdapter.java @@ -51,9 +51,11 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt private Markwon mMarkwon; private boolean mShowElapsedTime; private String mTimeFormatPattern; - private int mMessageBackgroundColor; private int mSecondaryTextColor; - private int mUnreadMessageBackgroundColor; + private int mReceivedMessageTextColor; + private int mSentMessageTextColor; + private int mReceivedMessageBackgroundColor; + private int mSentMessageBackgroundColor; public PrivateMessagesDetailRecyclerViewAdapter(ViewPrivateMessagesActivity viewPrivateMessagesActivity, SharedPreferences sharedPreferences, Locale locale, @@ -96,9 +98,11 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt .build(); mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE); - mMessageBackgroundColor = customThemeWrapper.getCardViewBackgroundColor(); mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor(); - mUnreadMessageBackgroundColor = customThemeWrapper.getUnreadMessageBackgroundColor(); + mReceivedMessageTextColor = customThemeWrapper.getReceivedMessageTextColor(); + mSentMessageTextColor = customThemeWrapper.getSentMessageTextColor(); + mReceivedMessageBackgroundColor = customThemeWrapper.getReceivedMessageBackgroundColor(); + mSentMessageBackgroundColor = customThemeWrapper.getSentMessageBackgroundColor(); } @Override @@ -151,7 +155,8 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt } if (holder instanceof SentMessageViewHolder) { - ((SentMessageViewHolder) holder).messageTextView.setBackgroundResource(R.drawable.private_message_ballon_sent); + ((SentMessageViewHolder) holder).messageTextView.setBackground(Utils.getTintedDrawable(mViewPrivateMessagesActivity, + R.drawable.private_message_ballon, mSentMessageBackgroundColor)); } else if (holder instanceof ReceivedMessageViewHolder) { mViewPrivateMessagesActivity.fetchUserAvatar(message.getAuthor(), userAvatarUrl -> { if (userAvatarUrl == null || userAvatarUrl.equals("")) { @@ -172,7 +177,10 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getAuthor()); mViewPrivateMessagesActivity.startActivity(intent); }); - ((ReceivedMessageViewHolder) holder).messageTextView.setBackgroundResource(R.drawable.private_message_ballon_received); + + ((ReceivedMessageViewHolder) holder).messageTextView.setBackground( + Utils.getTintedDrawable(mViewPrivateMessagesActivity, + R.drawable.private_message_ballon, mReceivedMessageBackgroundColor)); } } } @@ -244,6 +252,9 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt super(itemView); ButterKnife.bind(this, itemView); setBaseView(messageTextView, timeTextView); + + messageTextView.setTextColor(mSentMessageTextColor); + } } @@ -259,6 +270,8 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt super(itemView); ButterKnife.bind(this, itemView); setBaseView(messageTextView, timeTextView); + + messageTextView.setTextColor(mReceivedMessageTextColor); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java index d5d7530f..14cdb57a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Utils; import android.app.Activity; import android.content.Context; +import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkInfo; @@ -11,7 +12,9 @@ import android.util.DisplayMetrics; import android.view.inputmethod.InputMethodManager; import android.widget.TextView; +import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; +import androidx.core.graphics.drawable.DrawableCompat; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -139,4 +142,16 @@ public class Utils { public static float convertDpToPixel(float dp, Context context){ return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT); } + + @Nullable + public static Drawable getTintedDrawable(Context context, int drawableId, int color) { + Drawable drawable = context.getDrawable(drawableId); + if (drawable != null) { + Drawable wrappedDrawable = DrawableCompat.wrap(drawable).mutate(); + DrawableCompat.setTint(wrappedDrawable, color); + return wrappedDrawable; + } + + return null; + } } diff --git a/app/src/main/res/drawable/private_message_ballon.xml b/app/src/main/res/drawable/private_message_ballon.xml new file mode 100644 index 00000000..3e7f44d9 --- /dev/null +++ b/app/src/main/res/drawable/private_message_ballon.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/private_message_ballon_received.xml b/app/src/main/res/drawable/private_message_ballon_received.xml deleted file mode 100644 index 522d5cf0..00000000 --- a/app/src/main/res/drawable/private_message_ballon_received.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/drawable/private_message_ballon_sent.xml b/app/src/main/res/drawable/private_message_ballon_sent.xml deleted file mode 100644 index e813c552..00000000 --- a/app/src/main/res/drawable/private_message_ballon_sent.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - \ No newline at end of file -- cgit v1.2.3