Open profiles from mentions
This commit is contained in:
@@ -69,7 +69,7 @@ public abstract class StatusDisplayItem{
|
||||
}
|
||||
items.add(new HeaderStatusDisplayItem(parentID, statusForContent.account, statusForContent.createdAt, fragment, accountID));
|
||||
if(!TextUtils.isEmpty(statusForContent.content))
|
||||
items.add(new TextStatusDisplayItem(parentID, HtmlParser.parse(statusForContent.content, statusForContent.emojis), fragment));
|
||||
items.add(new TextStatusDisplayItem(parentID, HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, accountID), fragment));
|
||||
int photoIndex=0;
|
||||
int totalPhotos=0;
|
||||
for(Attachment attachment:statusForContent.mediaAttachments){
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.text.Spanned;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.joinmastodon.android.model.Emoji;
|
||||
import org.joinmastodon.android.model.Mention;
|
||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -40,7 +41,7 @@ public class HtmlParser{
|
||||
* @param emojis Custom emojis that are present in source as <code>:code:</code>
|
||||
* @return a spanned string
|
||||
*/
|
||||
public static SpannableStringBuilder parse(String source, List<Emoji> emojis){
|
||||
public static SpannableStringBuilder parse(String source, List<Emoji> emojis, List<Mention> mentions, String accountID){
|
||||
class SpanInfo{
|
||||
public Object span;
|
||||
public int start;
|
||||
@@ -53,6 +54,8 @@ public class HtmlParser{
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> idsByUrl=mentions.stream().collect(Collectors.toMap(m->m.url, m->m.id));
|
||||
|
||||
final SpannableStringBuilder ssb=new SpannableStringBuilder();
|
||||
Jsoup.parseBodyFragment(source).body().traverse(new NodeVisitor(){
|
||||
private final ArrayList<SpanInfo> openSpans=new ArrayList<>();
|
||||
@@ -65,15 +68,22 @@ public class HtmlParser{
|
||||
Element el=(Element)node;
|
||||
switch(el.nodeName()){
|
||||
case "a" -> {
|
||||
String href=el.attr("href");
|
||||
LinkSpan.Type linkType;
|
||||
if(el.hasClass("hashtag")){
|
||||
linkType=LinkSpan.Type.HASHTAG;
|
||||
}else if(el.hasClass("mention")){
|
||||
linkType=LinkSpan.Type.MENTION;
|
||||
String id=idsByUrl.get(href);
|
||||
if(id!=null){
|
||||
linkType=LinkSpan.Type.MENTION;
|
||||
href=id;
|
||||
}else{
|
||||
linkType=LinkSpan.Type.URL;
|
||||
}
|
||||
}else{
|
||||
linkType=LinkSpan.Type.URL;
|
||||
}
|
||||
openSpans.add(new SpanInfo(new LinkSpan(el.attr("href"), null, linkType), ssb.length(), el));
|
||||
openSpans.add(new SpanInfo(new LinkSpan(href, null, linkType, accountID), ssb.length(), el));
|
||||
}
|
||||
case "br" -> ssb.append('\n');
|
||||
case "span" -> {
|
||||
|
||||
@@ -13,11 +13,13 @@ public class LinkSpan extends CharacterStyle {
|
||||
private OnLinkClickListener listener;
|
||||
private String link;
|
||||
private Type type;
|
||||
private String accountID;
|
||||
|
||||
public LinkSpan(String link, OnLinkClickListener listener, Type type) {
|
||||
public LinkSpan(String link, OnLinkClickListener listener, Type type, String accountID){
|
||||
this.listener=listener;
|
||||
this.link=link;
|
||||
this.type=type;
|
||||
this.accountID=accountID;
|
||||
}
|
||||
|
||||
public void setColor(int c){
|
||||
@@ -36,7 +38,8 @@ public class LinkSpan extends CharacterStyle {
|
||||
public void onClick(Context context){
|
||||
switch(getType()){
|
||||
case URL -> UiUtils.launchWebBrowser(context, link);
|
||||
case HASHTAG, MENTION -> Toast.makeText(context, "Not implemented yet", Toast.LENGTH_SHORT).show();
|
||||
case MENTION -> UiUtils.openProfileByID(context, accountID, link);
|
||||
case HASHTAG -> Toast.makeText(context, "Not implemented yet", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package org.joinmastodon.android.ui.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.OpenableColumns;
|
||||
@@ -17,6 +19,7 @@ import android.widget.TextView;
|
||||
|
||||
import org.joinmastodon.android.MastodonApp;
|
||||
import org.joinmastodon.android.R;
|
||||
import org.joinmastodon.android.fragments.ProfileFragment;
|
||||
import org.joinmastodon.android.model.Emoji;
|
||||
import org.joinmastodon.android.ui.text.CustomEmojiSpan;
|
||||
|
||||
@@ -29,6 +32,7 @@ import java.util.stream.Collectors;
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
import me.grishka.appkit.Nav;
|
||||
import me.grishka.appkit.imageloader.ViewImageLoader;
|
||||
import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest;
|
||||
import me.grishka.appkit.utils.V;
|
||||
@@ -161,4 +165,11 @@ public class UiUtils{
|
||||
ta.recycle();
|
||||
return color;
|
||||
}
|
||||
|
||||
public static void openProfileByID(Context context, String selfID, String id){
|
||||
Bundle args=new Bundle();
|
||||
args.putString("account", selfID);
|
||||
args.putString("profileAccountID", id);
|
||||
Nav.go((Activity)context, ProfileFragment.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user