diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java index 89b4ca1b6..2bf26d92e 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java @@ -77,6 +77,7 @@ public interface IntentConstants { String EXTRA_MENTIONS = "mentions"; String EXTRA_ACCOUNT_KEY = "account_key"; String EXTRA_ACCOUNT_HOST = "account_host"; + String EXTRA_ACCOUNT_TYPE = "account_type"; String EXTRA_ACCOUNT_KEYS = "account_keys"; String EXTRA_PAGE = "page"; String EXTRA_DATA = "data"; diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java index 63578b845..145128285 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/model/ParcelableUser.java @@ -180,6 +180,7 @@ public class ParcelableUser implements Parcelable, Comparable { @ParcelableThisPlease @JsonField(name = "extras") @CursorField(value = CachedUsers.EXTRAS, converter = LoganSquareCursorFieldConverter.class) + @Nullable public Extras extras; @ParcelableNoThanks diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AccountSelectorActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AccountSelectorActivity.kt index 767f2769c..46c8c6dc8 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AccountSelectorActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AccountSelectorActivity.kt @@ -59,19 +59,16 @@ class AccountSelectorActivity : BaseActivity(), OnItemClickListener { * If not null, account selector will only show accounts matched this host. */ private val accountHost: String? - get() { - return intent.getStringExtra(EXTRA_ACCOUNT_HOST) - } + get() = intent.getStringExtra(EXTRA_ACCOUNT_HOST) + + private val accountType: String? + get() = intent.getStringExtra(EXTRA_ACCOUNT_TYPE) private val isSelectNoneAllowed: Boolean - get() { - return intent.getBooleanExtra(EXTRA_ALLOW_SELECT_NONE, false) - } + get() = intent.getBooleanExtra(EXTRA_ALLOW_SELECT_NONE, false) private val isSingleSelection: Boolean - get() { - return intent.getBooleanExtra(EXTRA_SINGLE_SELECTION, true) - } + get() = intent.getBooleanExtra(EXTRA_SINGLE_SELECTION, true) /** * True if you want account picked automatically if there are only one match. @@ -98,6 +95,7 @@ class AccountSelectorActivity : BaseActivity(), OnItemClickListener { val extraKeys = onlyIncludeKeys val oauthOnly = isOAuthOnly val accountHost = accountHost + val accountType = accountType addAll(allAccountDetails.filter { if (extraKeys != null) { return@filter extraKeys.contains(it.key) @@ -110,6 +108,9 @@ class AccountSelectorActivity : BaseActivity(), OnItemClickListener { } else if (accountHost != null) { if (accountHost != it.key.host) return@filter false } + if (accountType != null) { + if (accountType != it.type) return@filter false + } return@filter true }) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/GlideExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/GlideExtensions.kt index af8aa26f4..01e182fcd 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/GlideExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/GlideExtensions.kt @@ -57,7 +57,7 @@ fun RequestManager.loadProfileImage(context: Context, account: AccountDetails, @ fun RequestManager.loadProfileImage(context: Context, user: ParcelableUser, @ImageShapeStyle shapeStyle: Int, cornerRadius: Float = 0f, cornerRadiusRatio: Float = 0f, size: String? = null): DrawableRequestBuilder { - if (user.extras != null && user.extras.profile_image_url_fallback == null) { + if (user.extras != null && user.extras?.profile_image_url_fallback == null) { // No fallback image, use compatible logic return loadProfileImage(context, user.profile_image_url, shapeStyle, cornerRadius, cornerRadiusRatio, size) 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 2c6c77459..3d6b87312 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 @@ -47,3 +47,5 @@ inline val ParcelableUser.acct: String get() = if (account_key.host == key.host) } else { "$screen_name@${key.host}" } + +inline val ParcelableUser.groups_count: Long get() = extras?.groups_count ?: -1 \ No newline at end of file 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 73b7a27a5..dac83b559 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt @@ -63,7 +63,6 @@ import android.support.v7.app.AppCompatActivity import android.support.v7.widget.Toolbar import android.text.SpannableStringBuilder import android.text.Spanned -import android.text.TextUtils import android.text.util.Linkify import android.util.SparseBooleanArray import android.view.* @@ -488,13 +487,12 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, val locale = Locale.getDefault() listedContainer.listedCount.text = Utils.getLocalizedNumber(locale, user.listed_count) - val groupsCount = if (user.extras != null) user.extras.groups_count else -1 - groupsContainer.groupsCount.text = Utils.getLocalizedNumber(locale, groupsCount) + groupsContainer.groupsCount.text = Utils.getLocalizedNumber(locale, user.groups_count) followersContainer.followersCount.text = Utils.getLocalizedNumber(locale, user.followers_count) friendsContainer.friendsCount.text = Utils.getLocalizedNumber(locale, user.friends_count) listedContainer.visibility = if (user.listed_count < 0) View.GONE else View.VISIBLE - groupsContainer.visibility = if (groupsCount < 0) View.GONE else View.VISIBLE + groupsContainer.visibility = if (user.groups_count < 0) View.GONE else View.VISIBLE if (user.color != 0) { setUiColor(user.color) @@ -639,10 +637,14 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, if (resultCode == Activity.RESULT_OK) { if (data == null || !data.hasExtra(EXTRA_ID)) return val accountKey = data.getParcelableExtra(EXTRA_ACCOUNT_KEY) + var userKey = user.key + if (account?.type == AccountType.MASTODON && account?.key?.host != accountKey.host) { + userKey = MastodonPlaceholderUserKey(user.key.host) + } @Referral val referral = arguments.getString(EXTRA_REFERRAL) - IntentUtils.openUserProfile(activity, accountKey, user.key, user.screen_name, - user.extras.statusnet_profile_url, preferences[newDocumentApiKey], + IntentUtils.openUserProfile(activity, accountKey, userKey, user.screen_name, + user.extras?.statusnet_profile_url, preferences[newDocumentApiKey], referral, null) } } @@ -948,7 +950,10 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, val intent = Intent(INTENT_ACTION_SELECT_ACCOUNT) intent.setClass(activity, AccountSelectorActivity::class.java) intent.putExtra(EXTRA_SINGLE_SELECTION, true) - intent.putExtra(EXTRA_ACCOUNT_HOST, user.key.host) + when (account?.type) { + AccountType.MASTODON -> intent.putExtra(EXTRA_ACCOUNT_TYPE, AccountType.MASTODON) + else -> intent.putExtra(EXTRA_ACCOUNT_HOST, user.key.host) + } startActivityForResult(intent, REQUEST_SELECT_ACCOUNT) } R.id.follow -> { @@ -1539,7 +1544,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, if (account_key != user.account_key) { return false } - return user.extras != null && TextUtils.equals(user_key.id, user.extras.unique_id) || TextUtils.equals(user_key.id, user.key.id) + return user_key.id == user.extras?.unique_id || user_key.id == user.key.id } private fun setFollowEditButton(@DrawableRes icon: Int, @ColorRes color: Int, @StringRes label: Int) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/util/ParcelableRelationshipUtils.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/util/ParcelableRelationshipUtils.kt index dc98f6f72..fc0bba588 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/model/util/ParcelableRelationshipUtils.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/util/ParcelableRelationshipUtils.kt @@ -59,11 +59,11 @@ object ParcelableRelationshipUtils { obj.filtering = filtering if (user.extras != null) { obj.following = user.is_following - obj.followed_by = user.extras.followed_by - obj.blocking = user.extras.blocking - obj.blocked_by = user.extras.blocked_by - obj.can_dm = user.extras.followed_by - obj.notifications_enabled = user.extras.notifications_enabled + obj.followed_by = user.extras?.followed_by ?: false + obj.blocking = user.extras?.blocking ?: false + obj.blocked_by = user.extras?.blocked_by ?: false + obj.can_dm = user.extras?.followed_by ?: false + obj.notifications_enabled = user.extras?.notifications_enabled ?: false } return obj } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt index e6e75f41d..a1f7324fa 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt @@ -75,7 +75,7 @@ object IntentUtils { intent.setExtrasClassLoader(TwidereApplication::class.java.classLoader) intent.putExtra(EXTRA_USER, user) if (user.extras != null) { - intent.putExtra(EXTRA_PROFILE_URL, user.extras.statusnet_profile_url) + intent.putExtra(EXTRA_PROFILE_URL, user.extras?.statusnet_profile_url) } if (referral != null) { intent.putExtra(EXTRA_REFERRAL, referral) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/LinkCreator.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/LinkCreator.kt index 6ec8f93ac..31a7bae57 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/LinkCreator.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/LinkCreator.kt @@ -131,8 +131,8 @@ object LinkCreator { } fun getUserWebLink(user: ParcelableUser): Uri { - if (user.extras != null && user.extras.statusnet_profile_url != null) { - return Uri.parse(user.extras.statusnet_profile_url) + if (user.extras != null && user.extras?.statusnet_profile_url != null) { + return Uri.parse(user.extras?.statusnet_profile_url) } when (user.user_type) { AccountType.FANFOU -> return getFanfouUserLink(user.key.id)