|
19 | 19 | import android.graphics.drawable.Drawable; |
20 | 20 | import android.os.Handler; |
21 | 21 | import android.os.Looper; |
| 22 | +import android.graphics.drawable.Drawable; |
| 23 | +import android.net.Uri; |
22 | 24 | import android.text.Spannable; |
| 25 | +import android.text.SpannableString; |
23 | 26 | import android.text.SpannableStringBuilder; |
24 | 27 | import android.text.Spanned; |
25 | 28 | import android.text.TextPaint; |
26 | 29 | import android.text.TextUtils; |
27 | 30 | import android.text.format.DateFormat; |
28 | 31 | import android.text.format.DateUtils; |
29 | | -import android.text.method.LinkMovementMethod; |
30 | 32 | import android.text.style.ClickableSpan; |
31 | 33 | import android.text.style.ForegroundColorSpan; |
32 | 34 | import android.text.style.StyleSpan; |
|
37 | 39 | import android.widget.LinearLayout; |
38 | 40 | import android.widget.TextView; |
39 | 41 |
|
| 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; |
40 | 49 | import com.google.android.material.chip.ChipDrawable; |
41 | 50 | import com.nextcloud.client.account.CurrentAccountProvider; |
42 | 51 | import com.nextcloud.client.network.ClientFactory; |
43 | 52 | import com.nextcloud.common.NextcloudClient; |
| 53 | +import com.nextcloud.utils.text.Spans; |
44 | 54 | import com.nextcloud.utils.GlideHelper; |
45 | 55 | import com.nextcloud.utils.text.Spans; |
46 | 56 | import com.owncloud.android.MainApp; |
|
62 | 72 | import java.util.List; |
63 | 73 | import java.util.Locale; |
64 | 74 | import java.util.Optional; |
| 75 | +import java.util.regex.Matcher; |
| 76 | +import java.util.regex.Pattern; |
65 | 77 |
|
66 | 78 | import androidx.annotation.NonNull; |
| 79 | +import androidx.annotation.XmlRes; |
67 | 80 | import androidx.recyclerview.widget.RecyclerView; |
68 | 81 | import third_parties.fresco.BetterImageSpan; |
69 | 82 |
|
@@ -320,6 +333,74 @@ private ChipDrawable getDrawableForMentionChipSpan(int chipResource, String text |
320 | 333 | return chip; |
321 | 334 | } |
322 | 335 |
|
| 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 | + |
323 | 404 | private SpannableStringBuilder addClickablePart(RichElement richElement) { |
324 | 405 | String text = richElement.getRichSubject(); |
325 | 406 | SpannableStringBuilder ssb = new SpannableStringBuilder(text); |
|
0 commit comments