1
0
Fork 1

show images from links in status in contact details

(cherry picked from commit 5e7ea866fb)
This commit is contained in:
Arne 2024-03-18 01:32:11 +01:00 committed by 12aw
parent c052044353
commit bea04708b2
3 changed files with 210 additions and 64 deletions

View file

@ -11,35 +11,9 @@
"type": "UNIVERSAL",
"filters": [],
"attributes": [],
"versionCode": 165,
"versionName": "1.7.9.4",
"outputFile": "monocles chat-1.7.9.4-git-universal-release.apk"
},
{
"type": "ONE_OF_MANY",
"filters": [
{
"filterType": "ABI",
"value": "x86_64"
}
],
"attributes": [],
"versionCode": 16503,
"versionName": "1.7.9.4",
"outputFile": "monocles chat-1.7.9.4-git-x86_64-release.apk"
},
{
"type": "ONE_OF_MANY",
"filters": [
{
"filterType": "ABI",
"value": "armeabi-v7a"
}
],
"attributes": [],
"versionCode": 16501,
"versionName": "1.7.9.4",
"outputFile": "monocles chat-1.7.9.4-git-armeabi-v7a-release.apk"
"versionCode": 166,
"versionName": "1.7.9.4.1",
"outputFile": "monocles chat-1.7.9.4.1-git-universal-release.apk"
},
{
"type": "ONE_OF_MANY",
@ -50,9 +24,9 @@
}
],
"attributes": [],
"versionCode": 16504,
"versionName": "1.7.9.4",
"outputFile": "monocles chat-1.7.9.4-git-arm64-v8a-release.apk"
"versionCode": 16604,
"versionName": "1.7.9.4.1",
"outputFile": "monocles chat-1.7.9.4.1-git-arm64-v8a-release.apk"
},
{
"type": "ONE_OF_MANY",
@ -63,9 +37,35 @@
}
],
"attributes": [],
"versionCode": 16502,
"versionName": "1.7.9.4",
"outputFile": "monocles chat-1.7.9.4-git-x86-release.apk"
"versionCode": 16602,
"versionName": "1.7.9.4.1",
"outputFile": "monocles chat-1.7.9.4.1-git-x86-release.apk"
},
{
"type": "ONE_OF_MANY",
"filters": [
{
"filterType": "ABI",
"value": "armeabi-v7a"
}
],
"attributes": [],
"versionCode": 16601,
"versionName": "1.7.9.4.1",
"outputFile": "monocles chat-1.7.9.4.1-git-armeabi-v7a-release.apk"
},
{
"type": "ONE_OF_MANY",
"filters": [
{
"filterType": "ABI",
"value": "x86_64"
}
],
"attributes": [],
"versionCode": 16603,
"versionName": "1.7.9.4.1",
"outputFile": "monocles chat-1.7.9.4.1-git-x86_64-release.apk"
}
],
"elementType": "File"

View file

@ -4,6 +4,11 @@ import static eu.siacs.conversations.ui.util.IntroHelper.showIntro;
import eu.siacs.conversations.databinding.ThreadRowBinding;
import eu.monocles.chat.Util;
import androidx.annotation.NonNull;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.util.Patterns;
import android.view.ViewGroup;
import android.Manifest;
@ -33,6 +38,7 @@ import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ArrayAdapter;
import android.widget.Toast;
@ -51,6 +57,9 @@ import com.google.common.base.Optional;
import org.openintents.openpgp.util.OpenPgpUtils;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -58,6 +67,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import eu.siacs.conversations.entities.Bookmark;
@ -101,6 +111,8 @@ import eu.monocles.chat.Util;
import android.view.ViewGroup;
import android.util.TypedValue;
import android.graphics.drawable.Drawable;
import android.widget.ViewFlipper;
import eu.siacs.conversations.xmpp.jingle.OngoingRtpSession;
import eu.siacs.conversations.xmpp.jingle.RtpCapability;
import me.drakeet.support.toast.ToastCompat;
@ -108,7 +120,6 @@ import me.drakeet.support.toast.ToastCompat;
public class ContactDetailsActivity extends OmemoActivity implements OnAccountUpdate, OnRosterUpdate, OnUpdateBlocklist, OnKeyStatusUpdated, OnMediaLoaded {
public static final String ACTION_VIEW_CONTACT = "view_contact";
private final int REQUEST_SYNC_CONTACTS = 0x28cf;
private Contact contact;
private Conversation mConversation;
private ConversationFragment mConversationFragment;
@ -726,27 +737,95 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
.setPositiveButton(getString(R.string.delete), removeFromRoster).create().show();
});
List<String> statusMessages = contact.getPresences().getStatusMessages();
if (statusMessages.size() == 0) {
binding.statusMessage.setVisibility(View.GONE);
} else if (statusMessages.size() == 1) {
final String message = statusMessages.get(0);
binding.statusMessage.setVisibility(View.VISIBLE);
final Spannable span = new SpannableString(message);
if (Emoticons.isOnlyEmoji(message)) {
span.setSpan(new RelativeSizeSpan(2.0f), 0, message.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
binding.statusMessage.setText(span);
} else {
StringBuilder builder = new StringBuilder();
binding.statusMessage.setVisibility(View.VISIBLE);
int s = statusMessages.size();
for (int i = 0; i < s; ++i) {
builder.append(statusMessages.get(i));
if (i < s - 1) {
builder.append("\n");
if (getPreferences().getBoolean("send_link_previews", true)) {
if (statusMessages.size() == 0) {
binding.statusMessage.setVisibility(View.GONE);
binding.statusImage.setVisibility(View.GONE);
} else if (statusMessages.size() == 1) {
final String message = statusMessages.get(0);
binding.statusMessage.setVisibility(View.VISIBLE);
final Spannable span = new SpannableString(message);
if (Emoticons.isOnlyEmoji(message)) {
span.setSpan(new RelativeSizeSpan(2.0f), 0, message.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
binding.statusMessage.setText(span);
//find and show images from links
for (String statusMessage : statusMessages) {
if (containsLink(statusMessage)) {
List<String> url = extractUrls(statusMessage);
binding.statusImage.setVisibility(View.VISIBLE);
for (String imageurl : url) {
Thread imageDataThread = new Thread(() -> {
try {
URL tUrl = new URL(imageurl);
Bitmap imageBitmap = BitmapFactory.decodeStream(tUrl.openConnection().getInputStream());
BitmapDrawable image = new BitmapDrawable(imageBitmap);
binding.statusImage.setImageDrawable(image);
} catch (IOException pExc) {
pExc.printStackTrace();
}
});
imageDataThread.start();
}
}
}
} else {
StringBuilder builder = new StringBuilder();
binding.statusMessage.setVisibility(View.VISIBLE);
int s = statusMessages.size();
for (int i = 0; i < s; ++i) {
builder.append(statusMessages.get(i));
if (i < s - 1) {
builder.append("\n");
}
}
binding.statusMessage.setText(builder);
//find and show images from links
for (String statusMessage : statusMessages) {
if (containsLink(statusMessage)) {
List<String> url = extractUrls(statusMessage);
binding.statusImage.setVisibility(View.VISIBLE);
for (String imageurl : url) {
Thread imageDataThread = new Thread(() -> {
try {
URL tUrl = new URL(imageurl);
Bitmap imageBitmap = BitmapFactory.decodeStream(tUrl.openConnection().getInputStream());
BitmapDrawable image = new BitmapDrawable(imageBitmap);
binding.statusImage.setImageDrawable(image);
} catch (IOException pExc) {
pExc.printStackTrace();
}
});
imageDataThread.start();
}
}
}
}
binding.statusMessage.setText(builder);
} else {
if (statusMessages.size() == 0) {
binding.statusMessage.setVisibility(View.GONE);
} else if (statusMessages.size() == 1) {
final String message = statusMessages.get(0);
binding.statusMessage.setVisibility(View.VISIBLE);
final Spannable span = new SpannableString(message);
if (Emoticons.isOnlyEmoji(message)) {
span.setSpan(new RelativeSizeSpan(2.0f), 0, message.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
binding.statusMessage.setText(span);
} else {
StringBuilder builder = new StringBuilder();
binding.statusMessage.setVisibility(View.VISIBLE);
int s = statusMessages.size();
for (int i = 0; i < s; ++i) {
builder.append(statusMessages.get(i));
if (i < s - 1) {
builder.append("\n");
}
}
binding.statusMessage.setText(builder);
}
}
String resources = contact.getPresences().getMostAvailableResource();
if (resources.length() == 0) {
@ -1139,4 +1218,42 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
return binding.getRoot();
}
}
public static boolean containsLink(String input) {
boolean result = false;
String[] parts = input.split("\\s+");
for (String item : parts) {
if (android.util.Patterns.WEB_URL.matcher(item).matches()) {
result = true;
break;
}
}
return result;
}
public static List<String> extractUrls(String input)
{
List<String> result = new ArrayList<String>();
String[] words = input.split("\\s+");
Pattern pattern = Patterns.WEB_URL;
for(String word : words)
{
if(pattern.matcher(word).find())
{
if(!word.toLowerCase().contains("http://") && !word.toLowerCase().contains("https://"))
{
word = "http://" + word;
}
result.add(word);
}
}
return result;
}
}

View file

@ -44,7 +44,7 @@
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:orientation="vertical">
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
@ -131,14 +131,6 @@
android:layout_marginBottom="4dp"
android:textAppearance="@style/TextAppearance.Conversations.Subhead" />
<TextView
android:id="@+id/status_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:textAppearance="@style/TextAppearance.Conversations.Subhead" />
<TextView
android:id="@+id/resource"
android:layout_width="wrap_content"
@ -147,6 +139,43 @@
android:layout_marginBottom="4dp"
android:textAppearance="@style/TextAppearance.Conversations.Status" />
</LinearLayout>
<LinearLayout
android:layout_below="@+id/details_display"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<TextView
android:id="@+id/status_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:clickable="true"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:textAppearance="@style/TextAppearance.Conversations.Subhead" />
<ImageSwitcher
android:id="@+id/status_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:maxWidth="120dp"
android:maxHeight="120dp"
android:adjustViewBounds="true"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:scaleType="fitXY"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout