improved status highlight

made dm selectable
This commit is contained in:
Mariotaku Lee 2016-03-22 22:31:27 +08:00
parent 5cc46bc49e
commit 7590992083
6 changed files with 31 additions and 17 deletions

View File

@ -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;
}
}

View File

@ -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() {

View File

@ -90,12 +90,6 @@ public class ParcelableStatusLoader extends AsyncTaskLoader<SingleResponse<Parce
@Override
protected void onStartLoading() {
if (!mOmitIntentExtra && mExtras != null) {
final ParcelableStatus status = mExtras.getParcelable(EXTRA_STATUS);
if (status != null) {
deliverResult(SingleResponse.getInstance(status));
}
}
forceLoad();
}

View File

@ -3,6 +3,7 @@ package org.mariotaku.twidere.model.util;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.Pair;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
@ -18,6 +19,7 @@ import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.SpanItem;
import org.mariotaku.twidere.model.UserKey;
import org.mariotaku.twidere.util.HtmlEscapeHelper;
import org.mariotaku.twidere.util.HtmlSpanBuilder;
import org.mariotaku.twidere.util.InternalTwitterContentUtils;
import org.mariotaku.twidere.util.TwitterContentUtils;
import org.mariotaku.twidere.util.UserColorNameManager;
@ -140,8 +142,14 @@ public class ParcelableStatusUtils {
// Twitter will escape <> to &lt;&gt;, 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<String, List<SpanItem>> textWithIndices = InternalTwitterContentUtils.formatStatusTextWithIndices(status);
result.text_plain = InternalTwitterContentUtils.unescapeTwitterStatusText(text);

View File

@ -17,11 +17,12 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:showIn="@layout/card_item_message_conversation_incoming">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:showIn="@layout/card_item_message_conversation_incoming">
<org.mariotaku.twidere.view.CardMediaContainer
android:id="@+id/media_preview_container"
@ -45,6 +46,7 @@
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:textIsSelectable="true"
tools:text="@string/sample_status_text"/>
<TextView

View File

@ -17,7 +17,8 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -28,7 +29,7 @@
style="?profileImageStyle"
android:layout_width="@dimen/icon_size_card_list_item"
android:layout_height="@dimen/icon_size_card_list_item"
android:layout_alignTop="@+id/message_content" />
android:layout_alignTop="@+id/message_content"/>
<org.mariotaku.messagebubbleview.library.MessageBubbleView
android:id="@+id/message_content"
@ -44,7 +45,7 @@
app:caretWidth="8dp"
app:cornerRadius="2dp">
<include layout="@layout/card_item_message_conversation_common" />
<include layout="@layout/card_item_message_conversation_common"/>
</org.mariotaku.messagebubbleview.library.MessageBubbleView>
</RelativeLayout>