From ebc3385c4884f3667045904ddb323d8fb7a20011 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sun, 23 Apr 2017 15:15:46 +0800 Subject: [PATCH] fixed #776 --- .../twidere/model/ParcelableStatus.java | 1 + .../twidere/activity/ComposeActivity.kt | 17 +++---- .../model/ParcelableUserMentionExtensions.kt | 34 +++++++++++++ .../fragment/AddStatusFilterDialogFragment.kt | 2 +- .../twidere/fragment/StatusFragment.kt | 25 +++++---- .../twidere/fragment/UserFragment.kt | 2 +- twidere/src/main/res/layout/header_user.xml | 51 +++++++++++-------- 7 files changed, 88 insertions(+), 44 deletions(-) create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserMentionExtensions.kt diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java index 49d9e2e79..d4782d03b 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableStatus.java @@ -237,6 +237,7 @@ public class ParcelableStatus implements Parcelable, Comparable() + val userAcct = status.user_acct if (accountUser.key != status.user_key) { - editText.append("@${status.user_screen_name} ") + editText.append("@$userAcct ") } var selectionStart = editText.length() if (status.is_retweet && !TextUtils.isEmpty(status.retweeted_by_user_screen_name)) { - mentions.add(status.retweeted_by_user_screen_name) + status.retweeted_by_user_acct?.addTo(mentions) } if (status.is_quote && !TextUtils.isEmpty(status.quoted_user_screen_name)) { - mentions.add(status.quoted_user_screen_name) + status.quoted_user_acct?.addTo(mentions) } if (status.mentions.isNotNullOrEmpty()) { status.mentions.filterNot { it.key == status.account_key || it.screen_name.isNullOrEmpty() - }.mapTo(mentions) { it.screen_name } + }.mapTo(mentions) { it.getAcct(details.key) } mentions.addAll(extractor.extractMentionedScreennames(status.quoted_text_plain)) } else if (USER_TYPE_FANFOU_COM == status.account_key.host) { addFanfouHtmlToMentions(status.text_unescaped, status.spans, mentions) @@ -992,13 +991,13 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener } mentions.distinctBy { it.toLowerCase(Locale.US) }.filterNot { - return@filterNot it.equals(status.user_screen_name, ignoreCase = true) + return@filterNot it.equals(userAcct, ignoreCase = true) }.forEach { editText.append("@$it ") } // For non-Twitter instances, put current user mention at last if (details.type != AccountType.TWITTER && accountUser.key == status.user_key) { selectionStart = editText.length() - editText.append("@${status.user_screen_name} ") + editText.append("@$userAcct ") } val text = intent.getStringExtra(EXTRA_TEXT) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserMentionExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserMentionExtensions.kt new file mode 100644 index 000000000..5849d7ecf --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserMentionExtensions.kt @@ -0,0 +1,34 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.extension.model + +import org.mariotaku.twidere.model.ParcelableUserMention +import org.mariotaku.twidere.model.UserKey + +/** + * Created by mariotaku on 2017/4/23. + */ +fun ParcelableUserMention.getAcct(accountKey: UserKey): String { + if (accountKey.host == key.host) { + return screen_name + } else { + return "$screen_name@${key.host}" + } +} \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.kt index 5eca01179..a3f051556 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.kt @@ -157,7 +157,7 @@ class AddStatusFilterDialogFragment : BaseDialogFragment() { for (hashtag in hashtags) { list.add(FilterItemInfo(FilterItemInfo.FILTER_TYPE_KEYWORD, hashtag)) } - val source = HtmlEscapeHelper.toPlainText(status.source) + val source = status.source?.let(HtmlEscapeHelper::toPlainText) if (source != null) { list.add(FilterItemInfo(FilterItemInfo.FILTER_TYPE_SOURCE, source)) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt index 5d06c8022..98ea1143b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt @@ -433,7 +433,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks { + HtmlSpanBuilder.fromHtml(context.getString(R.string.status_format_time_source, + timeString, source)) + } + source != null -> HtmlSpanBuilder.fromHtml(source) + timeString != null -> timeString + else -> null } itemView.timeSource.movementMethod = LinkMovementMethod.getInstance() diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt index 6f0ef89c2..1cc484926 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt @@ -450,7 +450,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, profileType.visibility = View.GONE } @SuppressLint("SetTextI18n") - profileNameContainer.screenName.text = "@${user.screen_name}" + profileNameContainer.screenName.text = "@${user.acct}" val linkHighlightOption = preferences[linkHighlightOptionKey] val linkify = TwidereLinkify(this, linkHighlightOption) if (user.description_unescaped != null) { diff --git a/twidere/src/main/res/layout/header_user.xml b/twidere/src/main/res/layout/header_user.xml index 7f337cafc..87dde1150 100644 --- a/twidere/src/main/res/layout/header_user.xml +++ b/twidere/src/main/res/layout/header_user.xml @@ -113,32 +113,39 @@ android:textColor="?android:textColorPrimary" tools:text="Name"/> - + android:baselineAligned="true" + android:orientation="horizontal"> - + + + +