aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java50
-rw-r--r--src/main/java/de/pixart/messenger/utils/GeoHelper.java22
2 files changed, 57 insertions, 15 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index c07215df7..409fa185f 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -23,6 +23,7 @@ import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.text.util.Linkify;
import android.util.DisplayMetrics;
+import android.util.Log;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.View;
@@ -37,6 +38,9 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.engine.DiskCacheStrategy;
+
import java.lang.ref.WeakReference;
import java.net.URL;
import java.util.HashMap;
@@ -54,6 +58,7 @@ import de.pixart.messenger.entities.Message;
import de.pixart.messenger.entities.Message.FileParams;
import de.pixart.messenger.entities.Transferable;
import de.pixart.messenger.persistance.FileBackend;
+import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.ui.ConversationActivity;
import de.pixart.messenger.ui.ShowFullscreenMessageActivity;
import de.pixart.messenger.ui.widget.ClickableMovementMethod;
@@ -65,6 +70,7 @@ import de.pixart.messenger.utils.UIHelper;
import nl.changer.audiowife.AudioWife;
public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler {
+ private XmppConnectionService mXmppConnectionService;
private static final int SENT = 0;
private static final int RECEIVED = 1;
@@ -443,20 +449,33 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
});
}
- private void displayLocationMessage(ViewHolder viewHolder, final Message message) {
- viewHolder.aw_player.setVisibility(View.GONE);
- viewHolder.image.setVisibility(View.GONE);
- viewHolder.messageBody.setVisibility(View.GONE);
- viewHolder.download_button.setText(R.string.show_location);
- viewHolder.download_button.setVisibility(View.VISIBLE);
- viewHolder.download_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_map_marker_grey600_48dp,0,0,0);
- viewHolder.download_button.setOnClickListener(new OnClickListener() {
+ private void displayLocationMessage(ViewHolder viewHolder, final Message message) {
+ viewHolder.aw_player.setVisibility(View.GONE);
+ viewHolder.messageBody.setVisibility(View.GONE);
+ String url = GeoHelper.MapPreviewUri(message);
+ Log.d(Config.LOGTAG, "Map preview = " + url);
+ viewHolder.image.setVisibility(View.VISIBLE);
+ viewHolder.image.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- showLocation(message);
- }
- });
+ @Override
+ public void onClick(View v) {
+ showLocation(message);
+ }
+ });
+ Glide
+ .with(activity)
+ .load(Uri.parse(url))
+ .diskCacheStrategy(DiskCacheStrategy.ALL)
+ .fitCenter()
+ .placeholder(R.drawable.ic_map_marker_grey600_48dp)
+ .error(R.drawable.ic_map_marker_grey600_48dp)
+ .into(viewHolder.image);
+ viewHolder.image.getLayoutParams().width = 400;
+ viewHolder.image.getLayoutParams().height = 400;
+ viewHolder.image.setAdjustViewBounds(true);
+ viewHolder.download_button.setVisibility(View.GONE);
+ viewHolder.download_button.setText(R.string.show_location);
+ viewHolder.download_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_map_marker_grey600_48dp, 0, 0, 0);
viewHolder.download_button.setOnClickListener(new OnClickListener() {
@Override
@@ -464,7 +483,8 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
showLocation(message);
}
});
- }
+
+ }
private void displayImageMessage(ViewHolder viewHolder,
final Message message) {
@@ -700,7 +720,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
displayDecryptionFailed(viewHolder,darkBackground);
} else {
if (GeoHelper.isGeoUri(message.getBody())) {
- displayLocationMessage(viewHolder,message);
+ displayLocationMessage(viewHolder,message);
} else if (message.bodyIsHeart()) {
displayHeartMessage(viewHolder, message.getBody().trim());
} else if (message.treatAsDownloadable() == Message.Decision.MUST ||
diff --git a/src/main/java/de/pixart/messenger/utils/GeoHelper.java b/src/main/java/de/pixart/messenger/utils/GeoHelper.java
index afcb1bd8e..a524c1356 100644
--- a/src/main/java/de/pixart/messenger/utils/GeoHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/GeoHelper.java
@@ -20,6 +20,28 @@ public class GeoHelper {
return body != null && GEO_URI.matcher(body).matches();
}
+ public static String MapPreviewUri (Message message) {
+ Matcher matcher = GEO_URI.matcher(message.getBody());
+ if (!matcher.matches()) {
+ return null;
+ }
+ double latitude;
+ double longitude;
+ try {
+ latitude = Double.parseDouble(matcher.group(1));
+ if (latitude > 90.0 || latitude < -90.0) {
+ return null;
+ }
+ longitude = Double.parseDouble(matcher.group(2));
+ if (longitude > 180.0 || longitude < -180.0) {
+ return null;
+ }
+ } catch (NumberFormatException nfe) {
+ return null;
+ }
+ return "https://maps.google.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&size=400x400&scale=2&format=jpg&markers=" + latitude + "," + longitude + "&sensor=false";
+ }
+
public static ArrayList<Intent> createGeoIntentsFromMessage(Message message) {
final ArrayList<Intent> intents = new ArrayList<>();
Matcher matcher = GEO_URI.matcher(message.getBody());