parent
4677cef580
commit
8455dc7bd2
|
@ -150,7 +150,7 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
||||||
v.removeCallbacks(longClickRunnable);
|
v.removeCallbacks(longClickRunnable);
|
||||||
v.animate().scaleX(1).scaleY(1).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(150).start();
|
v.animate().scaleX(1).scaleY(1).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(150).start();
|
||||||
if (disabled) return true;
|
if (disabled) return true;
|
||||||
if (action == MotionEvent.ACTION_UP && eventDuration < ViewConfiguration.getLongPressTimeout()) v.performClick();
|
if (action == MotionEvent.ACTION_UP && eventDuration <= ViewConfiguration.getLongPressTimeout()) v.performClick();
|
||||||
else v.startAnimation(opacityIn);
|
else v.startAnimation(opacityIn);
|
||||||
} else if (action == MotionEvent.ACTION_DOWN) {
|
} else if (action == MotionEvent.ACTION_DOWN) {
|
||||||
touchingView = v;
|
touchingView = v;
|
||||||
|
|
|
@ -10,6 +10,8 @@ import android.text.Layout;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.SoundEffectConstants;
|
import android.view.SoundEffectConstants;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewConfiguration;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import me.grishka.appkit.utils.V;
|
import me.grishka.appkit.utils.V;
|
||||||
|
@ -21,6 +23,10 @@ public class ClickableLinksDelegate {
|
||||||
private LinkSpan selectedSpan;
|
private LinkSpan selectedSpan;
|
||||||
private TextView view;
|
private TextView view;
|
||||||
|
|
||||||
|
private final Runnable longClickRunnable = () -> {
|
||||||
|
if (selectedSpan != null) selectedSpan.onLongClick(view.getContext());
|
||||||
|
};
|
||||||
|
|
||||||
public ClickableLinksDelegate(TextView view) {
|
public ClickableLinksDelegate(TextView view) {
|
||||||
this.view=view;
|
this.view=view;
|
||||||
hlPaint=new Paint();
|
hlPaint=new Paint();
|
||||||
|
@ -30,6 +36,7 @@ public class ClickableLinksDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onTouch(MotionEvent event) {
|
public boolean onTouch(MotionEvent event) {
|
||||||
|
long eventDuration = event.getEventTime() - event.getDownTime();
|
||||||
if(event.getAction()==MotionEvent.ACTION_DOWN){
|
if(event.getAction()==MotionEvent.ACTION_DOWN){
|
||||||
int line=-1;
|
int line=-1;
|
||||||
Rect rect=new Rect();
|
Rect rect=new Rect();
|
||||||
|
@ -63,6 +70,7 @@ public class ClickableLinksDelegate {
|
||||||
}
|
}
|
||||||
hlPath=new Path();
|
hlPath=new Path();
|
||||||
selectedSpan=span;
|
selectedSpan=span;
|
||||||
|
view.postDelayed(longClickRunnable, ViewConfiguration.getLongPressTimeout());
|
||||||
hlPaint.setColor((span.getColor() & 0x00FFFFFF) | 0x33000000);
|
hlPaint.setColor((span.getColor() & 0x00FFFFFF) | 0x33000000);
|
||||||
//l.getSelectionPath(start, end, hlPath);
|
//l.getSelectionPath(start, end, hlPath);
|
||||||
for(int j=lstart;j<=lend;j++){
|
for(int j=lstart;j<=lend;j++){
|
||||||
|
@ -90,8 +98,11 @@ public class ClickableLinksDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(event.getAction()==MotionEvent.ACTION_UP && selectedSpan!=null){
|
if(event.getAction()==MotionEvent.ACTION_UP && selectedSpan!=null){
|
||||||
|
if (eventDuration <= ViewConfiguration.getLongPressTimeout()) {
|
||||||
view.playSoundEffect(SoundEffectConstants.CLICK);
|
view.playSoundEffect(SoundEffectConstants.CLICK);
|
||||||
selectedSpan.onClick(view.getContext());
|
selectedSpan.onClick(view.getContext());
|
||||||
|
}
|
||||||
|
view.removeCallbacks(longClickRunnable);
|
||||||
hlPath=null;
|
hlPath=null;
|
||||||
selectedSpan=null;
|
selectedSpan=null;
|
||||||
view.invalidate();
|
view.invalidate();
|
||||||
|
@ -100,6 +111,7 @@ public class ClickableLinksDelegate {
|
||||||
if(event.getAction()==MotionEvent.ACTION_CANCEL){
|
if(event.getAction()==MotionEvent.ACTION_CANCEL){
|
||||||
hlPath=null;
|
hlPath=null;
|
||||||
selectedSpan=null;
|
selectedSpan=null;
|
||||||
|
view.removeCallbacks(longClickRunnable);
|
||||||
view.invalidate();
|
view.invalidate();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,8 +117,8 @@ public class HtmlParser{
|
||||||
case "a" -> {
|
case "a" -> {
|
||||||
String href=el.attr("href");
|
String href=el.attr("href");
|
||||||
LinkSpan.Type linkType;
|
LinkSpan.Type linkType;
|
||||||
if(el.hasClass("hashtag")){
|
|
||||||
String text=el.text();
|
String text=el.text();
|
||||||
|
if(el.hasClass("hashtag")){
|
||||||
if(text.startsWith("#")){
|
if(text.startsWith("#")){
|
||||||
linkType=LinkSpan.Type.HASHTAG;
|
linkType=LinkSpan.Type.HASHTAG;
|
||||||
href=text.substring(1);
|
href=text.substring(1);
|
||||||
|
@ -136,7 +136,7 @@ public class HtmlParser{
|
||||||
}else{
|
}else{
|
||||||
linkType=LinkSpan.Type.URL;
|
linkType=LinkSpan.Type.URL;
|
||||||
}
|
}
|
||||||
openSpans.add(new SpanInfo(new LinkSpan(href, null, linkType, accountID), ssb.length(), el));
|
openSpans.add(new SpanInfo(new LinkSpan(href, null, linkType, accountID, text), ssb.length(), el));
|
||||||
}
|
}
|
||||||
case "br" -> ssb.append('\n');
|
case "br" -> ssb.append('\n');
|
||||||
case "span" -> {
|
case "span" -> {
|
||||||
|
@ -260,7 +260,7 @@ public class HtmlParser{
|
||||||
String url=matcher.group(3);
|
String url=matcher.group(3);
|
||||||
if(TextUtils.isEmpty(matcher.group(4)))
|
if(TextUtils.isEmpty(matcher.group(4)))
|
||||||
url="http://"+url;
|
url="http://"+url;
|
||||||
ssb.setSpan(new LinkSpan(url, null, LinkSpan.Type.URL, null), matcher.start(3), matcher.end(3), 0);
|
ssb.setSpan(new LinkSpan(url, null, LinkSpan.Type.URL, null, url), matcher.start(3), matcher.end(3), 0);
|
||||||
}while(matcher.find()); // Find more URLs
|
}while(matcher.find()); // Find more URLs
|
||||||
return ssb;
|
return ssb;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,14 @@ public class LinkSpan extends CharacterStyle {
|
||||||
private String link;
|
private String link;
|
||||||
private Type type;
|
private Type type;
|
||||||
private String accountID;
|
private String accountID;
|
||||||
|
private String text;
|
||||||
|
|
||||||
public LinkSpan(String link, OnLinkClickListener listener, Type type, String accountID){
|
public LinkSpan(String link, OnLinkClickListener listener, Type type, String accountID, String text){
|
||||||
this.listener=listener;
|
this.listener=listener;
|
||||||
this.link=link;
|
this.link=link;
|
||||||
this.type=type;
|
this.type=type;
|
||||||
this.accountID=accountID;
|
this.accountID=accountID;
|
||||||
|
this.text=text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColor(){
|
public int getColor(){
|
||||||
|
@ -38,6 +40,10 @@ public class LinkSpan extends CharacterStyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onLongClick(Context context) {
|
||||||
|
UiUtils.copyText(context, getType() == Type.URL ? link : text);
|
||||||
|
}
|
||||||
|
|
||||||
public String getLink(){
|
public String getLink(){
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue