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";
private static int linkColor;
private static boolean underlineLinks;
public static Spannable convert(Context context, String text,
Status status, Account account, Announcement announcement,
@ -115,6 +116,7 @@ public class SpannableHelper {
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);
underlineLinks = sharedpreferences.getBoolean(context.getString(R.string.SET_UNDERLINE_CLICKABLE), false);
int link_color;
if (currentNightMode == Configuration.UI_MODE_NIGHT_NO && customLight) {
link_color = sharedpreferences.getInt(context.getString(R.string.SET_LIGHT_LINK), -1);
@ -309,7 +311,9 @@ public class SpannableHelper {
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(status != null && status.underlined);
if(!underlineLinks) {
ds.setUnderlineText(status != null && status.underlined);
}
if (linkColor != -1) {
ds.setColor(linkColor);
}
@ -599,7 +603,9 @@ public class SpannableHelper {
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(status != null && status.underlined);
if(!underlineLinks) {
ds.setUnderlineText(status != null && status.underlined);
}
if (linkColor != -1) {
ds.setColor(linkColor);
}
@ -744,7 +750,9 @@ public class SpannableHelper {
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(status != null && status.underlined);
if(!underlineLinks) {
ds.setUnderlineText(status != null && status.underlined);
}
if (linkColor != -1) {
ds.setColor(linkColor);
}
@ -891,7 +899,9 @@ public class SpannableHelper {
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if(!underlineLinks) {
ds.setUnderlineText(false);
}
if (linkColor != -1) {
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_MARKDOWN_SUPPORT" translatable="false">SET_MARKDOWN_SUPPORT</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_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="truncate_links">Truncate links</string>
<string name="underline_links">Underlines clickable elements</string>
<string name="truncate_links_max">Max chars in links</string>

View File

@ -64,6 +64,13 @@
app:singleLineTitle="false"
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
android:defaultValue="30"
android:max="150"