|
99 | 99 | import android.view.inspector.WindowInspector;
|
100 | 100 | import android.webkit.MimeTypeMap;
|
101 | 101 | import android.widget.EdgeEffect;
|
102 |
| -import android.widget.FrameLayout; |
103 | 102 | import android.widget.HorizontalScrollView;
|
104 | 103 | import android.widget.ImageView;
|
105 | 104 | import android.widget.LinearLayout;
|
|
123 | 122 |
|
124 | 123 | import com.android.internal.telephony.ITelephony;
|
125 | 124 | import com.google.android.exoplayer2.util.Consumer;
|
126 |
| -import com.google.android.exoplayer2.util.Log; |
127 | 125 | import com.google.android.gms.auth.api.phone.SmsRetriever;
|
128 | 126 | import com.google.android.gms.auth.api.phone.SmsRetrieverClient;
|
129 | 127 | import com.google.android.gms.tasks.Task;
|
|
155 | 153 | import org.telegram.ui.Components.PickerBottomLayout;
|
156 | 154 | import org.telegram.ui.Components.RecyclerListView;
|
157 | 155 | import org.telegram.ui.Components.ShareAlert;
|
158 |
| -import org.telegram.ui.Components.SizeNotifierFrameLayout; |
159 | 156 | import org.telegram.ui.Components.TypefaceSpan;
|
160 | 157 | import org.telegram.ui.Components.URLSpanReplacement;
|
161 | 158 | import org.telegram.ui.Components.UndoView;
|
|
177 | 174 | import java.io.InputStreamReader;
|
178 | 175 | import java.io.OutputStream;
|
179 | 176 | import java.io.RandomAccessFile;
|
180 |
| -import java.lang.ref.WeakReference; |
181 | 177 | import java.lang.reflect.Field;
|
182 | 178 | import java.lang.reflect.Method;
|
183 | 179 | import java.net.IDN;
|
|
196 | 192 | import java.util.List;
|
197 | 193 | import java.util.Locale;
|
198 | 194 | import java.util.Map;
|
199 |
| -import java.util.Objects; |
200 | 195 | import java.util.concurrent.CountDownLatch;
|
201 | 196 | import java.util.concurrent.atomic.AtomicBoolean;
|
202 | 197 | import java.util.concurrent.atomic.AtomicReference;
|
@@ -590,7 +585,7 @@ public static boolean findClickableView(ViewGroup container, float x, float y) {
|
590 | 585 | }
|
591 | 586 |
|
592 | 587 | public static void removeFromParent(View child) {
|
593 |
| - if (child.getParent() != null) { |
| 588 | + if (child != null && child.getParent() != null) { |
594 | 589 | ((ViewGroup) child.getParent()).removeView(child);
|
595 | 590 | }
|
596 | 591 | }
|
@@ -2750,6 +2745,39 @@ public static SpannableStringBuilder replaceTags(String str, int flag, Object...
|
2750 | 2745 | return new SpannableStringBuilder(str);
|
2751 | 2746 | }
|
2752 | 2747 |
|
| 2748 | + private static Pattern linksPattern; |
| 2749 | + public static SpannableStringBuilder replaceLinks(String str, Theme.ResourcesProvider resourcesProvider) { |
| 2750 | + if (linksPattern == null) { |
| 2751 | + linksPattern = Pattern.compile("\\[(.+?)\\]\\((.+?)\\)"); |
| 2752 | + } |
| 2753 | + SpannableStringBuilder spannable = new SpannableStringBuilder(); |
| 2754 | + Matcher matcher = linksPattern.matcher(str); |
| 2755 | + int lastMatchEnd = 0; |
| 2756 | + while (matcher.find()) { |
| 2757 | + spannable.append(str, lastMatchEnd, matcher.start()); |
| 2758 | + String linkText = matcher.group(1); |
| 2759 | + String url = matcher.group(2); |
| 2760 | + spannable.append(linkText); |
| 2761 | + int start = spannable.length() - linkText.length(); |
| 2762 | + int end = spannable.length(); |
| 2763 | + spannable.setSpan(new ClickableSpan() { |
| 2764 | + @Override |
| 2765 | + public void onClick(@NonNull View widget) { |
| 2766 | + Browser.openUrl(ApplicationLoader.applicationContext, url); |
| 2767 | + } |
| 2768 | + @Override |
| 2769 | + public void updateDrawState(@NonNull TextPaint ds) { |
| 2770 | + ds.setColor(Theme.getColor(Theme.key_chat_messageLinkIn, resourcesProvider)); |
| 2771 | + ds.setUnderlineText(false); |
| 2772 | + } |
| 2773 | + }, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 2774 | + |
| 2775 | + lastMatchEnd = matcher.end(); |
| 2776 | + } |
| 2777 | + spannable.append(str, lastMatchEnd, str.length()); |
| 2778 | + return spannable; |
| 2779 | + } |
| 2780 | + |
2753 | 2781 | public static class LinkMovementMethodMy extends LinkMovementMethod {
|
2754 | 2782 | @Override
|
2755 | 2783 | public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
|
@@ -5324,4 +5352,12 @@ public static String translitSafe(String str) {
|
5324 | 5352 | } catch (Exception ignore) {}
|
5325 | 5353 | return "";
|
5326 | 5354 | }
|
| 5355 | + |
| 5356 | + public static void quietSleep(long millis) { |
| 5357 | + try { |
| 5358 | + Thread.sleep(millis); |
| 5359 | + } catch (InterruptedException ignored) { |
| 5360 | + |
| 5361 | + } |
| 5362 | + } |
5327 | 5363 | }
|
0 commit comments