mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-01 17:26:46 +01:00
fixed several crashes
This commit is contained in:
parent
df8fb6ef0b
commit
c20df0cb05
@ -40,9 +40,6 @@ import java.util.Map;
|
||||
*/
|
||||
public class JsonSerializer {
|
||||
|
||||
static {
|
||||
}
|
||||
|
||||
private JsonSerializer() {
|
||||
}
|
||||
|
||||
|
@ -103,26 +103,28 @@ public final class TwidereLinkify implements Constants {
|
||||
setHighlightOption(highlightOption);
|
||||
}
|
||||
|
||||
public void applyAllLinks(@Nullable Spannable text, final UserKey accountKey,
|
||||
public void applyAllLinks(@Nullable Spannable text, @Nullable final UserKey accountKey,
|
||||
final long extraId, final boolean sensitive,
|
||||
final boolean skipLinksInText) {
|
||||
applyAllLinks(text, mOnLinkClickListener, accountKey, extraId, sensitive,
|
||||
mHighlightOption, skipLinksInText);
|
||||
}
|
||||
|
||||
public void applyAllLinks(@Nullable Spannable text, final UserKey accountKey,
|
||||
public void applyAllLinks(@Nullable Spannable text, @Nullable final UserKey accountKey,
|
||||
final boolean sensitive, final boolean skipLinksInText) {
|
||||
applyAllLinks(text, mOnLinkClickListener, accountKey, -1, sensitive, mHighlightOption, skipLinksInText);
|
||||
applyAllLinks(text, mOnLinkClickListener, accountKey, -1, sensitive, mHighlightOption,
|
||||
skipLinksInText);
|
||||
}
|
||||
|
||||
public void applyAllLinks(@Nullable Spannable text, final UserKey accountKey,
|
||||
final long extraId, final boolean sensitive,
|
||||
final int highlightOption, final boolean skipLinksInText) {
|
||||
applyAllLinks(text, mOnLinkClickListener, accountKey, extraId, sensitive, highlightOption, skipLinksInText);
|
||||
public void applyAllLinks(@Nullable Spannable text, @Nullable final UserKey accountKey,
|
||||
final long extraId, final boolean sensitive, final int highlightOption,
|
||||
final boolean skipLinksInText) {
|
||||
applyAllLinks(text, mOnLinkClickListener, accountKey, extraId, sensitive, highlightOption,
|
||||
skipLinksInText);
|
||||
}
|
||||
|
||||
public void applyAllLinks(@Nullable final Spannable text, final OnLinkClickListener listener,
|
||||
final UserKey accountKey, final long extraId, final boolean sensitive,
|
||||
@Nullable final UserKey accountKey, final long extraId, final boolean sensitive,
|
||||
final int highlightOption, boolean skipLinksInText) {
|
||||
if (text == null) return;
|
||||
for (final int type : ALL_LINK_TYPES) {
|
||||
@ -131,20 +133,21 @@ public final class TwidereLinkify implements Constants {
|
||||
}
|
||||
}
|
||||
|
||||
public SpannableString applyUserProfileLink(final CharSequence text, final UserKey accountKey, final long extraId,
|
||||
final long userId, final String screenName) {
|
||||
public SpannableString applyUserProfileLink(@Nullable final CharSequence text,
|
||||
@Nullable final UserKey accountKey, final long extraId, final long userId,
|
||||
final String screenName) {
|
||||
return applyUserProfileLink(text, accountKey, extraId, userId, screenName, mHighlightOption);
|
||||
}
|
||||
|
||||
public SpannableString applyUserProfileLink(final CharSequence text, final UserKey accountKey, final long extraId,
|
||||
final long userId, final String screenName, final int highlightOption) {
|
||||
public SpannableString applyUserProfileLink(@Nullable final CharSequence text,
|
||||
@Nullable final UserKey accountKey, final long extraId, final long userId,
|
||||
final String screenName, final int highlightOption) {
|
||||
return applyUserProfileLink(text, accountKey, extraId, userId, screenName, highlightOption, mOnLinkClickListener);
|
||||
}
|
||||
|
||||
public final SpannableString applyUserProfileLink(final CharSequence text, final UserKey accountKey,
|
||||
final long extraId, final long userId,
|
||||
final String screenName, final int highlightOption,
|
||||
final OnLinkClickListener listener) {
|
||||
public final SpannableString applyUserProfileLink(final CharSequence text,
|
||||
@Nullable final UserKey accountKey, final long extraId, final long userId,
|
||||
final String screenName, final int highlightOption, final OnLinkClickListener listener) {
|
||||
final SpannableString string = SpannableString.valueOf(text);
|
||||
final URLSpan[] spans = string.getSpans(0, string.length(), URLSpan.class);
|
||||
for (final URLSpan span : spans) {
|
||||
@ -164,7 +167,7 @@ public final class TwidereLinkify implements Constants {
|
||||
mHighlightOption = style;
|
||||
}
|
||||
|
||||
private boolean addCashtagLinks(final Spannable spannable, final UserKey accountKey,
|
||||
private boolean addCashtagLinks(final Spannable spannable, @Nullable final UserKey accountKey,
|
||||
final long extraId, final OnLinkClickListener listener, final int highlightOption) {
|
||||
boolean hasMatches = false;
|
||||
for (final Entity entity : mExtractor.extractCashtagsWithIndices(spannable.toString())) {
|
||||
@ -177,7 +180,7 @@ public final class TwidereLinkify implements Constants {
|
||||
return hasMatches;
|
||||
}
|
||||
|
||||
private boolean addHashtagLinks(final Spannable spannable, final UserKey accountKey,
|
||||
private boolean addHashtagLinks(final Spannable spannable, @Nullable final UserKey accountKey,
|
||||
final long extraId, final OnLinkClickListener listener, final int highlightOption) {
|
||||
boolean hasMatches = false;
|
||||
for (final Entity entity : mExtractor.extractHashtagsWithIndices(spannable.toString())) {
|
||||
|
@ -21,6 +21,7 @@ package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.animation.ArgbEvaluator
|
||||
import android.annotation.SuppressLint
|
||||
import android.annotation.TargetApi
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
@ -158,6 +159,8 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
override val toolbar: Toolbar
|
||||
get() = profileContentContainer.toolbar
|
||||
|
||||
override val pinnedStatusIds: Array<String>?
|
||||
get() = user?.extras?.pinned_status_ids
|
||||
|
||||
private lateinit var profileBirthdayBanner: View
|
||||
private lateinit var actionBarBackground: ActionBarDrawable
|
||||
@ -206,8 +209,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
override fun onLoadFinished(loader: Loader<SingleResponse<ParcelableRelationship>>,
|
||||
data: SingleResponse<ParcelableRelationship>) {
|
||||
followProgress.visibility = View.GONE
|
||||
val relationship = data.data
|
||||
displayRelationship(user, relationship)
|
||||
displayRelationship(data.data)
|
||||
updateOptionsMenuVisibility()
|
||||
}
|
||||
|
||||
@ -275,38 +277,35 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
}
|
||||
|
||||
}
|
||||
override val pinnedStatusIds: Array<String>?
|
||||
get() = user?.extras?.pinned_status_ids
|
||||
|
||||
private fun updateOptionsMenuVisibility() {
|
||||
setHasOptionsMenu(user != null && relationship != null)
|
||||
}
|
||||
|
||||
private fun displayRelationship(user: ParcelableUser?,
|
||||
userRelationship: ParcelableRelationship?) {
|
||||
if (user == null) {
|
||||
relationship = null
|
||||
private fun displayRelationship(relationship: ParcelableRelationship?) {
|
||||
val user = this.user ?: run {
|
||||
this.relationship = null
|
||||
return
|
||||
}
|
||||
if (user.account_key.maybeEquals(user.key)) {
|
||||
if (user.key.maybeEquals(user.account_key)) {
|
||||
setFollowEditButton(R.drawable.ic_action_edit, R.color.material_light_blue,
|
||||
R.string.action_edit)
|
||||
followContainer.follow.visibility = View.VISIBLE
|
||||
relationship = userRelationship
|
||||
this.relationship = relationship
|
||||
return
|
||||
}
|
||||
if (userRelationship == null || !userRelationship.check(user)) {
|
||||
relationship = null
|
||||
if (relationship == null || !relationship.check(user)) {
|
||||
this.relationship = null
|
||||
return
|
||||
} else {
|
||||
relationship = userRelationship
|
||||
this.relationship = relationship
|
||||
}
|
||||
activity.invalidateOptionsMenu()
|
||||
if (userRelationship.blocked_by) {
|
||||
if (relationship.blocked_by) {
|
||||
pagesErrorContainer.visibility = View.GONE
|
||||
pagesErrorText.text = null
|
||||
pagesContent.visibility = View.VISIBLE
|
||||
} else if (!userRelationship.following && user.is_protected) {
|
||||
} else if (!relationship.following && user.is_protected) {
|
||||
pagesErrorContainer.visibility = View.VISIBLE
|
||||
pagesErrorText.setText(R.string.user_protected_summary)
|
||||
pagesErrorIcon.setImageResource(R.drawable.ic_info_locked)
|
||||
@ -316,13 +315,13 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
pagesErrorText.text = null
|
||||
pagesContent.visibility = View.VISIBLE
|
||||
}
|
||||
if (userRelationship.blocking) {
|
||||
if (relationship.blocking) {
|
||||
setFollowEditButton(R.drawable.ic_action_block, R.color.material_red,
|
||||
R.string.action_unblock)
|
||||
} else if (userRelationship.blocked_by) {
|
||||
} else if (relationship.blocked_by) {
|
||||
setFollowEditButton(R.drawable.ic_action_block, R.color.material_grey,
|
||||
R.string.action_block)
|
||||
} else if (userRelationship.following) {
|
||||
} else if (relationship.following) {
|
||||
setFollowEditButton(R.drawable.ic_action_confirm, R.color.material_light_blue,
|
||||
R.string.action_unfollow)
|
||||
} else if (user.is_follow_request_sent) {
|
||||
@ -332,12 +331,12 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
setFollowEditButton(R.drawable.ic_action_add, android.R.color.white,
|
||||
R.string.action_follow)
|
||||
}
|
||||
followingYouIndicator.visibility = if (userRelationship.followed_by) View.VISIBLE else View.GONE
|
||||
followingYouIndicator.visibility = if (relationship.followed_by) View.VISIBLE else View.GONE
|
||||
|
||||
val resolver = context.applicationContext.contentResolver
|
||||
task {
|
||||
resolver.insert(CachedUsers.CONTENT_URI, ObjectCursor.valuesCreatorFrom(ParcelableUser::class.java).create(user))
|
||||
resolver.insert(CachedRelationships.CONTENT_URI, ObjectCursor.valuesCreatorFrom(ParcelableRelationship::class.java).create(userRelationship))
|
||||
resolver.insert(CachedRelationships.CONTENT_URI, ObjectCursor.valuesCreatorFrom(ParcelableRelationship::class.java).create(relationship))
|
||||
}
|
||||
followContainer.follow.visibility = View.VISIBLE
|
||||
}
|
||||
@ -377,46 +376,6 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
updateSubtitle()
|
||||
}
|
||||
|
||||
private fun updateSubtitle() {
|
||||
val activity = activity as AppCompatActivity
|
||||
val actionBar = activity.supportActionBar ?: return
|
||||
val user = this.user
|
||||
if (user == null) {
|
||||
actionBar.subtitle = null
|
||||
return
|
||||
}
|
||||
val spec = pagerAdapter.get(viewPager.currentItem)
|
||||
assert(spec.type != null)
|
||||
when (spec.type) {
|
||||
TAB_TYPE_STATUSES, TAB_TYPE_STATUSES_WITH_REPLIES -> {
|
||||
actionBar.subtitle = resources.getQuantityString(R.plurals.N_statuses,
|
||||
user.statuses_count.toInt(), user.statuses_count)
|
||||
}
|
||||
TAB_TYPE_MEDIA -> {
|
||||
if (user.media_count < 0) {
|
||||
actionBar.setSubtitle(R.string.recent_media)
|
||||
} else {
|
||||
actionBar.subtitle = resources.getQuantityString(R.plurals.N_media,
|
||||
user.media_count.toInt(), user.media_count)
|
||||
}
|
||||
}
|
||||
TAB_TYPE_FAVORITES -> {
|
||||
if (preferences.getBoolean(KEY_I_WANT_MY_STARS_BACK)) {
|
||||
actionBar.subtitle = resources.getQuantityString(R.plurals.N_favorites,
|
||||
user.favorites_count.toInt(), user.favorites_count)
|
||||
} else {
|
||||
actionBar.subtitle = resources.getQuantityString(R.plurals.N_likes,
|
||||
user.favorites_count.toInt(), user.favorites_count)
|
||||
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
actionBar.subtitle = null
|
||||
}
|
||||
}
|
||||
updateTitleAlpha()
|
||||
}
|
||||
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
|
||||
}
|
||||
@ -487,6 +446,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
profileType.setImageDrawable(null)
|
||||
profileType.visibility = View.GONE
|
||||
}
|
||||
@SuppressLint("SetTextI18n")
|
||||
profileNameContainer.screenName.text = "@${user.screen_name}"
|
||||
val linkHighlightOption = preferences[linkHighlightOptionKey]
|
||||
val linkify = TwidereLinkify(this, linkHighlightOption)
|
||||
@ -776,14 +736,13 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
getUserInfo(accountKey, userKey, screenName, false)
|
||||
}
|
||||
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
bus.register(this)
|
||||
}
|
||||
|
||||
|
||||
override fun onStop() {
|
||||
val context = context
|
||||
bus.unregister(this)
|
||||
super.onStop()
|
||||
}
|
||||
@ -1151,6 +1110,46 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
||||
return handleFragmentKeyboardShortcutRepeat(handler, keyCode, repeatCount, event, metaState)
|
||||
}
|
||||
|
||||
private fun updateSubtitle() {
|
||||
val activity = activity as AppCompatActivity
|
||||
val actionBar = activity.supportActionBar ?: return
|
||||
val user = this.user
|
||||
if (user == null) {
|
||||
actionBar.subtitle = null
|
||||
return
|
||||
}
|
||||
val spec = pagerAdapter.get(viewPager.currentItem)
|
||||
assert(spec.type != null)
|
||||
when (spec.type) {
|
||||
TAB_TYPE_STATUSES, TAB_TYPE_STATUSES_WITH_REPLIES -> {
|
||||
actionBar.subtitle = resources.getQuantityString(R.plurals.N_statuses,
|
||||
user.statuses_count.toInt(), user.statuses_count)
|
||||
}
|
||||
TAB_TYPE_MEDIA -> {
|
||||
if (user.media_count < 0) {
|
||||
actionBar.setSubtitle(R.string.recent_media)
|
||||
} else {
|
||||
actionBar.subtitle = resources.getQuantityString(R.plurals.N_media,
|
||||
user.media_count.toInt(), user.media_count)
|
||||
}
|
||||
}
|
||||
TAB_TYPE_FAVORITES -> {
|
||||
if (preferences.getBoolean(KEY_I_WANT_MY_STARS_BACK)) {
|
||||
actionBar.subtitle = resources.getQuantityString(R.plurals.N_favorites,
|
||||
user.favorites_count.toInt(), user.favorites_count)
|
||||
} else {
|
||||
actionBar.subtitle = resources.getQuantityString(R.plurals.N_likes,
|
||||
user.favorites_count.toInt(), user.favorites_count)
|
||||
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
actionBar.subtitle = null
|
||||
}
|
||||
}
|
||||
updateTitleAlpha()
|
||||
}
|
||||
|
||||
private fun handleFragmentKeyboardShortcutRepeat(handler: KeyboardShortcutsHandler,
|
||||
keyCode: Int, repeatCount: Int, event: KeyEvent, metaState: Int): Boolean {
|
||||
val fragment = keyboardShortcutRecipient
|
||||
|
@ -49,7 +49,7 @@ class TwidereGlideModule : GlideModule {
|
||||
val conf = HttpClientFactory.HttpClientConfiguration(holder.preferences)
|
||||
val thumbor = holder.thumbor
|
||||
HttpClientFactory.initOkHttpClient(conf, builder, holder.dns, holder.connectionPool, holder.cache)
|
||||
val userAgent = UserAgentUtils.getDefaultUserAgentStringSafe(context) ?: ""
|
||||
val userAgent = UserAgentUtils.getDefaultUserAgentString(context)
|
||||
builder.addInterceptor(ModifyRequestInterceptor(ThumborModifier(thumbor), UserAgentModifier(userAgent)))
|
||||
val client = builder.build()
|
||||
glide.register(GlideUrl::class.java, InputStream::class.java, OkHttpUrlLoader.Factory(client))
|
||||
@ -78,10 +78,12 @@ class TwidereGlideModule : GlideModule {
|
||||
|
||||
}
|
||||
|
||||
class UserAgentModifier(val userAgent: String) : ModifyRequestInterceptor.RequestModifier {
|
||||
class UserAgentModifier(val userAgent: String?) : ModifyRequestInterceptor.RequestModifier {
|
||||
|
||||
override fun modify(original: Request, builder: Request.Builder): Boolean {
|
||||
if (userAgent != null) {
|
||||
builder.header("User-Agent", userAgent)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user