perf: 移除无用代码

This commit is contained in:
HuanChengFly 2020-04-05 16:21:00 +08:00
parent f2656a7d0f
commit 4db6ec60ce
13 changed files with 45 additions and 52 deletions

View File

@ -24,21 +24,21 @@ fun String.urlDecode() : String {
} }
fun FormBody.containsEncodedName(name: String): Boolean { fun FormBody.containsEncodedName(name: String): Boolean {
repeat(size()) { repeat(size) {
if (encodedName(it) == name) return true if (encodedName(it) == name) return true
} }
return false return false
} }
inline fun FormBody.forEach(block: (String, String) -> Unit) { inline fun FormBody.forEach(block: (String, String) -> Unit) {
repeat(size()) { repeat(size) {
block(encodedName(it), encodedValue(it)) block(encodedName(it), encodedValue(it))
} }
} }
fun FormBody.raw() = fun FormBody.raw() =
StringBuilder().apply { StringBuilder().apply {
repeat(size()) { repeat(size) {
if (it != 0) append('&') if (it != 0) append('&')
append(encodedName(it)) append(encodedName(it))
append('=') append('=')
@ -48,7 +48,7 @@ fun FormBody.raw() =
fun FormBody.sortedEncodedRaw(separator: Boolean = true): String { fun FormBody.sortedEncodedRaw(separator: Boolean = true): String {
val nameAndValue = ArrayList<String>() val nameAndValue = ArrayList<String>()
repeat(size()) { repeat(size) {
nameAndValue.add("${encodedName(it)}=${encodedValue(it)}") nameAndValue.add("${encodedName(it)}=${encodedValue(it)}")
} }
if (separator) return nameAndValue.sorted().joinToString(separator = "&") if (separator) return nameAndValue.sorted().joinToString(separator = "&")
@ -57,7 +57,7 @@ fun FormBody.sortedEncodedRaw(separator: Boolean = true): String {
fun FormBody.sortedRaw(separator: Boolean = true): String { fun FormBody.sortedRaw(separator: Boolean = true): String {
val nameAndValue = ArrayList<String>() val nameAndValue = ArrayList<String>()
repeat(size()) { repeat(size) {
nameAndValue.add("${name(it)}=${value(it)}") nameAndValue.add("${name(it)}=${value(it)}")
} }
if (separator) return nameAndValue.sorted().joinToString(separator = "&") if (separator) return nameAndValue.sorted().joinToString(separator = "&")
@ -66,7 +66,7 @@ fun FormBody.sortedRaw(separator: Boolean = true): String {
fun FormBody.Builder.addAllEncoded(formBody: FormBody): FormBody.Builder { fun FormBody.Builder.addAllEncoded(formBody: FormBody): FormBody.Builder {
with(formBody) { with(formBody) {
repeat(size()) { repeat(size) {
addEncoded(encodedName(it), encodedValue(it)) addEncoded(encodedName(it), encodedValue(it))
} }
} }

View File

@ -1,8 +1,8 @@
package com.huanchengfly.tieba.api.interceptors package com.huanchengfly.tieba.api.interceptors
import android.util.Log import android.util.Log
import com.huanchengfly.tieba.api.containsEncodedName
import com.huanchengfly.tieba.api.Param import com.huanchengfly.tieba.api.Param
import com.huanchengfly.tieba.api.containsEncodedName
import com.huanchengfly.tieba.api.sortedEncodedRaw import com.huanchengfly.tieba.api.sortedEncodedRaw
import com.huanchengfly.tieba.api.sortedRaw import com.huanchengfly.tieba.api.sortedRaw
import com.huanchengfly.toMD5 import com.huanchengfly.toMD5
@ -20,14 +20,14 @@ import okhttp3.Response
class SortAndSignInterceptor(private val appSecret: String) : Interceptor { class SortAndSignInterceptor(private val appSecret: String) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
var request = chain.request() var request = chain.request()
val url = request.url() val url = request.url
val body = request.body() val body = request.body
request = when { request = when {
url.queryParameter("BDUSS") != null && url.queryParameter(Param.SIGN) == null -> { url.queryParameter("BDUSS") != null && url.queryParameter(Param.SIGN) == null -> {
Log.i("SortAndSign", "get") Log.i("SortAndSign", "get")
val sortedQuery = url.query()!!.split('&').sorted().joinToString(separator = "") val sortedQuery = url.query!!.split('&').sorted().joinToString(separator = "")
val sortedEncodedQuery = url.encodedQuery()!!.split('&').sorted().joinToString(separator = "&") val sortedEncodedQuery = url.encodedQuery!!.split('&').sorted().joinToString(separator = "&")
request.newBuilder() request.newBuilder()
.url(url.newBuilder() .url(url.newBuilder()
.encodedQuery("$sortedEncodedQuery&${Param.SIGN}=${calculateSign(sortedQuery, appSecret)}") .encodedQuery("$sortedEncodedQuery&${Param.SIGN}=${calculateSign(sortedQuery, appSecret)}")
@ -47,7 +47,7 @@ class SortAndSignInterceptor(private val appSecret: String) : Interceptor {
addEncoded(Param.SIGN, calculateSign(body.sortedRaw(false), appSecret)) addEncoded(Param.SIGN, calculateSign(body.sortedRaw(false), appSecret))
}.build() }.build()
request.newBuilder() request.newBuilder()
.method(request.method(), formBody) .method(request.method, formBody)
.build() .build()
} }

View File

@ -9,9 +9,9 @@ import okhttp3.Response
object AddCookieInterceptor : Interceptor { object AddCookieInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request() val request = chain.request()
var headers = request.headers() var headers = request.headers
val httpUrl = request.url() val httpUrl = request.url
val body = request.body() val body = request.body
var addCookie = true var addCookie = true
val addCookieHeader = headers[Header.ADD_COOKIE] val addCookieHeader = headers[Header.ADD_COOKIE]
@ -33,7 +33,7 @@ object AddCookieInterceptor : Interceptor {
request.newBuilder() request.newBuilder()
.headers(headers) .headers(headers)
.url(httpUrl) .url(httpUrl)
.method(request.method(), body) .method(request.method, body)
.build() .build()
) )
} }

View File

@ -8,7 +8,7 @@ import okhttp3.Response
class CommonHeaderInterceptor(private vararg val additionHeaders: ParamExpression) : Interceptor { class CommonHeaderInterceptor(private vararg val additionHeaders: ParamExpression) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request() val request = chain.request()
val headers = request.headers() val headers = request.headers
return chain.proceed(request.newBuilder().apply { return chain.proceed(request.newBuilder().apply {
additionHeaders.forEachNonNull { name, value -> additionHeaders.forEachNonNull { name, value ->

View File

@ -1,11 +1,6 @@
package com.huanchengfly.tieba.api.retrofit.interceptors package com.huanchengfly.tieba.api.retrofit.interceptors
import com.huanchengfly.tieba.api.ParamExpression import com.huanchengfly.tieba.api.*
import com.huanchengfly.tieba.api.addAllEncoded
import com.huanchengfly.tieba.api.containsEncodedName
import com.huanchengfly.tieba.api.forEachNonNull
import com.huanchengfly.tieba.api.Header
import com.huanchengfly.tieba.api.Method
import okhttp3.FormBody import okhttp3.FormBody
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.Response import okhttp3.Response
@ -13,9 +8,9 @@ import okhttp3.Response
class CommonParamInterceptor(private vararg val additionParams: ParamExpression) : Interceptor { class CommonParamInterceptor(private vararg val additionParams: ParamExpression) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request() val request = chain.request()
var headers = request.headers() var headers = request.headers
var httpUrl = request.url() var httpUrl = request.url
var body = request.body() var body = request.body
//是否强制加到 Query(暂不存在强制加到 FormBody 的情况) //是否强制加到 Query(暂不存在强制加到 FormBody 的情况)
var forceQuery = false var forceQuery = false
@ -27,10 +22,10 @@ class CommonParamInterceptor(private vararg val additionParams: ParamExpression)
when { when {
//如果是 GET 则添加到 Query //如果是 GET 则添加到 Query
request.method() == Method.GET || forceQuery -> { request.method == Method.GET || forceQuery -> {
httpUrl = request.url().newBuilder().apply { httpUrl = request.url.newBuilder().apply {
additionParams.forEachNonNull { name, value -> additionParams.forEachNonNull { name, value ->
if (request.url().queryParameter(name) == null) addQueryParameter(name, value) if (request.url.queryParameter(name) == null) addQueryParameter(name, value)
} }
}.build() }.build()
} }
@ -48,7 +43,7 @@ class CommonParamInterceptor(private vararg val additionParams: ParamExpression)
body is FormBody -> { body is FormBody -> {
body = FormBody.Builder().addAllEncoded(body).apply { body = FormBody.Builder().addAllEncoded(body).apply {
additionParams.forEachNonNull { name, value -> additionParams.forEachNonNull { name, value ->
if (!(request.body() as FormBody).containsEncodedName(name)) add(name, value) if (!(request.body as FormBody).containsEncodedName(name)) add(name, value)
} }
}.build() }.build()
} }
@ -62,7 +57,7 @@ class CommonParamInterceptor(private vararg val additionParams: ParamExpression)
request.newBuilder() request.newBuilder()
.headers(headers) .headers(headers)
.url(httpUrl) .url(httpUrl)
.method(request.method(), body) .method(request.method, body)
.build() .build()
) )
} }

View File

@ -11,7 +11,7 @@ object FailureResponseInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
val response = chain.proceed(chain.request()) val response = chain.proceed(chain.request())
val body = response.body() val body = response.body
if (!response.isSuccessful || body == null || body.contentLength() == 0L) return response if (!response.isSuccessful || body == null || body.contentLength() == 0L) return response
//获取字符集 //获取字符集

View File

@ -11,9 +11,9 @@ import okhttp3.Response
object ForceLoginInterceptor : Interceptor { object ForceLoginInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request() val request = chain.request()
var headers = request.headers() var headers = request.headers
var httpUrl = request.url() var httpUrl = request.url
var body = request.body() var body = request.body
//是否强制登录 //是否强制登录
var forceLogin = false var forceLogin = false
@ -31,7 +31,7 @@ object ForceLoginInterceptor : Interceptor {
request.newBuilder() request.newBuilder()
.headers(headers) .headers(headers)
.url(httpUrl) .url(httpUrl)
.method(request.method(), body) .method(request.method, body)
.build() .build()
) )
} }

View File

@ -1,9 +1,9 @@
package com.huanchengfly.tieba.api.retrofit.interceptors package com.huanchengfly.tieba.api.retrofit.interceptors
import com.huanchengfly.tieba.api.addAllEncoded
import com.huanchengfly.tieba.api.forEachNonNull
import com.huanchengfly.tieba.api.Header import com.huanchengfly.tieba.api.Header
import com.huanchengfly.tieba.api.Method import com.huanchengfly.tieba.api.Method
import com.huanchengfly.tieba.api.addAllEncoded
import com.huanchengfly.tieba.api.forEachNonNull
import okhttp3.FormBody import okhttp3.FormBody
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.Response import okhttp3.Response
@ -13,9 +13,9 @@ import kotlin.math.roundToInt
class StParamInterceptor(private val method: Boolean = false) : Interceptor { class StParamInterceptor(private val method: Boolean = false) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request() val request = chain.request()
var headers = request.headers() var headers = request.headers
var httpUrl = request.url() var httpUrl = request.url
var body = request.body() var body = request.body
//是否强制加到 Query(暂不存在强制加到 FormBody 的情况) //是否强制加到 Query(暂不存在强制加到 FormBody 的情况)
var forceQuery = false var forceQuery = false
@ -52,8 +52,8 @@ class StParamInterceptor(private val method: Boolean = false) : Interceptor {
when { when {
//如果是 GET 则添加到 Query //如果是 GET 则添加到 Query
request.method() == Method.GET || forceQuery -> { request.method == Method.GET || forceQuery -> {
httpUrl = request.url().newBuilder().apply { httpUrl = request.url.newBuilder().apply {
additionParams.forEachNonNull { name, value -> additionParams.forEachNonNull { name, value ->
addQueryParameter(name, value) addQueryParameter(name, value)
} }
@ -87,7 +87,7 @@ class StParamInterceptor(private val method: Boolean = false) : Interceptor {
request.newBuilder() request.newBuilder()
.headers(headers) .headers(headers)
.url(httpUrl) .url(httpUrl)
.method(request.method(), body) .method(request.method, body)
.build() .build()
) )
} }

View File

@ -177,7 +177,7 @@ class FloorActivity : BaseActivity() {
hasMore = false hasMore = false
recyclerViewAdapter!!.loadEnd() recyclerViewAdapter!!.loadEnd()
} }
toolbar.title = getString(R.string.title_floor_loaded, subFloorListBean.post!!.floor) toolbar.title = getString(R.string.title_floor_loaded, subFloorListBean.post.floor)
dataBean = subFloorListBean dataBean = subFloorListBean
recyclerViewAdapter!!.setData(subFloorListBean) recyclerViewAdapter!!.setData(subFloorListBean)
refreshLayout.isRefreshing = false refreshLayout.isRefreshing = false

View File

@ -53,7 +53,6 @@ public class ForumAdapter extends MultiBaseAdapter<ForumPageBean.ThreadBean> {
public static final int TYPE_THREAD_VIDEO = 14; public static final int TYPE_THREAD_VIDEO = 14;
private ForumPageBean data; private ForumPageBean data;
private Map<String, ForumPageBean.UserBean> userBeanMap; private Map<String, ForumPageBean.UserBean> userBeanMap;
private NavigationHelper navigationHelper;
private GoodClassifyAdapter goodClassifyAdapter; private GoodClassifyAdapter goodClassifyAdapter;
private List<Long> ids; private List<Long> ids;
private boolean good; private boolean good;
@ -62,7 +61,6 @@ public class ForumAdapter extends MultiBaseAdapter<ForumPageBean.ThreadBean> {
super(context, null, true); super(context, null, true);
ids = new ArrayList<>(); ids = new ArrayList<>();
userBeanMap = new HashMap<>(); userBeanMap = new HashMap<>();
navigationHelper = NavigationHelper.newInstance(mContext);
good = isGood; good = isGood;
if (isGood) { if (isGood) {
View goodView = Util.inflate(mContext, R.layout.layout_header_forum_good); View goodView = Util.inflate(mContext, R.layout.layout_header_forum_good);
@ -303,7 +301,7 @@ public class ForumAdapter extends MultiBaseAdapter<ForumPageBean.ThreadBean> {
VideoPlayerStandard videoPlayerStandard = viewHolder.getView(R.id.forum_item_content_video); VideoPlayerStandard videoPlayerStandard = viewHolder.getView(R.id.forum_item_content_video);
videoPlayerStandard.setLayoutParams(getLayoutParams((RelativeLayout.LayoutParams) videoPlayerStandard.getLayoutParams())); videoPlayerStandard.setLayoutParams(getLayoutParams((RelativeLayout.LayoutParams) videoPlayerStandard.getLayoutParams()));
videoPlayerStandard.setUp(threadBean.getVideoInfo().getVideoUrl(), ""); videoPlayerStandard.setUp(threadBean.getVideoInfo().getVideoUrl(), "");
ImageUtil.load(videoPlayerStandard.thumbImageView, ImageUtil.LOAD_TYPE_SMALL_PIC, threadBean.getVideoInfo().getThumbnailUrl(), true); ImageUtil.load(videoPlayerStandard.posterImageView, ImageUtil.LOAD_TYPE_SMALL_PIC, threadBean.getVideoInfo().getThumbnailUrl(), true);
break; break;
} }
} }

View File

@ -264,7 +264,7 @@ public class PersonalizedFeedAdapter extends MultiBaseAdapter<PersonalizedBean.T
VideoPlayerStandard videoPlayerStandard = viewHolder.getView(R.id.forum_item_content_video); VideoPlayerStandard videoPlayerStandard = viewHolder.getView(R.id.forum_item_content_video);
videoPlayerStandard.setLayoutParams(getLayoutParams((RelativeLayout.LayoutParams) videoPlayerStandard.getLayoutParams())); videoPlayerStandard.setLayoutParams(getLayoutParams((RelativeLayout.LayoutParams) videoPlayerStandard.getLayoutParams()));
videoPlayerStandard.setUp(threadBean.getVideoInfo().getVideoUrl(), ""); videoPlayerStandard.setUp(threadBean.getVideoInfo().getVideoUrl(), "");
ImageUtil.load(videoPlayerStandard.thumbImageView, ImageUtil.LOAD_TYPE_SMALL_PIC, threadBean.getVideoInfo().getThumbnailUrl(), true); ImageUtil.load(videoPlayerStandard.posterImageView, ImageUtil.LOAD_TYPE_SMALL_PIC, threadBean.getVideoInfo().getThumbnailUrl(), true);
break; break;
} }
if (!TextUtils.isEmpty(threadBean.getForumName())) if (!TextUtils.isEmpty(threadBean.getForumName()))

View File

@ -847,7 +847,7 @@ public class RecyclerThreadAdapter extends MultiBaseAdapter<ThreadContentBean.Po
videoPlayerStandard.setUp(contentBean.getLink(), ""); videoPlayerStandard.setUp(contentBean.getLink(), "");
videoPlayerStandard.setLayoutParams(getLayoutParams(contentBean, postListItemBean.getFloor())); videoPlayerStandard.setLayoutParams(getLayoutParams(contentBean, postListItemBean.getFloor()));
videoPlayerStandard.setId(R.id.video_player); videoPlayerStandard.setId(R.id.video_player);
ImageUtil.load(videoPlayerStandard.thumbImageView, ImageUtil.LOAD_TYPE_SMALL_PIC, contentBean.getSrc(), true); ImageUtil.load(videoPlayerStandard.posterImageView, ImageUtil.LOAD_TYPE_SMALL_PIC, contentBean.getSrc(), true);
views.add(videoPlayerStandard); views.add(videoPlayerStandard);
} else { } else {
MyImageView videoImageView = new MyImageView(mContext); MyImageView videoImageView = new MyImageView(mContext);

View File

@ -24,7 +24,7 @@
</FrameLayout> </FrameLayout>
<ImageView <ImageView
android:id="@+id/thumb" android:id="@+id/poster"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
@ -274,7 +274,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="15dp" android:layout_marginTop="15dp"
android:background="@drawable/retry_bg" android:background="@drawable/jz_retry"
android:paddingLeft="9dp" android:paddingLeft="9dp"
android:paddingTop="4dp" android:paddingTop="4dp"
android:paddingRight="9dp" android:paddingRight="9dp"