From 759099208305f0656cdd3601e545e631725cb131 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Tue, 22 Mar 2016 22:31:27 +0800 Subject: [PATCH] improved status highlight made dm selectable --- .../java/org/mariotaku/twidere/model/SpanItem.java | 10 ++++++++++ .../mariotaku/twidere/fragment/StatusFragment.java | 3 +-- .../twidere/loader/ParcelableStatusLoader.java | 6 ------ .../twidere/model/util/ParcelableStatusUtils.java | 10 +++++++++- .../layout/card_item_message_conversation_common.xml | 12 +++++++----- .../card_item_message_conversation_incoming.xml | 7 ++++--- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/SpanItem.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/SpanItem.java index 5aa82d7cf..c24afc4ce 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/SpanItem.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/SpanItem.java @@ -2,6 +2,8 @@ package org.mariotaku.twidere.model; import android.os.Parcel; import android.os.Parcelable; +import android.text.Spanned; +import android.text.style.URLSpan; import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonObject; @@ -56,4 +58,12 @@ public class SpanItem implements Parcelable { public void writeToParcel(Parcel dest, int flags) { SpanItemParcelablePlease.writeToParcel(this, dest, flags); } + + public static SpanItem from(Spanned spanned, URLSpan span) { + SpanItem spanItem = new SpanItem(); + spanItem.link = span.getURL(); + spanItem.start = spanned.getSpanStart(span); + spanItem.end = spanned.getSpanEnd(span); + return spanItem; + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/StatusFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/StatusFragment.java index 460404841..0929cfca2 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/StatusFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/StatusFragment.java @@ -2232,10 +2232,9 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac final ParcelableStatus old = mStatus; mStatus = status; mStatusAccount = credentials; - final boolean changed = !CompareUtils.objectEquals(old, status); notifyDataSetChanged(); updateItemDecoration(); - return changed; + return !CompareUtils.objectEquals(old, status); } private void updateItemDecoration() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/ParcelableStatusLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/ParcelableStatusLoader.java index 3107b2ee7..8f43df82d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/ParcelableStatusLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/ParcelableStatusLoader.java @@ -90,12 +90,6 @@ public class ParcelableStatusLoader extends AsyncTaskLoader to <>, so if a status contains those symbols unescaped // We should treat this as an html if (text.contains("<") && text.contains(">")) { - result.text_unescaped = HtmlEscapeHelper.toPlainText(text); + final Spannable html = HtmlSpanBuilder.fromHtml(text); + result.text_unescaped = html.toString(); result.text_plain = result.text_unescaped; + URLSpan[] spans = html.getSpans(0, html.length(), URLSpan.class); + result.spans = new SpanItem[spans.length]; + for (int i = 0, j = spans.length; i < j; i++) { + result.spans[i] = SpanItem.from(html, spans[i]); + } } else { final Pair> textWithIndices = InternalTwitterContentUtils.formatStatusTextWithIndices(status); result.text_plain = InternalTwitterContentUtils.unescapeTwitterStatusText(text); diff --git a/twidere/src/main/res/layout/card_item_message_conversation_common.xml b/twidere/src/main/res/layout/card_item_message_conversation_common.xml index 10be0fb93..9ba8e2816 100644 --- a/twidere/src/main/res/layout/card_item_message_conversation_common.xml +++ b/twidere/src/main/res/layout/card_item_message_conversation_common.xml @@ -17,11 +17,12 @@ ~ along with this program. If not, see . --> - + . --> - + android:layout_alignTop="@+id/message_content"/> - + \ No newline at end of file