Allow to underline clickable elements

This commit is contained in:
Thomas 2023-12-19 10:42:36 +01:00
parent 0064db72a1
commit dade64750d
3 changed files with 23 additions and 4 deletions

View file

@ -104,6 +104,7 @@ public class SpannableHelper {
public static final String CLICKABLE_SPAN = "CLICKABLE_SPAN"; public static final String CLICKABLE_SPAN = "CLICKABLE_SPAN";
private static int linkColor; private static int linkColor;
private static boolean underlineLinks;
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,
@ -115,6 +116,7 @@ public class SpannableHelper {
int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; 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 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); boolean customDark = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_DARK_COLORS), false);
underlineLinks = sharedpreferences.getBoolean(context.getString(R.string.SET_UNDERLINE_CLICKABLE), false);
int link_color; int link_color;
if (currentNightMode == Configuration.UI_MODE_NIGHT_NO && customLight) { if (currentNightMode == Configuration.UI_MODE_NIGHT_NO && customLight) {
link_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_LINK), -1); link_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_LINK), -1);
@ -309,7 +311,9 @@ public class SpannableHelper {
@Override @Override
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
ds.setUnderlineText(status != null && status.underlined); if(!underlineLinks) {
ds.setUnderlineText(status != null && status.underlined);
}
if (linkColor != -1) { if (linkColor != -1) {
ds.setColor(linkColor); ds.setColor(linkColor);
} }
@ -599,7 +603,9 @@ public class SpannableHelper {
@Override @Override
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
ds.setUnderlineText(status != null && status.underlined); if(!underlineLinks) {
ds.setUnderlineText(status != null && status.underlined);
}
if (linkColor != -1) { if (linkColor != -1) {
ds.setColor(linkColor); ds.setColor(linkColor);
} }
@ -744,7 +750,9 @@ public class SpannableHelper {
@Override @Override
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
ds.setUnderlineText(status != null && status.underlined); if(!underlineLinks) {
ds.setUnderlineText(status != null && status.underlined);
}
if (linkColor != -1) { if (linkColor != -1) {
ds.setColor(linkColor); ds.setColor(linkColor);
} }
@ -891,7 +899,9 @@ public class SpannableHelper {
@Override @Override
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
ds.setUnderlineText(false); if(!underlineLinks) {
ds.setUnderlineText(false);
}
if (linkColor != -1) { if (linkColor != -1) {
ds.setColor(linkColor); ds.setColor(linkColor);
} }

View file

@ -1189,6 +1189,7 @@
<string name="SET_BOOST_ORIGINAL_DATE" translatable="false">SET_BOOST_ORIGINAL_DATE</string> <string name="SET_BOOST_ORIGINAL_DATE" translatable="false">SET_BOOST_ORIGINAL_DATE</string>
<string name="SET_MARKDOWN_SUPPORT" translatable="false">SET_MARKDOWN_SUPPORT</string> <string name="SET_MARKDOWN_SUPPORT" translatable="false">SET_MARKDOWN_SUPPORT</string>
<string name="SET_TRUNCATE_LINKS" translatable="false">SET_TRUNCATE_LINKS</string> <string name="SET_TRUNCATE_LINKS" translatable="false">SET_TRUNCATE_LINKS</string>
<string name="SET_UNDERLINE_CLICKABLE" translatable="false">SET_UNDERLINE_CLICKABLE</string>
<string name="SET_TRUNCATE_LINKS_MAX" translatable="false">SET_TRUNCATE_LINKS_MAX</string> <string name="SET_TRUNCATE_LINKS_MAX" translatable="false">SET_TRUNCATE_LINKS_MAX</string>
<string name="SET_HIDE_SINGLE_MEDIA_WITH_CARD" translatable="false">SET_HIDE_SINGLE_MEDIA_WITH_CARD</string> <string name="SET_HIDE_SINGLE_MEDIA_WITH_CARD" translatable="false">SET_HIDE_SINGLE_MEDIA_WITH_CARD</string>
@ -1991,6 +1992,7 @@
<string name="toot_error_no_media_description">There are missing media descriptions</string> <string name="toot_error_no_media_description">There are missing media descriptions</string>
<string name="truncate_links">Truncate links</string> <string name="truncate_links">Truncate links</string>
<string name="underline_links">Underlines clickable elements</string>
<string name="truncate_links_max">Max chars in links</string> <string name="truncate_links_max">Max chars in links</string>

View file

@ -64,6 +64,13 @@
app:singleLineTitle="false" app:singleLineTitle="false"
app:title="@string/truncate_links" /> app:title="@string/truncate_links" />
<SwitchPreferenceCompat
android:defaultValue="false"
app:iconSpaceReserved="false"
app:key="@string/SET_UNDERLINE_CLICKABLE"
app:singleLineTitle="false"
app:title="@string/underline_links" />
<androidx.preference.SeekBarPreference <androidx.preference.SeekBarPreference
android:defaultValue="30" android:defaultValue="30"
android:max="150" android:max="150"