fixed NPEs

This commit is contained in:
Mariotaku Lee 2017-04-25 23:54:18 +08:00
parent c08c3a31e5
commit 05aa18a824
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
9 changed files with 36 additions and 26 deletions

View File

@ -77,6 +77,7 @@ public interface IntentConstants {
String EXTRA_MENTIONS = "mentions"; String EXTRA_MENTIONS = "mentions";
String EXTRA_ACCOUNT_KEY = "account_key"; String EXTRA_ACCOUNT_KEY = "account_key";
String EXTRA_ACCOUNT_HOST = "account_host"; String EXTRA_ACCOUNT_HOST = "account_host";
String EXTRA_ACCOUNT_TYPE = "account_type";
String EXTRA_ACCOUNT_KEYS = "account_keys"; String EXTRA_ACCOUNT_KEYS = "account_keys";
String EXTRA_PAGE = "page"; String EXTRA_PAGE = "page";
String EXTRA_DATA = "data"; String EXTRA_DATA = "data";

View File

@ -180,6 +180,7 @@ public class ParcelableUser implements Parcelable, Comparable<ParcelableUser> {
@ParcelableThisPlease @ParcelableThisPlease
@JsonField(name = "extras") @JsonField(name = "extras")
@CursorField(value = CachedUsers.EXTRAS, converter = LoganSquareCursorFieldConverter.class) @CursorField(value = CachedUsers.EXTRAS, converter = LoganSquareCursorFieldConverter.class)
@Nullable
public Extras extras; public Extras extras;
@ParcelableNoThanks @ParcelableNoThanks

View File

@ -59,19 +59,16 @@ class AccountSelectorActivity : BaseActivity(), OnItemClickListener {
* If not null, account selector will only show accounts matched this host. * If not null, account selector will only show accounts matched this host.
*/ */
private val accountHost: String? private val accountHost: String?
get() { get() = intent.getStringExtra(EXTRA_ACCOUNT_HOST)
return intent.getStringExtra(EXTRA_ACCOUNT_HOST)
} private val accountType: String?
get() = intent.getStringExtra(EXTRA_ACCOUNT_TYPE)
private val isSelectNoneAllowed: Boolean private val isSelectNoneAllowed: Boolean
get() { get() = intent.getBooleanExtra(EXTRA_ALLOW_SELECT_NONE, false)
return intent.getBooleanExtra(EXTRA_ALLOW_SELECT_NONE, false)
}
private val isSingleSelection: Boolean private val isSingleSelection: Boolean
get() { get() = intent.getBooleanExtra(EXTRA_SINGLE_SELECTION, true)
return intent.getBooleanExtra(EXTRA_SINGLE_SELECTION, true)
}
/** /**
* True if you want account picked automatically if there are only one match. * 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 extraKeys = onlyIncludeKeys
val oauthOnly = isOAuthOnly val oauthOnly = isOAuthOnly
val accountHost = accountHost val accountHost = accountHost
val accountType = accountType
addAll(allAccountDetails.filter { addAll(allAccountDetails.filter {
if (extraKeys != null) { if (extraKeys != null) {
return@filter extraKeys.contains(it.key) return@filter extraKeys.contains(it.key)
@ -110,6 +108,9 @@ class AccountSelectorActivity : BaseActivity(), OnItemClickListener {
} else if (accountHost != null) { } else if (accountHost != null) {
if (accountHost != it.key.host) return@filter false if (accountHost != it.key.host) return@filter false
} }
if (accountType != null) {
if (accountType != it.type) return@filter false
}
return@filter true return@filter true
}) })
} }

View File

@ -57,7 +57,7 @@ fun RequestManager.loadProfileImage(context: Context, account: AccountDetails, @
fun RequestManager.loadProfileImage(context: Context, user: ParcelableUser, @ImageShapeStyle shapeStyle: Int, fun RequestManager.loadProfileImage(context: Context, user: ParcelableUser, @ImageShapeStyle shapeStyle: Int,
cornerRadius: Float = 0f, cornerRadiusRatio: Float = 0f, size: String? = null): DrawableRequestBuilder<String?> { cornerRadius: Float = 0f, cornerRadiusRatio: Float = 0f, size: String? = null): DrawableRequestBuilder<String?> {
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 // No fallback image, use compatible logic
return loadProfileImage(context, user.profile_image_url, shapeStyle, cornerRadius, return loadProfileImage(context, user.profile_image_url, shapeStyle, cornerRadius,
cornerRadiusRatio, size) cornerRadiusRatio, size)

View File

@ -47,3 +47,5 @@ inline val ParcelableUser.acct: String get() = if (account_key.host == key.host)
} else { } else {
"$screen_name@${key.host}" "$screen_name@${key.host}"
} }
inline val ParcelableUser.groups_count: Long get() = extras?.groups_count ?: -1

View File

@ -63,7 +63,6 @@ import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar import android.support.v7.widget.Toolbar
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import android.text.Spanned import android.text.Spanned
import android.text.TextUtils
import android.text.util.Linkify import android.text.util.Linkify
import android.util.SparseBooleanArray import android.util.SparseBooleanArray
import android.view.* import android.view.*
@ -488,13 +487,12 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
val locale = Locale.getDefault() val locale = Locale.getDefault()
listedContainer.listedCount.text = Utils.getLocalizedNumber(locale, user.listed_count) 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, user.groups_count)
groupsContainer.groupsCount.text = Utils.getLocalizedNumber(locale, groupsCount)
followersContainer.followersCount.text = Utils.getLocalizedNumber(locale, user.followers_count) followersContainer.followersCount.text = Utils.getLocalizedNumber(locale, user.followers_count)
friendsContainer.friendsCount.text = Utils.getLocalizedNumber(locale, user.friends_count) friendsContainer.friendsCount.text = Utils.getLocalizedNumber(locale, user.friends_count)
listedContainer.visibility = if (user.listed_count < 0) View.GONE else View.VISIBLE 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) { if (user.color != 0) {
setUiColor(user.color) setUiColor(user.color)
@ -639,10 +637,14 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
if (data == null || !data.hasExtra(EXTRA_ID)) return if (data == null || !data.hasExtra(EXTRA_ID)) return
val accountKey = data.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY) val accountKey = data.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY)
var userKey = user.key
if (account?.type == AccountType.MASTODON && account?.key?.host != accountKey.host) {
userKey = MastodonPlaceholderUserKey(user.key.host)
}
@Referral @Referral
val referral = arguments.getString(EXTRA_REFERRAL) val referral = arguments.getString(EXTRA_REFERRAL)
IntentUtils.openUserProfile(activity, accountKey, user.key, user.screen_name, IntentUtils.openUserProfile(activity, accountKey, userKey, user.screen_name,
user.extras.statusnet_profile_url, preferences[newDocumentApiKey], user.extras?.statusnet_profile_url, preferences[newDocumentApiKey],
referral, null) referral, null)
} }
} }
@ -948,7 +950,10 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
val intent = Intent(INTENT_ACTION_SELECT_ACCOUNT) val intent = Intent(INTENT_ACTION_SELECT_ACCOUNT)
intent.setClass(activity, AccountSelectorActivity::class.java) intent.setClass(activity, AccountSelectorActivity::class.java)
intent.putExtra(EXTRA_SINGLE_SELECTION, true) 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) startActivityForResult(intent, REQUEST_SELECT_ACCOUNT)
} }
R.id.follow -> { R.id.follow -> {
@ -1539,7 +1544,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
if (account_key != user.account_key) { if (account_key != user.account_key) {
return false 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) { private fun setFollowEditButton(@DrawableRes icon: Int, @ColorRes color: Int, @StringRes label: Int) {

View File

@ -59,11 +59,11 @@ object ParcelableRelationshipUtils {
obj.filtering = filtering obj.filtering = filtering
if (user.extras != null) { if (user.extras != null) {
obj.following = user.is_following obj.following = user.is_following
obj.followed_by = user.extras.followed_by obj.followed_by = user.extras?.followed_by ?: false
obj.blocking = user.extras.blocking obj.blocking = user.extras?.blocking ?: false
obj.blocked_by = user.extras.blocked_by obj.blocked_by = user.extras?.blocked_by ?: false
obj.can_dm = user.extras.followed_by obj.can_dm = user.extras?.followed_by ?: false
obj.notifications_enabled = user.extras.notifications_enabled obj.notifications_enabled = user.extras?.notifications_enabled ?: false
} }
return obj return obj
} }

View File

@ -75,7 +75,7 @@ object IntentUtils {
intent.setExtrasClassLoader(TwidereApplication::class.java.classLoader) intent.setExtrasClassLoader(TwidereApplication::class.java.classLoader)
intent.putExtra(EXTRA_USER, user) intent.putExtra(EXTRA_USER, user)
if (user.extras != null) { 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) { if (referral != null) {
intent.putExtra(EXTRA_REFERRAL, referral) intent.putExtra(EXTRA_REFERRAL, referral)

View File

@ -131,8 +131,8 @@ object LinkCreator {
} }
fun getUserWebLink(user: ParcelableUser): Uri { fun getUserWebLink(user: ParcelableUser): Uri {
if (user.extras != null && user.extras.statusnet_profile_url != null) { if (user.extras != null && user.extras?.statusnet_profile_url != null) {
return Uri.parse(user.extras.statusnet_profile_url) return Uri.parse(user.extras?.statusnet_profile_url)
} }
when (user.user_type) { when (user.user_type) {
AccountType.FANFOU -> return getFanfouUserLink(user.key.id) AccountType.FANFOU -> return getFanfouUserLink(user.key.id)