improved sign in type #802
This commit is contained in:
parent
b7b9b0bb20
commit
c8f94880fa
|
@ -553,7 +553,7 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
|
|||
FilterFlags.QUOTE_NOT_AVAILABLE,
|
||||
FilterFlags.BLOCKING_USER,
|
||||
FilterFlags.BLOCKED_BY_USER,
|
||||
FilterFlags.POSSIBILITY_SENSITIVE
|
||||
FilterFlags.POSSIBLY_SENSITIVE
|
||||
}, flag = true)
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface FilterFlags {
|
||||
|
@ -577,8 +577,8 @@ public class ParcelableStatus implements Parcelable, Comparable<ParcelableStatus
|
|||
*/
|
||||
long BLOCKED_BY_USER = 0x4;
|
||||
/**
|
||||
* Status possibility sensitive (NSFW etc)
|
||||
* Status possibly sensitive (NSFW etc)
|
||||
*/
|
||||
long POSSIBILITY_SENSITIVE = 0x8;
|
||||
long POSSIBLY_SENSITIVE = 0x8;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package org.mariotaku.twidere.model.util;
|
||||
|
||||
import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.microblog.library.twitter.model.UserMentionEntity;
|
||||
import org.mariotaku.twidere.model.ParcelableUserMention;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/3/7.
|
||||
*/
|
||||
public class ParcelableUserMentionUtils {
|
||||
private ParcelableUserMentionUtils() {
|
||||
}
|
||||
|
||||
public static ParcelableUserMention fromMentionEntity(final User user,
|
||||
final UserMentionEntity entity) {
|
||||
ParcelableUserMention obj = new ParcelableUserMention();
|
||||
obj.key = new UserKey(entity.getId(), UserKeyUtils.getUserHost(user));
|
||||
obj.name = entity.getName();
|
||||
obj.screen_name = entity.getScreenName();
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static ParcelableUserMention[] fromUserMentionEntities(final User user,
|
||||
final UserMentionEntity[] entities) {
|
||||
if (entities == null) return null;
|
||||
final ParcelableUserMention[] mentions = new ParcelableUserMention[entities.length];
|
||||
for (int i = 0, j = entities.length; i < j; i++) {
|
||||
mentions[i] = fromMentionEntity(user, entities[i]);
|
||||
}
|
||||
return mentions;
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package org.mariotaku.twidere.model.util;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.mariotaku.microblog.library.twitter.model.User;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.util.UriUtils;
|
||||
|
||||
import static org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM;
|
||||
import static org.mariotaku.twidere.TwidereConstants.USER_TYPE_TWITTER_COM;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/3/7.
|
||||
*/
|
||||
public class UserKeyUtils {
|
||||
|
||||
private UserKeyUtils() {
|
||||
}
|
||||
|
||||
public static UserKey fromUser(@NonNull User user) {
|
||||
return new UserKey(user.getId(), getUserHost(user));
|
||||
}
|
||||
|
||||
public static String getUserHost(User user) {
|
||||
if (isFanfouUser(user)) return USER_TYPE_FANFOU_COM;
|
||||
return getUserHost(user.getStatusnetProfileUrl(), USER_TYPE_TWITTER_COM);
|
||||
}
|
||||
|
||||
public static String getUserHost(ParcelableUser user) {
|
||||
if (isFanfouUser(user)) return USER_TYPE_FANFOU_COM;
|
||||
if (user.extras == null) return USER_TYPE_TWITTER_COM;
|
||||
|
||||
return getUserHost(user.extras.statusnet_profile_url, USER_TYPE_TWITTER_COM);
|
||||
}
|
||||
|
||||
public static boolean isFanfouUser(User user) {
|
||||
return user.getUniqueId() != null && user.getProfileImageUrlLarge() != null;
|
||||
}
|
||||
|
||||
public static boolean isFanfouUser(ParcelableUser user) {
|
||||
return USER_TYPE_FANFOU_COM.equals(user.key.getHost());
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
public static String getUserHost(@Nullable String uri, @Nullable String def) {
|
||||
if (def == null) {
|
||||
def = USER_TYPE_TWITTER_COM;
|
||||
}
|
||||
if (uri == null) return def;
|
||||
final String authority = UriUtils.getAuthority(uri);
|
||||
if (authority == null) return def;
|
||||
return authority.replaceAll("[^\\w\\d\\.]", "-");
|
||||
}
|
||||
|
||||
public static boolean isSameHost(@Nullable UserKey accountKey, @Nullable UserKey userKey) {
|
||||
if (accountKey == null || userKey == null) return false;
|
||||
return isSameHost(accountKey.getHost(), userKey.getHost());
|
||||
}
|
||||
|
||||
public static boolean isSameHost(String a, String b) {
|
||||
if (TextUtils.isEmpty(a) || TextUtils.isEmpty(b)) return true;
|
||||
return TextUtils.equals(a, b);
|
||||
}
|
||||
}
|
|
@ -77,6 +77,8 @@ import org.mariotaku.twidere.constant.randomizeAccountNameKey
|
|||
import org.mariotaku.twidere.extension.applyTheme
|
||||
import org.mariotaku.twidere.extension.getErrorMessage
|
||||
import org.mariotaku.twidere.extension.model.*
|
||||
import org.mariotaku.twidere.extension.model.api.isFanfouUser
|
||||
import org.mariotaku.twidere.extension.model.api.key
|
||||
import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable
|
||||
import org.mariotaku.twidere.extension.model.api.toParcelable
|
||||
import org.mariotaku.twidere.fragment.APIEditorDialogFragment
|
||||
|
@ -95,7 +97,6 @@ import org.mariotaku.twidere.model.account.cred.*
|
|||
import org.mariotaku.twidere.model.analyzer.SignIn
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableUserUtils
|
||||
import org.mariotaku.twidere.model.util.UserKeyUtils
|
||||
import org.mariotaku.twidere.util.*
|
||||
import org.mariotaku.twidere.util.OAuthPasswordAuthenticator.*
|
||||
import java.io.IOException
|
||||
|
@ -634,17 +635,18 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher,
|
|||
val dialog = dialog ?: return
|
||||
val listView = dialog.findViewById(R.id.expandableList) as ExpandableListView
|
||||
val defaultConfig = preferences[defaultAPIConfigKey]
|
||||
val addDefault = !data.contains(defaultConfig)
|
||||
val configGroup = data.groupBy { it.safeType }
|
||||
defaultConfig.name = getString(R.string.login_type_default)
|
||||
val allConfig = ArraySet(data)
|
||||
allConfig.add(defaultConfig)
|
||||
val configGroup = allConfig.groupBy { it.safeType }
|
||||
val supportedAccountTypes = arrayOf(AccountType.TWITTER, AccountType.FANFOU,
|
||||
AccountType.MASTODON, AccountType.STATUSNET)
|
||||
val result = supportedAccountTypes.mapNotNullTo(ArrayList()) { type ->
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(), "-")
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<SingleResponse<Parcelable
|
|||
val activitySummary = StatusActivity(statusId, emptyList())
|
||||
try {
|
||||
activitySummary.retweeters = twitter.getRetweets(statusId, paging)
|
||||
.filterNot { DataStoreUtils.isFilteringUser(context, UserKeyUtils.fromUser(it.user)) }
|
||||
.filterNot { DataStoreUtils.isFilteringUser(context, it.user.key) }
|
||||
.map { it.user.toParcelable(details) }
|
||||
val countValues = ContentValues()
|
||||
val status = twitter.showStatus(statusId)
|
||||
|
|
|
@ -130,7 +130,6 @@ import org.mariotaku.twidere.model.event.TaskStateChangedEvent
|
|||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableMediaUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableRelationshipUtils
|
||||
import org.mariotaku.twidere.model.util.UserKeyUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers
|
||||
import org.mariotaku.twidere.text.TwidereURLSpan
|
||||
|
@ -1697,7 +1696,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||
val details = AccountUtils.getAccountDetails(AccountManager.get(context),
|
||||
accountKey, true) ?: return SingleResponse(MicroBlogException("No Account"))
|
||||
if (details.type == AccountType.TWITTER) {
|
||||
if (!UserKeyUtils.isSameHost(accountKey, user.key)) {
|
||||
if (!accountKey.hasSameHost(user.key)) {
|
||||
return SingleResponse.getInstance(ParcelableRelationshipUtils.create(user, isFiltering))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.mariotaku.twidere.annotation.Referral
|
|||
import org.mariotaku.twidere.extension.api.tryShowUser
|
||||
import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable
|
||||
import org.mariotaku.twidere.extension.model.api.toParcelable
|
||||
import org.mariotaku.twidere.extension.model.host
|
||||
import org.mariotaku.twidere.extension.model.isAcctPlaceholder
|
||||
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
|
@ -49,7 +50,6 @@ import org.mariotaku.twidere.model.SingleResponse
|
|||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.AccountUtils
|
||||
import org.mariotaku.twidere.model.util.ParcelableUserUtils
|
||||
import org.mariotaku.twidere.model.util.UserKeyUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers
|
||||
import org.mariotaku.twidere.task.UpdateAccountInfoTask
|
||||
import org.mariotaku.twidere.util.UserColorNameManager
|
||||
|
@ -126,7 +126,7 @@ class ParcelableUserLoader(
|
|||
val indices = ObjectCursor.indicesFrom(cur, ParcelableUser::class.java)
|
||||
while (!cur.isAfterLast) {
|
||||
val user = indices.newObject(cur)
|
||||
if (TextUtils.equals(UserKeyUtils.getUserHost(user), user.key.host)) {
|
||||
if (TextUtils.equals(user.host, user.key.host)) {
|
||||
user.account_key = accountKey
|
||||
user.account_color = details.color
|
||||
return SingleResponse(user).apply {
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.mariotaku.microblog.library.twitter.model.DMResponse.Entry.Message
|
|||
import org.mariotaku.microblog.library.twitter.model.DMResponse.Entry.Message.Data
|
||||
import org.mariotaku.microblog.library.twitter.model.DirectMessage
|
||||
import org.mariotaku.microblog.library.twitter.model.User
|
||||
import org.mariotaku.twidere.extension.model.api.key
|
||||
import org.mariotaku.twidere.extension.model.api.toParcelable
|
||||
import org.mariotaku.twidere.model.ParcelableMedia
|
||||
import org.mariotaku.twidere.model.ParcelableMessage
|
||||
|
@ -156,8 +157,8 @@ object ParcelableMessageUtils {
|
|||
) {
|
||||
this.account_key = accountKey
|
||||
this.id = message.id
|
||||
this.sender_key = UserKeyUtils.fromUser(message.sender)
|
||||
this.recipient_key = UserKeyUtils.fromUser(message.recipient)
|
||||
this.sender_key = message.sender.key
|
||||
this.recipient_key = message.recipient.key
|
||||
this.message_timestamp = message.createdAt.time
|
||||
this.local_timestamp = this.message_timestamp
|
||||
this.sort_id = this.message_timestamp + (499 * sortIdAdj).toLong()
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package org.mariotaku.twidere.model.util
|
||||
|
||||
import org.mariotaku.microblog.library.twitter.model.UserMentionEntity
|
||||
import org.mariotaku.twidere.model.ParcelableUserMention
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
|
||||
fun UserMentionEntity.toParcelable(host: String?): ParcelableUserMention {
|
||||
val obj = ParcelableUserMention()
|
||||
obj.key = UserKey(id, host)
|
||||
obj.name = name
|
||||
obj.screen_name = screenName
|
||||
return obj
|
||||
}
|
|
@ -32,6 +32,7 @@ import org.mariotaku.twidere.constant.streamingEnabledKey
|
|||
import org.mariotaku.twidere.constant.streamingNonMeteredNetworkKey
|
||||
import org.mariotaku.twidere.constant.streamingPowerSavingKey
|
||||
import org.mariotaku.twidere.extension.model.*
|
||||
import org.mariotaku.twidere.extension.model.api.key
|
||||
import org.mariotaku.twidere.extension.model.api.microblog.toParcelable
|
||||
import org.mariotaku.twidere.extension.model.api.toParcelable
|
||||
import org.mariotaku.twidere.model.*
|
||||
|
@ -382,7 +383,7 @@ class StreamingService : BaseService() {
|
|||
return
|
||||
}
|
||||
val user = status.user ?: return
|
||||
val userKey = UserKeyUtils.fromUser(user)
|
||||
val userKey = user.key
|
||||
val where = Expression.and(Expression.equalsArgs(CachedRelationships.ACCOUNT_KEY),
|
||||
Expression.equalsArgs(CachedRelationships.USER_KEY),
|
||||
Expression.equals(CachedRelationships.NOTIFICATIONS_ENABLED, 1)).sql
|
||||
|
|
|
@ -9,12 +9,12 @@ import org.mariotaku.ktextension.useCursor
|
|||
import org.mariotaku.library.objectcursor.ObjectCursor
|
||||
import org.mariotaku.microblog.library.twitter.model.User
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.extension.model.api.key
|
||||
import org.mariotaku.twidere.extension.model.api.toParcelable
|
||||
import org.mariotaku.twidere.model.ParcelableRelationship
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.util.ParcelableRelationshipUtils
|
||||
import org.mariotaku.twidere.model.util.UserKeyUtils
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers
|
||||
import org.mariotaku.twidere.task.BaseAbstractTask
|
||||
|
@ -51,7 +51,7 @@ class CacheUserRelationshipTask(
|
|||
return@useCursor cur.map(ObjectCursor.indicesFrom(cur, ParcelableRelationship::class.java))
|
||||
}
|
||||
val relationships = users.mapTo(ArraySet<ParcelableRelationship>()) { user ->
|
||||
val userKey = UserKeyUtils.fromUser(user)
|
||||
val userKey = user.key
|
||||
return@mapTo localRelationships.find {
|
||||
it.user_key == userKey
|
||||
}?.apply {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue