View links to statuses inside Tusky (#568)

* View links to statuses inside Tusky

* Only attempt to open links that look like mastodon statuses

* Add support for pleroma statuses

* Move "smells like mastodon" url check to click handler

* Add bottom sheet to notify users of post query status

* Improve architecture for managing search status

* Push everything into SFragment

* Add external lookup for non-locally-resolved account links

* Clean up copypasta from LinkHelper.setClickableText

* Apply PR feedback

* Migrate bottom sheet wrappers to CoordinatorLayout
This commit is contained in:
Levi Bard 2018-04-25 20:04:55 +02:00 committed by Konrad Pozniak
commit 76eae44324
13 changed files with 257 additions and 58 deletions

View file

@ -0,0 +1,11 @@
package com.keylesspalace.tusky.util
import android.text.TextPaint
import android.text.style.ClickableSpan
abstract class ClickableSpanNoUnderline : ClickableSpan() {
override fun updateDrawState(ds: TextPaint?) {
super.updateDrawState(ds)
ds?.isUnderlineText = false;
}
}

View file

@ -74,20 +74,14 @@ public class LinkHelper {
int end = builder.getSpanEnd(span);
int flags = builder.getSpanFlags(span);
CharSequence text = builder.subSequence(start, end);
ClickableSpan customSpan = null;
if (text.charAt(0) == '#') {
final String tag = text.subSequence(1, text.length()).toString();
ClickableSpan newSpan = new ClickableSpan() {
customSpan = new ClickableSpanNoUnderline() {
@Override
public void onClick(View widget) {
listener.onViewTag(tag);
}
@Override public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
public void onClick(View widget) { listener.onViewTag(tag); }
};
builder.removeSpan(span);
builder.setSpan(newSpan, start, end, flags);
} else if (text.charAt(0) == '@' && mentions != null && mentions.length > 0) {
String accountUsername = text.subSequence(1, text.length()).toString();
/* There may be multiple matches for users on different instances with the same
@ -104,28 +98,23 @@ public class LinkHelper {
}
if (id != null) {
final String accountId = id;
ClickableSpan newSpan = new ClickableSpan() {
customSpan = new ClickableSpanNoUnderline() {
@Override
public void onClick(View widget) {
listener.onViewAccount(accountId);
}
@Override public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
public void onClick(View widget) { listener.onViewAccount(accountId); }
};
builder.removeSpan(span);
builder.setSpan(newSpan, start, end, flags);
} else {
ClickableSpan newSpan = new CustomURLSpan(span.getURL());
builder.removeSpan(span);
builder.setSpan(newSpan, start, end, flags);
}
} else {
ClickableSpan newSpan = new CustomURLSpan(span.getURL());
builder.removeSpan(span);
builder.setSpan(newSpan, start, end, flags);
}
if (customSpan == null) {
customSpan = new CustomURLSpan(span.getURL()) {
@Override
public void onClick(View widget) {
listener.onViewURL(getURL());
}
};
}
builder.removeSpan(span);
builder.setSpan(customSpan, start, end, flags);
}
view.setText(builder);
view.setLinksClickable(true);