diff --git a/src/main/java/eu/siacs/conversations/AppSettings.java b/src/main/java/eu/siacs/conversations/AppSettings.java index d9ba42993..0be3605cb 100644 --- a/src/main/java/eu/siacs/conversations/AppSettings.java +++ b/src/main/java/eu/siacs/conversations/AppSettings.java @@ -44,6 +44,7 @@ public class AppSettings { public static final String SEND_CRASH_REPORTS = "send_crash_reports"; public static final String COLORFUL_CHAT_BUBBLES = "use_green_background"; public static final String LARGE_FONT = "large_font"; + public static final String SHOW_LINK_PREVIEWS = "show_link_previews"; private final Context context; @@ -108,6 +109,10 @@ public class AppSettings { return getBooleanPreference(LARGE_FONT, R.bool.large_font); } + public boolean showLinkPreviews() { + return getBooleanPreference(SHOW_LINK_PREVIEWS, R.bool.show_link_previews); + } + public boolean isUseTor() { return getBooleanPreference(USE_TOR, R.bool.use_tor); } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 3bbf3d29a..6cf421a3f 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -164,6 +164,7 @@ public class MessageAdapter extends ArrayAdapter { private final boolean mForceNames; private final Map lastWebxdcUpdate = new HashMap<>(); private String selectionUuid = null; + private final AppSettings appSettings; public MessageAdapter( final XmppActivity activity, final List messages, final boolean forceNames) { @@ -171,6 +172,7 @@ public class MessageAdapter extends ArrayAdapter { this.audioPlayer = new AudioPlayer(this); this.activity = activity; metrics = getContext().getResources().getDisplayMetrics(); + appSettings = new AppSettings(activity); updatePreferences(); this.mForceNames = forceNames; } @@ -1594,18 +1596,20 @@ public class MessageAdapter extends ArrayAdapter { setTextColor(viewHolder.inReplyTo, bubbleColor); } - final var descriptions = message.getLinkDescriptions(); - viewHolder.link_descriptions.setAdapter(new ArrayAdapter<>(activity, 0, descriptions) { - @Override - public View getView(int position, View view, @NonNull ViewGroup parent) { - final LinkDescriptionBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.link_description, parent, false); - binding.title.setText(getItem(position).findChildContent("title", "https://ogp.me/ns#")); - binding.description.setText(getItem(position).findChildContent("description", "https://ogp.me/ns#")); - binding.url.setText(getItem(position).findChildContent("url", "https://ogp.me/ns#")); - return binding.getRoot(); - } - }); - Util.justifyListViewHeightBasedOnChildren(viewHolder.link_descriptions, (int)(metrics.density * 100), true); + if (appSettings.showLinkPreviews()) { + final var descriptions = message.getLinkDescriptions(); + viewHolder.link_descriptions.setAdapter(new ArrayAdapter<>(activity, 0, descriptions) { + @Override + public View getView(int position, View view, @NonNull ViewGroup parent) { + final LinkDescriptionBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.link_description, parent, false); + binding.title.setText(getItem(position).findChildContent("title", "https://ogp.me/ns#")); + binding.description.setText(getItem(position).findChildContent("description", "https://ogp.me/ns#")); + binding.url.setText(getItem(position).findChildContent("url", "https://ogp.me/ns#")); + return binding.getRoot(); + } + }); + Util.justifyListViewHeightBasedOnChildren(viewHolder.link_descriptions, (int)(metrics.density * 100), true); + } } displayStatus(viewHolder, message, type, bubbleColor); @@ -1679,7 +1683,6 @@ public class MessageAdapter extends ArrayAdapter { } public void updatePreferences() { - final AppSettings appSettings = new AppSettings(activity); this.bubbleDesign = new BubbleDesign(appSettings.isColorfulChatBubbles(), appSettings.isLargeFont()); } diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index d0088775f..03fce9e61 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -52,6 +52,7 @@ false true true + true true true oval diff --git a/src/main/res/xml/preferences_interface.xml b/src/main/res/xml/preferences_interface.xml index 8f1d07694..f92ff642b 100644 --- a/src/main/res/xml/preferences_interface.xml +++ b/src/main/res/xml/preferences_interface.xml @@ -129,6 +129,12 @@ android:key="show_dynamic_tags" android:summary="@string/pref_show_dynamic_tags_summary" android:title="@string/pref_show_dynamic_tags" /> +