diff --git a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java index 66da5a5e..1eb8492e 100644 --- a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java @@ -24,6 +24,7 @@ import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -95,12 +96,33 @@ public class SpannableHelper { return convert(context, text, status, account, announcement, convertHtml, forceMentions, viewWeakReference, null); } + + private static int linkColor; + public static Spannable convert(Context context, String text, Status status, Account account, Announcement announcement, boolean convertHtml, boolean forceMentions, WeakReference 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; if (text == null) { @@ -166,7 +188,6 @@ public class SpannableHelper { } else { content = new SpannableStringBuilder(text); } - SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean animate = !sharedpreferences.getBoolean(context.getString(R.string.SET_DISABLE_ANIMATED_EMOJI), false); CustomEmoji customEmoji = new CustomEmoji(new WeakReference<>(view)); content = customEmoji.makeEmoji(content, emojiList, animate, callback); @@ -443,7 +464,7 @@ public class SpannableHelper { @Override public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); - ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); + ds.setColor(linkColor); } }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); @@ -668,7 +689,7 @@ public class SpannableHelper { public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); + ds.setColor(linkColor); } }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } @@ -702,7 +723,7 @@ public class SpannableHelper { public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); + ds.setColor(linkColor); } }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } @@ -739,7 +760,7 @@ public class SpannableHelper { public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); + ds.setColor(linkColor); } }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } @@ -887,7 +908,7 @@ public class SpannableHelper { public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); + ds.setColor(linkColor); } }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); @@ -1036,7 +1057,7 @@ public class SpannableHelper { public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - ds.setColor(ThemeHelper.getAttColor(context, R.attr.linkColor)); + ds.setColor(linkColor); } }, startPosition, endPosition, diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index 228dc427..d6f062a5 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -36,6 +36,7 @@ import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.graphics.PorterDuff; import android.graphics.Typeface; import android.graphics.drawable.Drawable; @@ -2155,6 +2156,90 @@ public class StatusAdapter extends RecyclerView.Adapter 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 public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { //Nothing to do with hidden statuses @@ -2172,6 +2257,7 @@ public class StatusAdapter extends RecyclerView.Adapter StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class); SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class); statusManagement(context, statusesVM, searchVM, holder, mRecyclerView, this, statusList, status, timelineType, minified, canBeFederated, checkRemotely, fetchMoreCallBack); + applyColor(context, holder); } else if (viewHolder.getItemViewType() == STATUS_FILTERED_HIDE) { StatusViewHolder holder = (StatusViewHolder) viewHolder; SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); @@ -2209,7 +2295,7 @@ public class StatusAdapter extends RecyclerView.Adapter } else { holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE); } - + applyColor(context, holder); } else if (viewHolder.getItemViewType() == STATUS_FILTERED) { StatusViewHolder holder = (StatusViewHolder) viewHolder; SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); @@ -2253,7 +2339,7 @@ public class StatusAdapter extends RecyclerView.Adapter } else { holder.bindingFiltered.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE); } - + applyColor(context, holder); } else if (viewHolder.getItemViewType() == STATUS_ART) { StatusViewHolder holder = (StatusViewHolder) viewHolder; SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); @@ -2333,6 +2419,7 @@ public class StatusAdapter extends RecyclerView.Adapter intent.putExtra(Helper.ARG_STATUS, status); context.startActivity(intent); }); + applyColor(context, holder); } }