|
@@ -68,6 +68,7 @@ import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
|
import java.text.DateFormat;
|
|
import java.text.DateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.Objects;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
@@ -168,12 +169,14 @@ public class DisplayUtils {
|
|
|
|
|
|
public static Drawable getDrawableForMentionChipSpan(Context context,
|
|
public static Drawable getDrawableForMentionChipSpan(Context context,
|
|
String id,
|
|
String id,
|
|
|
|
+ String roomToken,
|
|
CharSequence label,
|
|
CharSequence label,
|
|
User conversationUser,
|
|
User conversationUser,
|
|
String type,
|
|
String type,
|
|
@XmlRes int chipResource,
|
|
@XmlRes int chipResource,
|
|
@Nullable EditText emojiEditText,
|
|
@Nullable EditText emojiEditText,
|
|
- ViewThemeUtils viewThemeUtils) {
|
|
|
|
|
|
+ ViewThemeUtils viewThemeUtils,
|
|
|
|
+ Boolean isFederated) {
|
|
ChipDrawable chip = ChipDrawable.createFromResource(context, chipResource);
|
|
ChipDrawable chip = ChipDrawable.createFromResource(context, chipResource);
|
|
chip.setText(EmojiCompat.get().process(label));
|
|
chip.setText(EmojiCompat.get().process(label));
|
|
chip.setEllipsize(TextUtils.TruncateAt.MIDDLE);
|
|
chip.setEllipsize(TextUtils.TruncateAt.MIDDLE);
|
|
@@ -205,13 +208,21 @@ public class DisplayUtils {
|
|
chip.setBounds(0, 0, chip.getIntrinsicWidth(), chip.getIntrinsicHeight());
|
|
chip.setBounds(0, 0, chip.getIntrinsicWidth(), chip.getIntrinsicHeight());
|
|
|
|
|
|
if (!isCallOrGroup) {
|
|
if (!isCallOrGroup) {
|
|
- String url = ApiUtils.getUrlForAvatar(conversationUser.getBaseUrl(), id, true);
|
|
|
|
|
|
+ String url = ApiUtils.getUrlForAvatar(conversationUser.getBaseUrl(), id, false);
|
|
if ("guests".equals(type) || "guest".equals(type)) {
|
|
if ("guests".equals(type) || "guest".equals(type)) {
|
|
url = ApiUtils.getUrlForGuestAvatar(
|
|
url = ApiUtils.getUrlForGuestAvatar(
|
|
conversationUser.getBaseUrl(),
|
|
conversationUser.getBaseUrl(),
|
|
String.valueOf(label), true);
|
|
String.valueOf(label), true);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (isFederated) {
|
|
|
|
+ int darkTheme = (DisplayUtils.isDarkModeOn(context))? 1 : 0;
|
|
|
|
+ url = ApiUtils.getUrlForFederatedAvatar(Objects.requireNonNull(conversationUser.getBaseUrl()),
|
|
|
|
+ roomToken, id,
|
|
|
|
+ darkTheme, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
ImageRequest imageRequest = new ImageRequest.Builder(context)
|
|
ImageRequest imageRequest = new ImageRequest.Builder(context)
|
|
.data(url)
|
|
.data(url)
|
|
.crossfade(true)
|
|
.crossfade(true)
|
|
@@ -224,13 +235,12 @@ public class DisplayUtils {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void onError(@Nullable Drawable drawable) {
|
|
public void onError(@Nullable Drawable drawable) {
|
|
-
|
|
|
|
|
|
+ chip.setChipIcon(drawable);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void onSuccess(@NonNull Drawable drawable) {
|
|
public void onSuccess(@NonNull Drawable drawable) {
|
|
chip.setChipIcon(drawable);
|
|
chip.setChipIcon(drawable);
|
|
-
|
|
|
|
// A hack to refresh the chip icon
|
|
// A hack to refresh the chip icon
|
|
if (emojiEditText != null) {
|
|
if (emojiEditText != null) {
|
|
emojiEditText.post(() -> emojiEditText.setTextKeepState(
|
|
emojiEditText.post(() -> emojiEditText.setTextKeepState(
|
|
@@ -248,10 +258,12 @@ public class DisplayUtils {
|
|
}
|
|
}
|
|
|
|
|
|
public static Spannable searchAndReplaceWithMentionSpan(String key, Context context, Spanned text,
|
|
public static Spannable searchAndReplaceWithMentionSpan(String key, Context context, Spanned text,
|
|
- String id, String label, String type,
|
|
|
|
|
|
+ String id, String roomToken,
|
|
|
|
+ String label, String type,
|
|
User conversationUser,
|
|
User conversationUser,
|
|
@XmlRes int chipXmlRes,
|
|
@XmlRes int chipXmlRes,
|
|
- ViewThemeUtils viewThemeUtils) {
|
|
|
|
|
|
+ ViewThemeUtils viewThemeUtils,
|
|
|
|
+ Boolean isFederated) {
|
|
|
|
|
|
Spannable spannableString = new SpannableString(text);
|
|
Spannable spannableString = new SpannableString(text);
|
|
String stringText = text.toString();
|
|
String stringText = text.toString();
|
|
@@ -267,7 +279,7 @@ public class DisplayUtils {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- int lastStartIndex = -1;
|
|
|
|
|
|
+ int lastStartIndex = 0;
|
|
Spans.MentionChipSpan mentionChipSpan;
|
|
Spans.MentionChipSpan mentionChipSpan;
|
|
while (m.find()) {
|
|
while (m.find()) {
|
|
int start = stringText.indexOf(m.group(), lastStartIndex);
|
|
int start = stringText.indexOf(m.group(), lastStartIndex);
|
|
@@ -276,13 +288,14 @@ public class DisplayUtils {
|
|
|
|
|
|
Drawable drawableForChip = DisplayUtils.getDrawableForMentionChipSpan(context,
|
|
Drawable drawableForChip = DisplayUtils.getDrawableForMentionChipSpan(context,
|
|
id,
|
|
id,
|
|
|
|
+ roomToken,
|
|
label,
|
|
label,
|
|
conversationUser,
|
|
conversationUser,
|
|
type,
|
|
type,
|
|
chipXmlRes,
|
|
chipXmlRes,
|
|
null,
|
|
null,
|
|
- viewThemeUtils);
|
|
|
|
-
|
|
|
|
|
|
+ viewThemeUtils,
|
|
|
|
+ isFederated);
|
|
mentionChipSpan = new Spans.MentionChipSpan(drawableForChip,
|
|
mentionChipSpan = new Spans.MentionChipSpan(drawableForChip,
|
|
BetterImageSpan.ALIGN_CENTER,
|
|
BetterImageSpan.ALIGN_CENTER,
|
|
id,
|
|
id,
|