Set color of received and sent messages, and send message button.

This commit is contained in:
Alex Ning 2020-07-06 17:18:42 +08:00
parent 933e928faf
commit 3ef4b90a63
5 changed files with 37 additions and 25 deletions

View File

@ -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

View File

@ -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);
}
}
}

View File

@ -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;
}
}

View File

@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#31BF7D" >
</solid>
<corners
android:radius="22dp">
</corners>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#4185F4" >
</solid>
<corners
android:radius="22dp">
</corners>
</shape>