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 {
|
public class JsonSerializer {
|
||||||
|
|
||||||
static {
|
|
||||||
}
|
|
||||||
|
|
||||||
private JsonSerializer() {
|
private JsonSerializer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,27 +103,29 @@ public final class TwidereLinkify implements Constants {
|
|||||||
setHighlightOption(highlightOption);
|
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 long extraId, final boolean sensitive,
|
||||||
final boolean skipLinksInText) {
|
final boolean skipLinksInText) {
|
||||||
applyAllLinks(text, mOnLinkClickListener, accountKey, extraId, sensitive,
|
applyAllLinks(text, mOnLinkClickListener, accountKey, extraId, sensitive,
|
||||||
mHighlightOption, skipLinksInText);
|
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) {
|
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,
|
public void applyAllLinks(@Nullable Spannable text, @Nullable final UserKey accountKey,
|
||||||
final long extraId, final boolean sensitive,
|
final long extraId, final boolean sensitive, final int highlightOption,
|
||||||
final int highlightOption, final boolean skipLinksInText) {
|
final boolean skipLinksInText) {
|
||||||
applyAllLinks(text, mOnLinkClickListener, accountKey, extraId, sensitive, highlightOption, skipLinksInText);
|
applyAllLinks(text, mOnLinkClickListener, accountKey, extraId, sensitive, highlightOption,
|
||||||
|
skipLinksInText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyAllLinks(@Nullable final Spannable text, final OnLinkClickListener listener,
|
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) {
|
final int highlightOption, boolean skipLinksInText) {
|
||||||
if (text == null) return;
|
if (text == null) return;
|
||||||
for (final int type : ALL_LINK_TYPES) {
|
for (final int type : ALL_LINK_TYPES) {
|
||||||
if (type == LINK_TYPE_LINK_IN_TEXT && skipLinksInText) continue;
|
if (type == LINK_TYPE_LINK_IN_TEXT && skipLinksInText) continue;
|
||||||
@ -131,20 +133,21 @@ public final class TwidereLinkify implements Constants {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpannableString applyUserProfileLink(final CharSequence text, final UserKey accountKey, final long extraId,
|
public SpannableString applyUserProfileLink(@Nullable final CharSequence text,
|
||||||
final long userId, final String screenName) {
|
@Nullable final UserKey accountKey, final long extraId, final long userId,
|
||||||
|
final String screenName) {
|
||||||
return applyUserProfileLink(text, accountKey, extraId, userId, screenName, mHighlightOption);
|
return applyUserProfileLink(text, accountKey, extraId, userId, screenName, mHighlightOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpannableString applyUserProfileLink(final CharSequence text, final UserKey accountKey, final long extraId,
|
public SpannableString applyUserProfileLink(@Nullable final CharSequence text,
|
||||||
final long userId, final String screenName, final int highlightOption) {
|
@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);
|
return applyUserProfileLink(text, accountKey, extraId, userId, screenName, highlightOption, mOnLinkClickListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final SpannableString applyUserProfileLink(final CharSequence text, final UserKey accountKey,
|
public final SpannableString applyUserProfileLink(final CharSequence text,
|
||||||
final long extraId, final long userId,
|
@Nullable final UserKey accountKey, final long extraId, final long userId,
|
||||||
final String screenName, final int highlightOption,
|
final String screenName, final int highlightOption, final OnLinkClickListener listener) {
|
||||||
final OnLinkClickListener listener) {
|
|
||||||
final SpannableString string = SpannableString.valueOf(text);
|
final SpannableString string = SpannableString.valueOf(text);
|
||||||
final URLSpan[] spans = string.getSpans(0, string.length(), URLSpan.class);
|
final URLSpan[] spans = string.getSpans(0, string.length(), URLSpan.class);
|
||||||
for (final URLSpan span : spans) {
|
for (final URLSpan span : spans) {
|
||||||
@ -164,7 +167,7 @@ public final class TwidereLinkify implements Constants {
|
|||||||
mHighlightOption = style;
|
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) {
|
final long extraId, final OnLinkClickListener listener, final int highlightOption) {
|
||||||
boolean hasMatches = false;
|
boolean hasMatches = false;
|
||||||
for (final Entity entity : mExtractor.extractCashtagsWithIndices(spannable.toString())) {
|
for (final Entity entity : mExtractor.extractCashtagsWithIndices(spannable.toString())) {
|
||||||
@ -177,7 +180,7 @@ public final class TwidereLinkify implements Constants {
|
|||||||
return hasMatches;
|
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) {
|
final long extraId, final OnLinkClickListener listener, final int highlightOption) {
|
||||||
boolean hasMatches = false;
|
boolean hasMatches = false;
|
||||||
for (final Entity entity : mExtractor.extractHashtagsWithIndices(spannable.toString())) {
|
for (final Entity entity : mExtractor.extractHashtagsWithIndices(spannable.toString())) {
|
||||||
|
@ -21,6 +21,7 @@ package org.mariotaku.twidere.fragment
|
|||||||
|
|
||||||
import android.accounts.AccountManager
|
import android.accounts.AccountManager
|
||||||
import android.animation.ArgbEvaluator
|
import android.animation.ArgbEvaluator
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
@ -158,6 +159,8 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||||||
override val toolbar: Toolbar
|
override val toolbar: Toolbar
|
||||||
get() = profileContentContainer.toolbar
|
get() = profileContentContainer.toolbar
|
||||||
|
|
||||||
|
override val pinnedStatusIds: Array<String>?
|
||||||
|
get() = user?.extras?.pinned_status_ids
|
||||||
|
|
||||||
private lateinit var profileBirthdayBanner: View
|
private lateinit var profileBirthdayBanner: View
|
||||||
private lateinit var actionBarBackground: ActionBarDrawable
|
private lateinit var actionBarBackground: ActionBarDrawable
|
||||||
@ -206,8 +209,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||||||
override fun onLoadFinished(loader: Loader<SingleResponse<ParcelableRelationship>>,
|
override fun onLoadFinished(loader: Loader<SingleResponse<ParcelableRelationship>>,
|
||||||
data: SingleResponse<ParcelableRelationship>) {
|
data: SingleResponse<ParcelableRelationship>) {
|
||||||
followProgress.visibility = View.GONE
|
followProgress.visibility = View.GONE
|
||||||
val relationship = data.data
|
displayRelationship(data.data)
|
||||||
displayRelationship(user, relationship)
|
|
||||||
updateOptionsMenuVisibility()
|
updateOptionsMenuVisibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,38 +277,35 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
override val pinnedStatusIds: Array<String>?
|
|
||||||
get() = user?.extras?.pinned_status_ids
|
|
||||||
|
|
||||||
private fun updateOptionsMenuVisibility() {
|
private fun updateOptionsMenuVisibility() {
|
||||||
setHasOptionsMenu(user != null && relationship != null)
|
setHasOptionsMenu(user != null && relationship != null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun displayRelationship(user: ParcelableUser?,
|
private fun displayRelationship(relationship: ParcelableRelationship?) {
|
||||||
userRelationship: ParcelableRelationship?) {
|
val user = this.user ?: run {
|
||||||
if (user == null) {
|
this.relationship = null
|
||||||
relationship = null
|
|
||||||
return
|
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,
|
setFollowEditButton(R.drawable.ic_action_edit, R.color.material_light_blue,
|
||||||
R.string.action_edit)
|
R.string.action_edit)
|
||||||
followContainer.follow.visibility = View.VISIBLE
|
followContainer.follow.visibility = View.VISIBLE
|
||||||
relationship = userRelationship
|
this.relationship = relationship
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (userRelationship == null || !userRelationship.check(user)) {
|
if (relationship == null || !relationship.check(user)) {
|
||||||
relationship = null
|
this.relationship = null
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
relationship = userRelationship
|
this.relationship = relationship
|
||||||
}
|
}
|
||||||
activity.invalidateOptionsMenu()
|
activity.invalidateOptionsMenu()
|
||||||
if (userRelationship.blocked_by) {
|
if (relationship.blocked_by) {
|
||||||
pagesErrorContainer.visibility = View.GONE
|
pagesErrorContainer.visibility = View.GONE
|
||||||
pagesErrorText.text = null
|
pagesErrorText.text = null
|
||||||
pagesContent.visibility = View.VISIBLE
|
pagesContent.visibility = View.VISIBLE
|
||||||
} else if (!userRelationship.following && user.is_protected) {
|
} else if (!relationship.following && user.is_protected) {
|
||||||
pagesErrorContainer.visibility = View.VISIBLE
|
pagesErrorContainer.visibility = View.VISIBLE
|
||||||
pagesErrorText.setText(R.string.user_protected_summary)
|
pagesErrorText.setText(R.string.user_protected_summary)
|
||||||
pagesErrorIcon.setImageResource(R.drawable.ic_info_locked)
|
pagesErrorIcon.setImageResource(R.drawable.ic_info_locked)
|
||||||
@ -316,13 +315,13 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||||||
pagesErrorText.text = null
|
pagesErrorText.text = null
|
||||||
pagesContent.visibility = View.VISIBLE
|
pagesContent.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
if (userRelationship.blocking) {
|
if (relationship.blocking) {
|
||||||
setFollowEditButton(R.drawable.ic_action_block, R.color.material_red,
|
setFollowEditButton(R.drawable.ic_action_block, R.color.material_red,
|
||||||
R.string.action_unblock)
|
R.string.action_unblock)
|
||||||
} else if (userRelationship.blocked_by) {
|
} else if (relationship.blocked_by) {
|
||||||
setFollowEditButton(R.drawable.ic_action_block, R.color.material_grey,
|
setFollowEditButton(R.drawable.ic_action_block, R.color.material_grey,
|
||||||
R.string.action_block)
|
R.string.action_block)
|
||||||
} else if (userRelationship.following) {
|
} else if (relationship.following) {
|
||||||
setFollowEditButton(R.drawable.ic_action_confirm, R.color.material_light_blue,
|
setFollowEditButton(R.drawable.ic_action_confirm, R.color.material_light_blue,
|
||||||
R.string.action_unfollow)
|
R.string.action_unfollow)
|
||||||
} else if (user.is_follow_request_sent) {
|
} 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,
|
setFollowEditButton(R.drawable.ic_action_add, android.R.color.white,
|
||||||
R.string.action_follow)
|
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
|
val resolver = context.applicationContext.contentResolver
|
||||||
task {
|
task {
|
||||||
resolver.insert(CachedUsers.CONTENT_URI, ObjectCursor.valuesCreatorFrom(ParcelableUser::class.java).create(user))
|
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
|
followContainer.follow.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
@ -377,46 +376,6 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||||||
updateSubtitle()
|
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) {
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -487,6 +446,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||||||
profileType.setImageDrawable(null)
|
profileType.setImageDrawable(null)
|
||||||
profileType.visibility = View.GONE
|
profileType.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
profileNameContainer.screenName.text = "@${user.screen_name}"
|
profileNameContainer.screenName.text = "@${user.screen_name}"
|
||||||
val linkHighlightOption = preferences[linkHighlightOptionKey]
|
val linkHighlightOption = preferences[linkHighlightOptionKey]
|
||||||
val linkify = TwidereLinkify(this, linkHighlightOption)
|
val linkify = TwidereLinkify(this, linkHighlightOption)
|
||||||
@ -776,14 +736,13 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||||||
getUserInfo(accountKey, userKey, screenName, false)
|
getUserInfo(accountKey, userKey, screenName, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
bus.register(this)
|
bus.register(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
val context = context
|
|
||||||
bus.unregister(this)
|
bus.unregister(this)
|
||||||
super.onStop()
|
super.onStop()
|
||||||
}
|
}
|
||||||
@ -1151,6 +1110,46 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||||||
return handleFragmentKeyboardShortcutRepeat(handler, keyCode, repeatCount, event, metaState)
|
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,
|
private fun handleFragmentKeyboardShortcutRepeat(handler: KeyboardShortcutsHandler,
|
||||||
keyCode: Int, repeatCount: Int, event: KeyEvent, metaState: Int): Boolean {
|
keyCode: Int, repeatCount: Int, event: KeyEvent, metaState: Int): Boolean {
|
||||||
val fragment = keyboardShortcutRecipient
|
val fragment = keyboardShortcutRecipient
|
||||||
|
@ -49,7 +49,7 @@ class TwidereGlideModule : GlideModule {
|
|||||||
val conf = HttpClientFactory.HttpClientConfiguration(holder.preferences)
|
val conf = HttpClientFactory.HttpClientConfiguration(holder.preferences)
|
||||||
val thumbor = holder.thumbor
|
val thumbor = holder.thumbor
|
||||||
HttpClientFactory.initOkHttpClient(conf, builder, holder.dns, holder.connectionPool, holder.cache)
|
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)))
|
builder.addInterceptor(ModifyRequestInterceptor(ThumborModifier(thumbor), UserAgentModifier(userAgent)))
|
||||||
val client = builder.build()
|
val client = builder.build()
|
||||||
glide.register(GlideUrl::class.java, InputStream::class.java, OkHttpUrlLoader.Factory(client))
|
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 {
|
override fun modify(original: Request, builder: Request.Builder): Boolean {
|
||||||
builder.header("User-Agent", userAgent)
|
if (userAgent != null) {
|
||||||
|
builder.header("User-Agent", userAgent)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user