Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky
2025-04-16 10:43:05 +02:00
parent 1791ce9f44
commit cd3eeb1835
3 changed files with 27 additions and 14 deletions

View File

@ -21,11 +21,11 @@ import android.net.Uri;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
@ -159,9 +159,9 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
if (!TextUtils.isEmpty(activity.getRichSubjectElement().getRichSubject())) {
activityViewHolder.binding.subject.setVisibility(View.VISIBLE);
activityViewHolder.binding.subject.setMovementMethod(LinkMovementMethod.getInstance());
activityViewHolder.binding.subject.setText(addClickablePart(activity.getRichSubjectElement()),
TextView.BufferType.SPANNABLE);
// activityViewHolder.binding.subject.setMovementMethod(LinkMovementMethod.getInstance());
// activityViewHolder.binding.subject.setText(addClickablePart(activity.getRichSubjectElement()),
// TextView.BufferType.SPANNABLE);
activityViewHolder.binding.subject.setText(searchAndReplaceWithMentionSpan("actor",
activity.getRichSubjectElement().getRichSubject(),
@ -308,7 +308,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
*
* @return Spannable
*/
private Spannable searchAndReplaceWithMentionSpan(
private Spanned searchAndReplaceWithMentionSpan(
String key,
String text,
String id,
@ -334,8 +334,11 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
int end = start + m.group().length();
lastStartIndex = end;
Drawable drawableForChip = getDrawableForMentionChipSpan(
chipXmlRes
chipXmlRes,
label
);
mentionChipSpan = new Spans.MentionChipSpan(
drawableForChip,
BetterImageSpan.ALIGN_CENTER,
@ -358,8 +361,14 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
return spannableString;
}
private Drawable getDrawableForMentionChipSpan(int chipResource) {
return ChipDrawable.createFromResource(context, chipResource);
private Drawable getDrawableForMentionChipSpan(int chipResource, String text) {
ChipDrawable chip = ChipDrawable.createFromResource(context, chipResource);
chip.setEllipsize(TextUtils.TruncateAt.MIDDLE);
chip.setText(text);
chip.setChipIconResource(R.drawable.accent_circle);
chip.setBounds(0, 0, chip.getIntrinsicWidth(), chip.getIntrinsicHeight());
return chip;
}
private SpannableStringBuilder addClickablePart(RichElement richElement) {

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Nextcloud Talk - Android Client
~
~ SPDX-FileCopyrightText: 2017-2018 Mario Danic <mario@lovelyhq.com>
~ SPDX-License-Identifier: GPL-3.0-or-later
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/colorPrimary" />
</shape>

View File

@ -36,12 +36,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.chip.Chip
android:id="@+id/chip"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="username" />
<TextView
android:id="@+id/subject"
android:layout_width="wrap_content"