Skip to content

Commit b0b7627

Browse files
Merge remote-tracking branch 'origin/showAvatars' into showAvatars
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
2 parents cc5f560 + cd3eeb1 commit b0b7627

File tree

2 files changed

+92
-13
lines changed

2 files changed

+92
-13
lines changed

app/src/main/java/com/owncloud/android/ui/adapter/ActivityListAdapter.java

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
import android.graphics.drawable.Drawable;
2020
import android.os.Handler;
2121
import android.os.Looper;
22+
import android.graphics.drawable.Drawable;
23+
import android.net.Uri;
2224
import android.text.Spannable;
25+
import android.text.SpannableString;
2326
import android.text.SpannableStringBuilder;
2427
import android.text.Spanned;
2528
import android.text.TextPaint;
2629
import android.text.TextUtils;
2730
import android.text.format.DateFormat;
2831
import android.text.format.DateUtils;
29-
import android.text.method.LinkMovementMethod;
3032
import android.text.style.ClickableSpan;
3133
import android.text.style.ForegroundColorSpan;
3234
import android.text.style.StyleSpan;
@@ -37,10 +39,18 @@
3739
import android.widget.LinearLayout;
3840
import android.widget.TextView;
3941

42+
import com.bumptech.glide.GenericRequestBuilder;
43+
import com.bumptech.glide.Glide;
44+
import com.bumptech.glide.load.engine.DiskCacheStrategy;
45+
import com.bumptech.glide.load.model.StreamEncoder;
46+
import com.bumptech.glide.load.resource.file.FileToStreamDecoder;
47+
import com.caverock.androidsvg.SVG;
48+
import com.google.android.material.chip.ChipDrawable;
4049
import com.google.android.material.chip.ChipDrawable;
4150
import com.nextcloud.client.account.CurrentAccountProvider;
4251
import com.nextcloud.client.network.ClientFactory;
4352
import com.nextcloud.common.NextcloudClient;
53+
import com.nextcloud.utils.text.Spans;
4454
import com.nextcloud.utils.GlideHelper;
4555
import com.nextcloud.utils.text.Spans;
4656
import com.owncloud.android.MainApp;
@@ -62,8 +72,11 @@
6272
import java.util.List;
6373
import java.util.Locale;
6474
import java.util.Optional;
75+
import java.util.regex.Matcher;
76+
import java.util.regex.Pattern;
6577

6678
import androidx.annotation.NonNull;
79+
import androidx.annotation.XmlRes;
6780
import androidx.recyclerview.widget.RecyclerView;
6881
import third_parties.fresco.BetterImageSpan;
6982

@@ -320,6 +333,74 @@ private ChipDrawable getDrawableForMentionChipSpan(int chipResource, String text
320333
return chip;
321334
}
322335

336+
/**
337+
* c&p from Talk: DisplayUtils:227
338+
*
339+
* @return Spannable
340+
*/
341+
private Spanned searchAndReplaceWithMentionSpan(
342+
String key,
343+
String text,
344+
String id,
345+
String label,
346+
@XmlRes int chipXmlRes) {
347+
Spannable spannableString = new SpannableString(text);
348+
String stringText = text.toString();
349+
String keyWithBrackets = "{" + key + "}";
350+
Matcher m = Pattern.compile(keyWithBrackets, Pattern.CASE_INSENSITIVE | Pattern.LITERAL | Pattern.MULTILINE)
351+
.matcher(spannableString);
352+
ClickableSpan clickableSpan = new ClickableSpan() {
353+
@Override
354+
public void onClick(@NonNull View view) {
355+
//EventBus.getDefault().post(new UserMentionClickEvent(id));
356+
}
357+
};
358+
359+
int lastStartIndex = 0;
360+
Spans.MentionChipSpan mentionChipSpan;
361+
362+
while (m.find()) {
363+
int start = stringText.indexOf(m.group(), lastStartIndex);
364+
int end = start + m.group().length();
365+
lastStartIndex = end;
366+
Drawable drawableForChip = getDrawableForMentionChipSpan(
367+
chipXmlRes,
368+
label
369+
);
370+
371+
372+
mentionChipSpan = new Spans.MentionChipSpan(
373+
drawableForChip,
374+
BetterImageSpan.ALIGN_CENTER,
375+
id,
376+
label
377+
);
378+
spannableString.setSpan(mentionChipSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
379+
// if (chipXmlRes == R.xml.chip_you) {
380+
// spannableString.setSpan(
381+
// viewThemeUtils.talk.themeForegroundColorSpan(context),
382+
// start,
383+
// end,
384+
// Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
385+
// );
386+
// }
387+
// if ("user" == type && conversationUser.userId != id && !isFederated) {
388+
// spannableString.setSpan(clickableSpan, start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
389+
// }
390+
}
391+
return spannableString;
392+
}
393+
394+
private Drawable getDrawableForMentionChipSpan(int chipResource, String text) {
395+
ChipDrawable chip = ChipDrawable.createFromResource(context, chipResource);
396+
chip.setEllipsize(TextUtils.TruncateAt.MIDDLE);
397+
chip.setText(text);
398+
chip.setChipIconResource(R.drawable.accent_circle);
399+
chip.setBounds(0, 0, chip.getIntrinsicWidth(), chip.getIntrinsicHeight());
400+
401+
return chip;
402+
}
403+
323404
private SpannableStringBuilder addClickablePart(RichElement richElement) {
324405
String text = richElement.getRichSubject();
325406
SpannableStringBuilder ssb = new SpannableStringBuilder(text);

app/src/main/java/third_parties/fresco/BetterImageSpan.kt renamed to app/src/main/kotlin/thirdparties/fresco/BetterImageSpan.kt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* SPDX-License-Identifier: AGPL-3.0-or-later
66
*/
77

8-
package third_parties.fresco
8+
package thirdParties.fresco
99

1010
import android.graphics.Canvas
1111
import android.graphics.Paint
@@ -98,18 +98,16 @@ open class BetterImageSpan @JvmOverloads constructor(
9898
mHeight = mBounds!!.height()
9999
}
100100

101-
private fun getOffsetAboveBaseline(fm: Paint.FontMetricsInt): Int {
102-
return when (mAlignment) {
103-
ALIGN_BOTTOM -> fm.descent - mHeight
104-
ALIGN_CENTER -> {
105-
val textHeight = fm.descent - fm.ascent
106-
val offset = (textHeight - mHeight) / 2
107-
fm.ascent + offset
108-
}
109-
110-
ALIGN_BASELINE -> -mHeight
111-
else -> -mHeight
101+
private fun getOffsetAboveBaseline(fm: Paint.FontMetricsInt): Int = when (mAlignment) {
102+
ALIGN_BOTTOM -> fm.descent - mHeight
103+
ALIGN_CENTER -> {
104+
val textHeight = fm.descent - fm.ascent
105+
val offset = (textHeight - mHeight) / 2
106+
fm.ascent + offset
112107
}
108+
109+
ALIGN_BASELINE -> -mHeight
110+
else -> -mHeight
113111
}
114112

115113
companion object {

0 commit comments

Comments
 (0)