mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Remove unused URL-searching when entering text.
This commit is contained in:
@@ -101,7 +101,6 @@ public class AndroidUtilities {
|
||||
private static Boolean isTablet = null;
|
||||
private static int adjustOwnerClassGuid = 0;
|
||||
|
||||
public static Pattern WEB_URL = null;
|
||||
static {
|
||||
try {
|
||||
final String GOOD_IRI_CHAR = "a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF";
|
||||
@@ -115,15 +114,6 @@ public class AndroidUtilities {
|
||||
final String GTLD = "[" + GOOD_GTLD_CHAR + "]{2,63}";
|
||||
final String HOST_NAME = "(" + IRI + "\\.)+" + GTLD;
|
||||
final Pattern DOMAIN_NAME = Pattern.compile("(" + HOST_NAME + "|" + IP_ADDRESS + ")");
|
||||
WEB_URL = Pattern.compile(
|
||||
"((?:(http|https|Http|Https):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)"
|
||||
+ "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_"
|
||||
+ "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?"
|
||||
+ "(?:" + DOMAIN_NAME + ")"
|
||||
+ "(?:\\:\\d{1,5})?)" // plus option port number
|
||||
+ "(\\/(?:(?:[" + GOOD_IRI_CHAR + "\\;\\/\\?\\:\\@\\&\\=\\#\\~" // plus option query params
|
||||
+ "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?"
|
||||
+ "(?:\\b|$)");
|
||||
} catch (Exception e) {
|
||||
FileLog.e("messenger", e);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,6 @@ import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ChatActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate,
|
||||
@@ -156,9 +155,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
private boolean paused = true;
|
||||
private boolean wasPaused = false;
|
||||
private boolean readWhenResume = false;
|
||||
private int linkSearchRequestId;
|
||||
private ArrayList<CharSequence> foundUrls;
|
||||
private Runnable waitingForCharaterEnterRunnable;
|
||||
|
||||
private boolean scrollToTopOnResume;
|
||||
private boolean forceScrollToTop;
|
||||
@@ -1040,29 +1036,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
@Override
|
||||
public void onTextChanged(final CharSequence text, boolean bigChange) {
|
||||
MediaController.getInstance().setInputFieldHasText(text != null && text.length() != 0);
|
||||
/*if (mentionsAdapter != null && text!=null ) {
|
||||
mentionsAdapter.searchUsernameOrHashtag(text.toString(), chatActivityEnterView.getCursorPosition(), messages);
|
||||
}*/
|
||||
if (waitingForCharaterEnterRunnable != null) {
|
||||
AndroidUtilities.cancelRunOnUIThread(waitingForCharaterEnterRunnable);
|
||||
waitingForCharaterEnterRunnable = null;
|
||||
}
|
||||
if( chatActivityEnterView.isMessageWebPageSearchEnabled() ) {
|
||||
if (bigChange) {
|
||||
searchLinks(text, true);
|
||||
} else {
|
||||
waitingForCharaterEnterRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (this == waitingForCharaterEnterRunnable) {
|
||||
searchLinks(text, false);
|
||||
waitingForCharaterEnterRunnable = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
AndroidUtilities.runOnUIThread(waitingForCharaterEnterRunnable, AndroidUtilities.WEB_URL == null ? 3000 : 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1333,92 +1306,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
return !(dialog == chatAttachAlert && PhotoViewer.getInstance().isVisible()) && super.dismissDialogOnPause(dialog);
|
||||
}
|
||||
|
||||
private void searchLinks(final CharSequence charSequence, final boolean force) {
|
||||
/*if (force && foundWebPage != null) {
|
||||
if (foundWebPage.url != null) {
|
||||
int index = TextUtils.indexOf(charSequence, foundWebPage.url);
|
||||
char lastChar = 0;
|
||||
boolean lenEqual = false;
|
||||
if (index == -1) {
|
||||
if (foundWebPage.display_url != null) {
|
||||
index = TextUtils.indexOf(charSequence, foundWebPage.display_url);
|
||||
lenEqual = index != -1 && index + foundWebPage.display_url.length() == charSequence.length();
|
||||
lastChar = index != -1 && !lenEqual ? charSequence.charAt(index + foundWebPage.display_url.length()) : 0;
|
||||
}
|
||||
} else {
|
||||
lenEqual = index + foundWebPage.url.length() == charSequence.length();
|
||||
lastChar = !lenEqual ? charSequence.charAt(index + foundWebPage.url.length()) : 0;
|
||||
}
|
||||
if (index != -1 && (lenEqual || lastChar == ' ' || lastChar == ',' || lastChar == '.' || lastChar == '!' || lastChar == '/')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
Utilities.searchQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (linkSearchRequestId != 0) {
|
||||
ConnectionsManager.getInstance().cancelRequest(linkSearchRequestId, true);
|
||||
linkSearchRequestId = 0;
|
||||
}
|
||||
ArrayList<CharSequence> urls = null;
|
||||
try {
|
||||
Matcher m = AndroidUtilities.WEB_URL.matcher(charSequence);
|
||||
while (m.find()) {
|
||||
if (m.start() > 0) {
|
||||
if (charSequence.charAt(m.start() - 1) == '@') {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (urls == null) {
|
||||
urls = new ArrayList<>();
|
||||
}
|
||||
urls.add(charSequence.subSequence(m.start(), m.end()));
|
||||
}
|
||||
if (urls != null && foundUrls != null && urls.size() == foundUrls.size()) {
|
||||
boolean clear = true;
|
||||
for (int a = 0; a < urls.size(); a++) {
|
||||
if (!TextUtils.equals(urls.get(a), foundUrls.get(a))) {
|
||||
clear = false;
|
||||
}
|
||||
}
|
||||
if (clear) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
foundUrls = urls;
|
||||
/*if (urls == null) {
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (foundWebPage != null) {
|
||||
foundWebPage = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}*/
|
||||
} catch (Exception e) {
|
||||
/*FileLog.e("messenger", e);
|
||||
String text = charSequence.toString().toLowerCase();
|
||||
if (charSequence.length() < 13 || !text.contains("http://") && !text.contains("https://")) {
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (foundWebPage != null) {
|
||||
foundWebPage = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}*/
|
||||
}
|
||||
|
||||
linkSearchRequestId = 0; // was: TL_messages_getWebPagePreview ...
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void moveScrollToLastMessage() {
|
||||
if( m_msglist.length > 0 ) {
|
||||
chatLayoutManager.scrollToPositionWithOffset(m_msglist.length - 1, -100000 - chatListView.getPaddingTop());
|
||||
|
||||
@@ -1186,10 +1186,6 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMessageWebPageSearchEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void hideRecordedAudioPanel() {
|
||||
audioToSendPath = null;
|
||||
audioToSend = null;
|
||||
|
||||
Reference in New Issue
Block a user