NekoX/TMessagesProj/src/main/java/org/telegram/ui/Components/URLSpanReplacement.java

60 lines
1.6 KiB
Java
Raw Normal View History

2015-09-02 00:14:21 +02:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
2015-09-02 00:14:21 +02:00
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov, 2013-2018.
2015-09-02 00:14:21 +02:00
*/
package org.telegram.ui.Components;
2018-07-30 04:07:02 +02:00
import android.net.Uri;
2019-07-18 15:01:39 +02:00
import android.text.TextPaint;
2015-09-02 00:14:21 +02:00
import android.text.style.URLSpan;
2018-07-30 04:07:02 +02:00
import android.view.View;
import org.telegram.messenger.browser.Browser;
2022-06-21 04:51:00 +02:00
import org.telegram.ui.LaunchActivity;
2015-09-02 00:14:21 +02:00
public class URLSpanReplacement extends URLSpan {
2019-07-18 15:01:39 +02:00
private TextStyleSpan.TextStyleRun style;
2022-06-21 04:51:00 +02:00
private boolean navigateToPremiumBot;
2019-07-18 15:01:39 +02:00
2015-09-02 00:14:21 +02:00
public URLSpanReplacement(String url) {
2019-07-18 15:01:39 +02:00
this(url, null);
}
public URLSpanReplacement(String url, TextStyleSpan.TextStyleRun run) {
2019-08-22 01:53:26 +02:00
super(url != null ? url.replace('\u202E', ' ') : url);
2019-07-18 15:01:39 +02:00
style = run;
}
2022-06-21 04:51:00 +02:00
public void setNavigateToPremiumBot(boolean navigateToPremiumBot) {
this.navigateToPremiumBot = navigateToPremiumBot;
}
2019-07-18 15:01:39 +02:00
public TextStyleSpan.TextStyleRun getTextStyleRun() {
return style;
2015-09-02 00:14:21 +02:00
}
2018-07-30 04:07:02 +02:00
@Override
public void onClick(View widget) {
2022-06-21 04:51:00 +02:00
if (navigateToPremiumBot && widget.getContext() instanceof LaunchActivity) {
((LaunchActivity) widget.getContext()).setNavigateToPremiumBot(true);
}
2018-07-30 04:07:02 +02:00
Uri uri = Uri.parse(getURL());
Browser.openUrl(widget.getContext(), uri);
}
2019-07-18 15:01:39 +02:00
@Override
public void updateDrawState(TextPaint p) {
2019-12-31 14:08:08 +01:00
int color = p.getColor();
2019-07-18 15:01:39 +02:00
super.updateDrawState(p);
if (style != null) {
style.applyStyle(p);
2019-12-31 14:08:08 +01:00
p.setUnderlineText(p.linkColor == color);
2019-07-18 15:01:39 +02:00
}
}
2015-09-02 00:14:21 +02:00
}