Change colors

This commit is contained in:
Thomas 2022-12-08 18:56:06 +01:00
parent 5337841da0
commit d9ed098464
2 changed files with 117 additions and 9 deletions

View File

@ -24,6 +24,7 @@ import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -95,12 +96,33 @@ public class SpannableHelper {
return convert(context, text, status, account, announcement, convertHtml, forceMentions, viewWeakReference, null); return convert(context, text, status, account, announcement, convertHtml, forceMentions, viewWeakReference, null);
} }
private static int linkColor;
public static Spannable convert(Context context, String text, public static Spannable convert(Context context, String text,
Status status, Account account, Announcement announcement, Status status, Account account, Announcement announcement,
boolean convertHtml, boolean convertHtml,
boolean forceMentions, boolean forceMentions,
WeakReference<View> viewWeakReference, Status.Callback callback) { WeakReference<View> viewWeakReference, Status.Callback callback) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
boolean customLight = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_LIGHT_COLORS), false);
boolean customDark = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_DARK_COLORS), false);
int link_color;
if (currentNightMode == Configuration.UI_MODE_NIGHT_NO && customLight) {
link_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_LINK), -1);
if (link_color != -1) {
linkColor = link_color;
}
} else if (currentNightMode == Configuration.UI_MODE_NIGHT_YES && customDark) {
link_color = sharedpreferences.getInt(context.getString(R.string.SET_DARK_LINK), -1);
if (link_color != -1) {
linkColor = link_color;
}
} else {
linkColor = linkColor;
}
SpannableString initialContent; SpannableString initialContent;
if (text == null) { if (text == null) {
@ -166,7 +188,6 @@ public class SpannableHelper {
} else { } else {
content = new SpannableStringBuilder(text); content = new SpannableStringBuilder(text);
} }
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean animate = !sharedpreferences.getBoolean(context.getString(R.string.SET_DISABLE_ANIMATED_EMOJI), false); boolean animate = !sharedpreferences.getBoolean(context.getString(R.string.SET_DISABLE_ANIMATED_EMOJI), false);
CustomEmoji customEmoji = new CustomEmoji(new WeakReference<>(view)); CustomEmoji customEmoji = new CustomEmoji(new WeakReference<>(view));
content = customEmoji.makeEmoji(content, emojiList, animate, callback); content = customEmoji.makeEmoji(content, emojiList, animate, callback);
@ -443,7 +464,7 @@ public class SpannableHelper {
@Override @Override
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); ds.setColor(linkColor);
} }
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
@ -668,7 +689,7 @@ public class SpannableHelper {
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
ds.setUnderlineText(false); ds.setUnderlineText(false);
ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); ds.setColor(linkColor);
} }
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
} }
@ -702,7 +723,7 @@ public class SpannableHelper {
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
ds.setUnderlineText(false); ds.setUnderlineText(false);
ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); ds.setColor(linkColor);
} }
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
} }
@ -739,7 +760,7 @@ public class SpannableHelper {
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
ds.setUnderlineText(false); ds.setUnderlineText(false);
ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); ds.setColor(linkColor);
} }
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
} }
@ -887,7 +908,7 @@ public class SpannableHelper {
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
ds.setUnderlineText(false); ds.setUnderlineText(false);
ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); ds.setColor(linkColor);
} }
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
@ -1036,7 +1057,7 @@ public class SpannableHelper {
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
ds.setUnderlineText(false); ds.setUnderlineText(false);
ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); ds.setColor(linkColor);
} }
}, },
startPosition, endPosition, startPosition, endPosition,

View File

@ -36,6 +36,7 @@ import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -2155,6 +2156,90 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
return position; return position;
} }
private static void applyColor(Context context, StatusViewHolder holder) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
boolean customLight = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_LIGHT_COLORS), false);
boolean customDark = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_DARK_COLORS), false);
int theme_icons_color = -1;
int theme_statuses_color = -1;
int theme_boost_header_color = -1;
int theme_text_color = -1;
int theme_text_header_1_line = -1;
int theme_text_header_2_line = -1;
int link_color = -1;
if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) { //LIGHT THEME
if (customLight) {
theme_icons_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_ICON), -1);
theme_statuses_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_BACKGROUND), -1);
theme_boost_header_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_BOOST_HEADER), -1);
theme_text_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_TEXT), -1);
theme_text_header_1_line = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_DISPLAY_NAME), -1);
theme_text_header_2_line = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_USERNAME), -1);
link_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_LINK), -1);
}
} else {
if (customDark) {
theme_icons_color = sharedpreferences.getInt(context.getString(R.string.SET_DARK_ICON), -1);
theme_statuses_color = sharedpreferences.getInt(context.getString(R.string.SET_DARK_BACKGROUND), -1);
theme_boost_header_color = sharedpreferences.getInt(context.getString(R.string.SET_DARK_BOOST_HEADER), -1);
theme_text_color = sharedpreferences.getInt(context.getString(R.string.SET_DARK_TEXT), -1);
theme_text_header_1_line = sharedpreferences.getInt(context.getString(R.string.SET_DARK_DISPLAY_NAME), -1);
theme_text_header_2_line = sharedpreferences.getInt(context.getString(R.string.SET_DARK_USERNAME), -1);
link_color = sharedpreferences.getInt(context.getString(R.string.SET_DARK_LINK), -1);
}
}
if (theme_icons_color != -1) {
Helper.changeDrawableColor(context, holder.binding.actionButtonReply, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.statusAddCustomEmoji, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.statusEmoji, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.actionButtonMore, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_baseline_star_24, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_repeat, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.visibility, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_star_outline, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_person, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_bot, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_baseline_reply_16, theme_icons_color);
holder.binding.actionButtonFavorite.setInActiveImageTintColor(theme_icons_color);
holder.binding.actionButtonBookmark.setInActiveImageTintColor(theme_icons_color);
holder.binding.actionButtonBoost.setInActiveImageTintColor(theme_icons_color);
holder.binding.replyCount.setTextColor(theme_icons_color);
}
if (theme_statuses_color != -1) {
holder.binding.cardviewContainer.setBackgroundColor(theme_statuses_color);
holder.binding.translationLabel.setBackgroundColor(theme_statuses_color);
}
if (theme_boost_header_color != -1) {
holder.binding.statusBoosterInfo.setBackgroundColor(theme_boost_header_color);
}
if (theme_text_color != -1) {
holder.binding.statusContent.setTextColor(theme_text_color);
holder.binding.statusContentTranslated.setTextColor(theme_text_color);
holder.binding.spoiler.setTextColor(theme_text_color);
holder.binding.dateShort.setTextColor(theme_text_color);
holder.binding.poll.pollInfo.setTextColor(theme_text_color);
holder.binding.cardDescription.setTextColor(theme_text_color);
holder.binding.time.setTextColor(theme_text_color);
holder.binding.reblogsCount.setTextColor(theme_text_color);
holder.binding.favoritesCount.setTextColor(theme_text_color);
holder.binding.favoritesCount.setTextColor(theme_text_color);
Helper.changeDrawableColor(context, holder.binding.repeatInfo, theme_text_color);
Helper.changeDrawableColor(context, holder.binding.favInfo, theme_text_color);
Helper.changeDrawableColor(context, R.drawable.ic_baseline_lock_24, theme_text_color);
}
if (theme_text_header_1_line != -1) {
holder.binding.displayName.setTextColor(theme_text_header_1_line);
}
if (theme_text_header_2_line != -1) {
holder.binding.username.setTextColor(theme_text_header_2_line);
}
if (link_color != -1) {
holder.binding.cardUrl.setTextColor(link_color);
}
}
@Override @Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
//Nothing to do with hidden statuses //Nothing to do with hidden statuses
@ -2172,6 +2257,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class); StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class);
SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class); SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class);
statusManagement(context, statusesVM, searchVM, holder, mRecyclerView, this, statusList, status, timelineType, minified, canBeFederated, checkRemotely, fetchMoreCallBack); statusManagement(context, statusesVM, searchVM, holder, mRecyclerView, this, statusList, status, timelineType, minified, canBeFederated, checkRemotely, fetchMoreCallBack);
applyColor(context, holder);
} else if (viewHolder.getItemViewType() == STATUS_FILTERED_HIDE) { } else if (viewHolder.getItemViewType() == STATUS_FILTERED_HIDE) {
StatusViewHolder holder = (StatusViewHolder) viewHolder; StatusViewHolder holder = (StatusViewHolder) viewHolder;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
@ -2209,7 +2295,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else { } else {
holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE); holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE);
} }
applyColor(context, holder);
} else if (viewHolder.getItemViewType() == STATUS_FILTERED) { } else if (viewHolder.getItemViewType() == STATUS_FILTERED) {
StatusViewHolder holder = (StatusViewHolder) viewHolder; StatusViewHolder holder = (StatusViewHolder) viewHolder;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
@ -2253,7 +2339,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else { } else {
holder.bindingFiltered.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE); holder.bindingFiltered.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE);
} }
applyColor(context, holder);
} else if (viewHolder.getItemViewType() == STATUS_ART) { } else if (viewHolder.getItemViewType() == STATUS_ART) {
StatusViewHolder holder = (StatusViewHolder) viewHolder; StatusViewHolder holder = (StatusViewHolder) viewHolder;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
@ -2333,6 +2419,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
intent.putExtra(Helper.ARG_STATUS, status); intent.putExtra(Helper.ARG_STATUS, status);
context.startActivity(intent); context.startActivity(intent);
}); });
applyColor(context, holder);
} }
} }