fixed NPEs
This commit is contained in:
parent
c08c3a31e5
commit
05aa18a824
|
@ -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";
|
||||
|
|
|
@ -180,6 +180,7 @@ public class ParcelableUser implements Parcelable, Comparable<ParcelableUser> {
|
|||
@ParcelableThisPlease
|
||||
@JsonField(name = "extras")
|
||||
@CursorField(value = CachedUsers.EXTRAS, converter = LoganSquareCursorFieldConverter.class)
|
||||
@Nullable
|
||||
public Extras extras;
|
||||
|
||||
@ParcelableNoThanks
|
||||
|
|
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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<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
|
||||
return loadProfileImage(context, user.profile_image_url, shapeStyle, cornerRadius,
|
||||
cornerRadiusRatio, size)
|
||||
|
|
|
@ -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
|
|
@ -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<UserKey>(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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue