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 027396bc7..7c1ace04f 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 @@ -553,7 +553,7 @@ public class ParcelableStatus implements Parcelable, Comparable if (type == AccountType.MASTODON) return@mapNotNullTo LoginType(type, listOf(CustomAPIConfig.mastodon(context))) - return@mapNotNullTo configGroup[type]?.let { list -> LoginType(type, list) } - } - if (addDefault) { - result.add(0, LoginType(defaultConfig.safeType, listOf(defaultConfig))) + return@mapNotNullTo configGroup[type]?.let { list -> + LoginType(type, list.sortedBy { !it.isDefault }) + } } (listView.expandableListAdapter as LoginTypeAdapter).data = result } @@ -690,12 +692,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, val view = convertView ?: inflater.inflate(android.R.layout.simple_expandable_list_item_1, parent, false) val text1 = view.findViewById(android.R.id.text1) as TextView val group = getGroup(groupPosition) - val singleChild = group.configs.singleOrNull() - if (singleChild != null && singleChild.isDefault) { - text1.setText(R.string.login_type_default) - } else { - text1.text = APIEditorDialogFragment.getTypeTitle(context, group.type) - } + text1.text = APIEditorDialogFragment.getTypeTitle(context, group.type) return view } @@ -860,7 +857,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, var color = analyseUserProfileColor(apiUser) val (type, extras) = SignInActivity.detectAccountType(twitter, apiUser, apiConfig.type) val userId = apiUser.id - val accountKey = UserKey(userId, UserKeyUtils.getUserHost(apiUser)) + val accountKey = apiUser.key val user = apiUser.toParcelable(accountKey, type, profileImageSize = profileImageSize) val am = AccountManager.get(context) val account = AccountUtils.findByAccountKey(am, accountKey) @@ -1000,7 +997,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, val userId = apiUser.id!! var color = analyseUserProfileColor(apiUser) val (type, extras) = SignInActivity.detectAccountType(twitter, apiUser, apiConfig.type) - val accountKey = UserKey(userId, UserKeyUtils.getUserHost(apiUser)) + val accountKey = apiUser.key val user = apiUser.toParcelable(accountKey, type, profileImageSize = profileImageSize) val am = AccountManager.get(activity) val account = AccountUtils.findByAccountKey(am, accountKey) @@ -1030,7 +1027,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, val userId = apiUser.id!! var color = analyseUserProfileColor(apiUser) val (type, extras) = SignInActivity.detectAccountType(twitter, apiUser, apiConfig.type) - val accountKey = UserKey(userId, UserKeyUtils.getUserHost(apiUser)) + val accountKey = apiUser.key val user = apiUser.toParcelable(accountKey, type, profileImageSize = profileImageSize) val am = AccountManager.get(activity) val account = AccountUtils.findByAccountKey(am, accountKey) @@ -1057,7 +1054,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, val apiUser = twitter.verifyCredentials() var color = analyseUserProfileColor(apiUser) val (type, extras) = SignInActivity.detectAccountType(twitter, apiUser, apiConfig.type) - val accountKey = UserKey(userId, UserKeyUtils.getUserHost(apiUser)) + val accountKey = apiUser.key val user = apiUser.toParcelable(accountKey, type, profileImageSize = profileImageSize) val am = AccountManager.get(activity) val account = AccountUtils.findByAccountKey(am, accountKey) @@ -1256,7 +1253,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, return Pair(AccountType.FANFOU, null) } else -> { - if (UserKeyUtils.isFanfouUser(user)) { + if (user.isFanfouUser) { return Pair(AccountType.FANFOU, null) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserExtensions.kt index a687e3b9b..17654efe2 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/ParcelableUserExtensions.kt @@ -20,6 +20,8 @@ package org.mariotaku.twidere.extension.model import org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM +import org.mariotaku.twidere.TwidereConstants.USER_TYPE_TWITTER_COM +import org.mariotaku.twidere.extension.model.api.getUserHost import org.mariotaku.twidere.model.ParcelableLiteUser import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.util.InternalTwitterContentUtils @@ -46,6 +48,17 @@ fun ParcelableUser.toLite(): ParcelableLiteUser { return result } +val ParcelableUser.host: String + get() { + if (this.isFanfouUser) return USER_TYPE_FANFOU_COM + if (extras == null) return USER_TYPE_TWITTER_COM + + return getUserHost(extras?.statusnet_profile_url, USER_TYPE_TWITTER_COM) + } + +val ParcelableUser.isFanfouUser: Boolean + get() = USER_TYPE_FANFOU_COM == key.host + inline val ParcelableUser.originalProfileImage: String? get() { return extras?.profile_image_url_original?.takeIf(String::isNotEmpty) ?: Utils.getOriginalTwitterProfileImage(profile_image_url) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/UserKeyExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/UserKeyExtensions.kt index f1ba2ce4e..63f46dd13 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/UserKeyExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/UserKeyExtensions.kt @@ -31,4 +31,8 @@ val UserKey.isAcctPlaceholder get() = acctPlaceholderId == id && host != null fun AcctPlaceholderUserKey(host: String?): UserKey { return UserKey(acctPlaceholderId, host) +} + +fun UserKey.hasSameHost(other: UserKey): Boolean { + return host == other.host } \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/StatusExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/StatusExtensions.kt index 42cedd268..96c0133b9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/StatusExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/StatusExtensions.kt @@ -29,8 +29,7 @@ import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.util.ParcelableLocationUtils import org.mariotaku.twidere.model.util.ParcelableMediaUtils import org.mariotaku.twidere.model.util.ParcelableStatusUtils.addFilterFlag -import org.mariotaku.twidere.model.util.ParcelableUserMentionUtils -import org.mariotaku.twidere.model.util.UserKeyUtils +import org.mariotaku.twidere.model.util.toParcelable import org.mariotaku.twidere.text.AcctMentionSpan import org.mariotaku.twidere.util.HtmlSpanBuilder import org.mariotaku.twidere.util.InternalTwitterContentUtils @@ -69,7 +68,7 @@ fun Status.applyTo(accountKey: UserKey, accountType: String, profileImageSize: S val retweetUser = user result.retweet_id = retweetedStatus.id result.retweet_timestamp = retweetedStatus.createdAt?.time ?: 0 - result.retweeted_by_user_key = UserKeyUtils.fromUser(retweetUser) + result.retweeted_by_user_key = retweetUser.key result.retweeted_by_user_name = retweetUser.name result.retweeted_by_user_screen_name = retweetUser.screenName result.retweeted_by_user_profile_image = retweetUser.getProfileImageOfSize(profileImageSize) @@ -83,12 +82,12 @@ fun Status.applyTo(accountKey: UserKey, accountType: String, profileImageSize: S result.addFilterFlag(ParcelableStatus.FilterFlags.BLOCKED_BY_USER) } if (retweetedStatus.isPossiblySensitive) { - result.addFilterFlag(ParcelableStatus.FilterFlags.POSSIBILITY_SENSITIVE) + result.addFilterFlag(ParcelableStatus.FilterFlags.POSSIBLY_SENSITIVE) } } else { status = this if (status.isPossiblySensitive) { - result.addFilterFlag(ParcelableStatus.FilterFlags.POSSIBILITY_SENSITIVE) + result.addFilterFlag(ParcelableStatus.FilterFlags.POSSIBLY_SENSITIVE) } } @@ -120,7 +119,7 @@ fun Status.applyTo(accountKey: UserKey, accountType: String, profileImageSize: S result.quoted_source = quoted.source result.quoted_media = ParcelableMediaUtils.fromStatus(quoted, accountKey, accountType) - result.quoted_user_key = UserKeyUtils.fromUser(quotedUser) + result.quoted_user_key = quotedUser.key result.quoted_user_name = quotedUser.name result.quoted_user_screen_name = quotedUser.screenName result.quoted_user_profile_image = quotedUser.getProfileImageOfSize(profileImageSize) @@ -128,7 +127,7 @@ fun Status.applyTo(accountKey: UserKey, accountType: String, profileImageSize: S result.quoted_user_is_verified = quotedUser.isVerified if (quoted.isPossiblySensitive) { - result.addFilterFlag(ParcelableStatus.FilterFlags.POSSIBILITY_SENSITIVE) + result.addFilterFlag(ParcelableStatus.FilterFlags.POSSIBLY_SENSITIVE) } } else if (status.isQuoteStatus) { result.addFilterFlag(ParcelableStatus.FilterFlags.QUOTE_NOT_AVAILABLE) @@ -144,7 +143,7 @@ fun Status.applyTo(accountKey: UserKey, accountType: String, profileImageSize: S result.in_reply_to_user_key = status.getInReplyToUserKey(accountKey) val user = status.user - result.user_key = UserKeyUtils.fromUser(user) + result.user_key = user.key result.user_name = user.name result.user_screen_name = user.screenName result.user_profile_image_url = user.getProfileImageOfSize(profileImageSize) @@ -179,8 +178,7 @@ fun Status.applyTo(accountKey: UserKey, accountType: String, profileImageSize: S result.my_retweet_id = status.currentUserRetweet } result.is_possibly_sensitive = status.isPossiblySensitive - result.mentions = ParcelableUserMentionUtils.fromUserMentionEntities(user, - status.userMentionEntities) + result.mentions = status.userMentionEntities?.mapToArray { it.toParcelable(user.host) } result.card = status.card?.toParcelable(accountKey, accountType) result.card_name = result.card?.name result.place_full_name = status.placeFullName @@ -242,8 +240,7 @@ private fun Status.getInReplyToUserKey(accountKey: UserKey): UserKey? { val attentions = attentions if (attentions != null) { attentions.firstOrNull { inReplyToUserId == it.id }?.let { - val host = UserKeyUtils.getUserHost(it.ostatusUri, - accountKey.host) + val host = getUserHost(it.ostatusUri, accountKey.host) return UserKey(inReplyToUserId, host) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/UserExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/UserExtensions.kt index 48bf44ba3..7d91c0ec9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/UserExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/UserExtensions.kt @@ -22,13 +22,15 @@ package org.mariotaku.twidere.extension.model.api import android.text.TextUtils import org.mariotaku.ktextension.isNotNullOrEmpty import org.mariotaku.microblog.library.twitter.model.User +import org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM +import org.mariotaku.twidere.TwidereConstants.USER_TYPE_TWITTER_COM import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.util.ParcelableUserUtils -import org.mariotaku.twidere.model.util.UserKeyUtils import org.mariotaku.twidere.util.InternalTwitterContentUtils +import org.mariotaku.twidere.util.UriUtils import org.mariotaku.twidere.util.Utils fun User.getProfileImageOfSize(size: String): String { @@ -61,7 +63,7 @@ fun User.toParcelableInternal(accountKey: UserKey?, @AccountType accountType: St val obj = ParcelableUser() obj.position = position obj.account_key = accountKey - obj.key = UserKeyUtils.fromUser(this) + obj.key = key obj.created_at = createdAt?.time ?: -1 obj.is_protected = isProtected obj.is_verified = isVerified @@ -113,3 +115,23 @@ fun User.toParcelableInternal(accountKey: UserKey?, @AccountType accountType: St obj.extras = extras return obj } + + +val User.key: UserKey + get() = UserKey(id, this.host) + +val User.host: String + get() { + if (isFanfouUser) return USER_TYPE_FANFOU_COM + return getUserHost(statusnetProfileUrl, USER_TYPE_TWITTER_COM) + } + +val User.isFanfouUser: Boolean + get() = uniqueId != null && profileImageUrlLarge != null + +fun getUserHost(uri: String?, def: String?): String { + val nonNullDef = def ?: USER_TYPE_TWITTER_COM + if (uri == null) return nonNullDef + val authority = UriUtils.getAuthority(uri) ?: return nonNullDef + return authority.replace("[^\\w\\d.]".toRegex(), "-") +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt index 85dea1404..3edbf6a65 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/StatusExtensions.kt @@ -71,12 +71,12 @@ fun Status.applyTo(accountKey: UserKey, result: ParcelableStatus) { extras.retweeted_external_url = retweetedStatus.url if (retweetedStatus.isSensitive) { - result.addFilterFlag(ParcelableStatus.FilterFlags.POSSIBILITY_SENSITIVE) + result.addFilterFlag(ParcelableStatus.FilterFlags.POSSIBLY_SENSITIVE) } } else { status = this if (status.isSensitive) { - result.addFilterFlag(ParcelableStatus.FilterFlags.POSSIBILITY_SENSITIVE) + result.addFilterFlag(ParcelableStatus.FilterFlags.POSSIBLY_SENSITIVE) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/microblog/UserListExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/microblog/UserListExtensions.kt index 8e7a535b2..44e5c9a62 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/microblog/UserListExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/microblog/UserListExtensions.kt @@ -21,9 +21,9 @@ package org.mariotaku.twidere.extension.model.api.microblog import org.mariotaku.microblog.library.twitter.model.UserList import org.mariotaku.twidere.extension.model.api.getProfileImageOfSize +import org.mariotaku.twidere.extension.model.api.key import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey -import org.mariotaku.twidere.model.util.UserKeyUtils fun UserList.toParcelable(accountKey: UserKey, position: Long = 0, isFollowing: Boolean = false, profileImageSize: String = "normal"): ParcelableUserList { @@ -36,7 +36,7 @@ fun UserList.toParcelable(accountKey: UserKey, position: Long = 0, isFollowing: obj.is_following = isFollowing obj.name = name obj.description = description - obj.user_key = UserKeyUtils.fromUser(user) + obj.user_key = user.key obj.user_name = user.name obj.user_screen_name = user.screenName obj.user_profile_image_url = user.getProfileImageOfSize(profileImageSize) 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 2d5655c46..29bd01dd7 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt @@ -90,6 +90,7 @@ import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.extension.getErrorMessage import org.mariotaku.twidere.extension.loadProfileImage import org.mariotaku.twidere.extension.model.* +import org.mariotaku.twidere.extension.model.api.key import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.view.calculateSpaceItemHeight import org.mariotaku.twidere.fragment.AbsStatusesFragment.Companion.handleActionClick @@ -106,7 +107,6 @@ import org.mariotaku.twidere.model.pagination.SinceMaxPagination import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.ParcelableLocationUtils import org.mariotaku.twidere.model.util.ParcelableMediaUtils -import org.mariotaku.twidere.model.util.UserKeyUtils import org.mariotaku.twidere.provider.TwidereDataStore.CachedStatuses import org.mariotaku.twidere.provider.TwidereDataStore.Statuses import org.mariotaku.twidere.task.AbsAccountRequestTask @@ -2069,7 +2069,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks()) { user -> - val userKey = UserKeyUtils.fromUser(user) + val userKey = user.key return@mapTo localRelationships.find { it.user_key == userKey }?.apply { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/DataStoreFunctions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/DataStoreFunctions.kt index 882cb37bc..d3261d61a 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/DataStoreFunctions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/DataStoreFunctions.kt @@ -81,7 +81,7 @@ fun buildStatusFilterWhereClause(preferences: SharedPreferences, table: String, filterFlags = filterFlags or FilterFlags.QUOTE_NOT_AVAILABLE } if (preferences[filterPossibilitySensitiveStatusesKey]) { - filterFlags = filterFlags or FilterFlags.POSSIBILITY_SENSITIVE + filterFlags = filterFlags or FilterFlags.POSSIBLY_SENSITIVE } val filterExpression = Expression.or( diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/UserColorNameManager.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/UserColorNameManager.kt index 5a22aa033..f2a70887d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/UserColorNameManager.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/UserColorNameManager.kt @@ -28,8 +28,8 @@ import android.support.v4.util.LruCache import org.mariotaku.microblog.library.twitter.model.User import org.mariotaku.twidere.TwidereConstants.USER_COLOR_PREFERENCES_NAME import org.mariotaku.twidere.TwidereConstants.USER_NICKNAME_PREFERENCES_NAME +import org.mariotaku.twidere.extension.model.api.key import org.mariotaku.twidere.model.* -import org.mariotaku.twidere.model.util.UserKeyUtils class UserColorNameManager(context: Context) { @@ -86,7 +86,7 @@ class UserColorNameManager(context: Context) { } fun getDisplayName(user: User, nameFirst: Boolean): String { - return getDisplayName(UserKeyUtils.fromUser(user), user.name, user.screenName, nameFirst) + return getDisplayName(user.key, user.name, user.screenName, nameFirst) } fun getDisplayName(user: ParcelableUserList, nameFirst: Boolean): String { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/GroupViewHolder.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/GroupViewHolder.kt index eb2c4388d..fc742f4bd 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/GroupViewHolder.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/GroupViewHolder.kt @@ -27,8 +27,8 @@ import org.mariotaku.ktextension.toLocalizedString import org.mariotaku.twidere.R import org.mariotaku.twidere.adapter.iface.IGroupsAdapter import org.mariotaku.twidere.extension.loadProfileImage +import org.mariotaku.twidere.extension.model.api.getUserHost import org.mariotaku.twidere.model.ParcelableGroup -import org.mariotaku.twidere.model.util.UserKeyUtils /** * Created by mariotaku on 15/4/29. @@ -58,8 +58,8 @@ class GroupViewHolder(private val adapter: IGroupsAdapter<*>, itemView: View) : nameView.screenName = "!${group.nickname}" nameView.updateText(formatter) - val groupHost = UserKeyUtils.getUserHost(group.url, group.account_key.host) - if (UserKeyUtils.isSameHost(group.account_key.host, groupHost)) { + val groupHost = getUserHost(group.url, group.account_key.host) + if (group.account_key.host == groupHost) { externalIndicator.visibility = View.GONE } else { externalIndicator.visibility = View.VISIBLE diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/UserViewHolder.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/UserViewHolder.kt index 54bb84418..b4d562745 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/UserViewHolder.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/UserViewHolder.kt @@ -30,8 +30,8 @@ import org.mariotaku.twidere.R import org.mariotaku.twidere.adapter.iface.IUsersAdapter import org.mariotaku.twidere.adapter.iface.IUsersAdapter.* import org.mariotaku.twidere.extension.loadProfileImage +import org.mariotaku.twidere.extension.model.hasSameHost import org.mariotaku.twidere.model.ParcelableUser -import org.mariotaku.twidere.model.util.UserKeyUtils import org.mariotaku.twidere.util.Utils import org.mariotaku.twidere.util.Utils.getUserTypeIconRes import java.util.* @@ -126,7 +126,7 @@ class UserViewHolder( processingRequestProgress.visibility = View.GONE actionsContainer.visibility = View.VISIBLE } - if (UserKeyUtils.isSameHost(user.account_key, user.key)) { + if (user.account_key != null && user.key.hasSameHost(user.account_key)) { externalIndicator.visibility = View.GONE } else { externalIndicator.visibility = View.VISIBLE