From ea8f92441c58ed6b3deaa9ef1b9a2500543b1ef8 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sun, 2 Mar 2014 13:23:06 +0400 Subject: [PATCH] Fixed RTL name position in messages --- TMessagesProj/src/main/AndroidManifest.xml | 2 +- .../org/telegram/messenger/ConnectionsManager.java | 1 + .../main/java/org/telegram/objects/MessageObject.java | 4 ++-- .../main/java/org/telegram/ui/Cells/ChatBaseCell.java | 8 ++++++-- .../java/org/telegram/ui/Cells/ChatMessageCell.java | 10 +++++----- .../src/main/java/org/telegram/ui/ChatActivity.java | 2 ++ .../main/java/org/telegram/ui/SettingsActivity.java | 2 +- 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/TMessagesProj/src/main/AndroidManifest.xml b/TMessagesProj/src/main/AndroidManifest.xml index fd7be431e..6f8b3a91c 100644 --- a/TMessagesProj/src/main/AndroidManifest.xml +++ b/TMessagesProj/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ datacenters = new HashMap(); private HashMap> processedMessageIdsSet = new HashMap>(); diff --git a/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java index 5e85b9b46..b839212dc 100644 --- a/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java +++ b/TMessagesProj/src/main/java/org/telegram/objects/MessageObject.java @@ -376,9 +376,9 @@ public class MessageObject { textLayoutBlocks = new ArrayList(); if (messageText instanceof Spannable) { - if (messageOwner.message != null && messageOwner.message.contains(".")) { + if (messageOwner.message != null && messageOwner.message.contains(".") && (messageOwner.message.contains(".com") || messageOwner.message.contains("http") || messageOwner.message.contains(".ru") || messageOwner.message.contains(".org") || messageOwner.message.contains(".net"))) { Linkify.addLinks((Spannable)messageText, Linkify.WEB_URLS); - } else if (messageText.length() < 400) { + } else if (messageText.length() < 100) { Linkify.addLinks((Spannable)messageText, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java index 0211e210b..d3efc3b9a 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java @@ -68,6 +68,7 @@ public class ChatBaseCell extends BaseCell { private StaticLayout nameLayout; protected int nameWidth; + private float nameOffsetX = 0; protected boolean drawName = false; private StaticLayout forwardedNameLayout; @@ -75,6 +76,7 @@ public class ChatBaseCell extends BaseCell { protected boolean drawForwardedName = false; private int forwardNameX; private int forwardNameY; + private float forwardNameOffsetX = 0; private StaticLayout timeLayout; protected int timeWidth; @@ -218,6 +220,7 @@ public class ChatBaseCell extends BaseCell { if (nameLayout.getLineCount() > 0) { nameWidth = (int)Math.ceil(nameLayout.getLineWidth(0)); namesOffset += Utilities.dp(18); + nameOffsetX = nameLayout.getLineLeft(0); } else { nameWidth = 0; } @@ -240,6 +243,7 @@ public class ChatBaseCell extends BaseCell { if (forwardedNameLayout.getLineCount() > 1) { forwardedNameWidth = Math.max((int) Math.ceil(forwardedNameLayout.getLineWidth(0)), (int) Math.ceil(forwardedNameLayout.getLineWidth(1))); namesOffset += Utilities.dp(36); + forwardNameOffsetX = Math.min(forwardedNameLayout.getLineLeft(0), forwardedNameLayout.getLineLeft(1)); } else { forwardedNameWidth = 0; } @@ -381,7 +385,7 @@ public class ChatBaseCell extends BaseCell { if (drawName && nameLayout != null) { canvas.save(); - canvas.translate(currentBackgroundDrawable.getBounds().left + Utilities.dp(19), Utilities.dp(10)); + canvas.translate(currentBackgroundDrawable.getBounds().left + Utilities.dp(19) - nameOffsetX, Utilities.dp(10)); namePaint.setColor(Utilities.getColorForId(currentUser.id)); nameLayout.draw(canvas); canvas.restore(); @@ -398,7 +402,7 @@ public class ChatBaseCell extends BaseCell { forwardNameX = currentBackgroundDrawable.getBounds().left + Utilities.dp(19); forwardNameY = Utilities.dp(10 + (drawName ? 18 : 0)); } - canvas.translate(forwardNameX, forwardNameY); + canvas.translate(forwardNameX - forwardNameOffsetX, forwardNameY); forwardedNameLayout.draw(canvas); canvas.restore(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java index cda68d560..7e9e34901 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java @@ -12,7 +12,6 @@ import android.content.Context; import android.graphics.Canvas; import android.text.Spannable; import android.text.style.ClickableSpan; -import android.util.Log; import android.view.MotionEvent; import org.telegram.messenger.Utilities; @@ -30,6 +29,8 @@ public class ChatMessageCell extends ChatBaseCell { private int firstVisibleBlockNum = 0; private int totalVisibleBlocksCount = 0; + private boolean wasLayout = false; + public ChatMessageCell(Context context, boolean isChat) { super(context, isChat); drawForwardedName = true; @@ -88,9 +89,6 @@ public class ChatMessageCell extends ChatBaseCell { public void setVisiblePart(int position, int height) { visibleY = position; visibleHeight = height; - if (visibleY < 0) { - Log.e("tmessages", "vis = " + visibleY); - } int newFirst = -1, newLast = -1, newCount = 0; @@ -126,6 +124,7 @@ public class ChatMessageCell extends ChatBaseCell { @Override public void setMessageObject(MessageObject messageObject) { if (currentMessageObject != messageObject || isUserDataChanged()) { + wasLayout = false; pressedLink = null; int maxWidth; if (chat) { @@ -173,7 +172,7 @@ public class ChatMessageCell extends ChatBaseCell { protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); - if (changed) { + if (changed || !wasLayout) { if (currentMessageObject.messageOwner.out) { textX = layoutWidth - backgroundWidth + Utilities.dp(10); textY = Utilities.dp(10) + namesOffset; @@ -181,6 +180,7 @@ public class ChatMessageCell extends ChatBaseCell { textX = Utilities.dp(19) + (chat ? Utilities.dp(52) : 0); textY = Utilities.dp(10) + namesOffset; } + wasLayout = true; } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 438a33664..585cb17c5 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -2897,6 +2897,8 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa view.setBackgroundColor(0); } + cell.setMessageObject(cell.getMessageObject()); + cell.setCheckPressed(!disableSelection, disableSelection && selected); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java index b4ea595ef..0d15da117 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java @@ -456,7 +456,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE); i.setType("message/rfc822") ; - i.putExtra(Intent.EXTRA_EMAIL, new String[]{"drklo.2kb@gmail.com"}); + i.putExtra(Intent.EXTRA_EMAIL, new String[]{ConnectionsManager.SEND_LOGS_EMAIL}); i.putExtra(Intent.EXTRA_SUBJECT, "last logs"); i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); startActivity(Intent.createChooser(i, "Select email application."));