perf: 移除无用代码
This commit is contained in:
parent
f2656a7d0f
commit
4db6ec60ce
|
@ -24,21 +24,21 @@ fun String.urlDecode() : String {
|
|||
}
|
||||
|
||||
fun FormBody.containsEncodedName(name: String): Boolean {
|
||||
repeat(size()) {
|
||||
repeat(size) {
|
||||
if (encodedName(it) == name) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
inline fun FormBody.forEach(block: (String, String) -> Unit) {
|
||||
repeat(size()) {
|
||||
repeat(size) {
|
||||
block(encodedName(it), encodedValue(it))
|
||||
}
|
||||
}
|
||||
|
||||
fun FormBody.raw() =
|
||||
StringBuilder().apply {
|
||||
repeat(size()) {
|
||||
repeat(size) {
|
||||
if (it != 0) append('&')
|
||||
append(encodedName(it))
|
||||
append('=')
|
||||
|
@ -48,7 +48,7 @@ fun FormBody.raw() =
|
|||
|
||||
fun FormBody.sortedEncodedRaw(separator: Boolean = true): String {
|
||||
val nameAndValue = ArrayList<String>()
|
||||
repeat(size()) {
|
||||
repeat(size) {
|
||||
nameAndValue.add("${encodedName(it)}=${encodedValue(it)}")
|
||||
}
|
||||
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 {
|
||||
val nameAndValue = ArrayList<String>()
|
||||
repeat(size()) {
|
||||
repeat(size) {
|
||||
nameAndValue.add("${name(it)}=${value(it)}")
|
||||
}
|
||||
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 {
|
||||
with(formBody) {
|
||||
repeat(size()) {
|
||||
repeat(size) {
|
||||
addEncoded(encodedName(it), encodedValue(it))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.huanchengfly.tieba.api.interceptors
|
||||
|
||||
import android.util.Log
|
||||
import com.huanchengfly.tieba.api.containsEncodedName
|
||||
import com.huanchengfly.tieba.api.Param
|
||||
import com.huanchengfly.tieba.api.containsEncodedName
|
||||
import com.huanchengfly.tieba.api.sortedEncodedRaw
|
||||
import com.huanchengfly.tieba.api.sortedRaw
|
||||
import com.huanchengfly.toMD5
|
||||
|
@ -20,14 +20,14 @@ import okhttp3.Response
|
|||
class SortAndSignInterceptor(private val appSecret: String) : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
var request = chain.request()
|
||||
val url = request.url()
|
||||
val body = request.body()
|
||||
val url = request.url
|
||||
val body = request.body
|
||||
|
||||
request = when {
|
||||
url.queryParameter("BDUSS") != null && url.queryParameter(Param.SIGN) == null -> {
|
||||
Log.i("SortAndSign", "get")
|
||||
val sortedQuery = url.query()!!.split('&').sorted().joinToString(separator = "")
|
||||
val sortedEncodedQuery = url.encodedQuery()!!.split('&').sorted().joinToString(separator = "&")
|
||||
val sortedQuery = url.query!!.split('&').sorted().joinToString(separator = "")
|
||||
val sortedEncodedQuery = url.encodedQuery!!.split('&').sorted().joinToString(separator = "&")
|
||||
request.newBuilder()
|
||||
.url(url.newBuilder()
|
||||
.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))
|
||||
}.build()
|
||||
request.newBuilder()
|
||||
.method(request.method(), formBody)
|
||||
.method(request.method, formBody)
|
||||
.build()
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ import okhttp3.Response
|
|||
object AddCookieInterceptor : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
var headers = request.headers()
|
||||
val httpUrl = request.url()
|
||||
val body = request.body()
|
||||
var headers = request.headers
|
||||
val httpUrl = request.url
|
||||
val body = request.body
|
||||
|
||||
var addCookie = true
|
||||
val addCookieHeader = headers[Header.ADD_COOKIE]
|
||||
|
@ -33,7 +33,7 @@ object AddCookieInterceptor : Interceptor {
|
|||
request.newBuilder()
|
||||
.headers(headers)
|
||||
.url(httpUrl)
|
||||
.method(request.method(), body)
|
||||
.method(request.method, body)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import okhttp3.Response
|
|||
class CommonHeaderInterceptor(private vararg val additionHeaders: ParamExpression) : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
val headers = request.headers()
|
||||
val headers = request.headers
|
||||
|
||||
return chain.proceed(request.newBuilder().apply {
|
||||
additionHeaders.forEachNonNull { name, value ->
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
package com.huanchengfly.tieba.api.retrofit.interceptors
|
||||
|
||||
import com.huanchengfly.tieba.api.ParamExpression
|
||||
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 com.huanchengfly.tieba.api.*
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
|
@ -13,9 +8,9 @@ import okhttp3.Response
|
|||
class CommonParamInterceptor(private vararg val additionParams: ParamExpression) : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
var headers = request.headers()
|
||||
var httpUrl = request.url()
|
||||
var body = request.body()
|
||||
var headers = request.headers
|
||||
var httpUrl = request.url
|
||||
var body = request.body
|
||||
|
||||
//是否强制加到 Query(暂不存在强制加到 FormBody 的情况)
|
||||
var forceQuery = false
|
||||
|
@ -27,10 +22,10 @@ class CommonParamInterceptor(private vararg val additionParams: ParamExpression)
|
|||
|
||||
when {
|
||||
//如果是 GET 则添加到 Query
|
||||
request.method() == Method.GET || forceQuery -> {
|
||||
httpUrl = request.url().newBuilder().apply {
|
||||
request.method == Method.GET || forceQuery -> {
|
||||
httpUrl = request.url.newBuilder().apply {
|
||||
additionParams.forEachNonNull { name, value ->
|
||||
if (request.url().queryParameter(name) == null) addQueryParameter(name, value)
|
||||
if (request.url.queryParameter(name) == null) addQueryParameter(name, value)
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
|
@ -48,7 +43,7 @@ class CommonParamInterceptor(private vararg val additionParams: ParamExpression)
|
|||
body is FormBody -> {
|
||||
body = FormBody.Builder().addAllEncoded(body).apply {
|
||||
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()
|
||||
}
|
||||
|
@ -62,7 +57,7 @@ class CommonParamInterceptor(private vararg val additionParams: ParamExpression)
|
|||
request.newBuilder()
|
||||
.headers(headers)
|
||||
.url(httpUrl)
|
||||
.method(request.method(), body)
|
||||
.method(request.method, body)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ object FailureResponseInterceptor : Interceptor {
|
|||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val response = chain.proceed(chain.request())
|
||||
val body = response.body()
|
||||
val body = response.body
|
||||
if (!response.isSuccessful || body == null || body.contentLength() == 0L) return response
|
||||
|
||||
//获取字符集
|
||||
|
|
|
@ -11,9 +11,9 @@ import okhttp3.Response
|
|||
object ForceLoginInterceptor : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
var headers = request.headers()
|
||||
var httpUrl = request.url()
|
||||
var body = request.body()
|
||||
var headers = request.headers
|
||||
var httpUrl = request.url
|
||||
var body = request.body
|
||||
|
||||
//是否强制登录
|
||||
var forceLogin = false
|
||||
|
@ -31,7 +31,7 @@ object ForceLoginInterceptor : Interceptor {
|
|||
request.newBuilder()
|
||||
.headers(headers)
|
||||
.url(httpUrl)
|
||||
.method(request.method(), body)
|
||||
.method(request.method, body)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
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.Method
|
||||
import com.huanchengfly.tieba.api.addAllEncoded
|
||||
import com.huanchengfly.tieba.api.forEachNonNull
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
|
@ -13,9 +13,9 @@ import kotlin.math.roundToInt
|
|||
class StParamInterceptor(private val method: Boolean = false) : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
var headers = request.headers()
|
||||
var httpUrl = request.url()
|
||||
var body = request.body()
|
||||
var headers = request.headers
|
||||
var httpUrl = request.url
|
||||
var body = request.body
|
||||
|
||||
//是否强制加到 Query(暂不存在强制加到 FormBody 的情况)
|
||||
var forceQuery = false
|
||||
|
@ -52,8 +52,8 @@ class StParamInterceptor(private val method: Boolean = false) : Interceptor {
|
|||
|
||||
when {
|
||||
//如果是 GET 则添加到 Query
|
||||
request.method() == Method.GET || forceQuery -> {
|
||||
httpUrl = request.url().newBuilder().apply {
|
||||
request.method == Method.GET || forceQuery -> {
|
||||
httpUrl = request.url.newBuilder().apply {
|
||||
additionParams.forEachNonNull { name, value ->
|
||||
addQueryParameter(name, value)
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class StParamInterceptor(private val method: Boolean = false) : Interceptor {
|
|||
request.newBuilder()
|
||||
.headers(headers)
|
||||
.url(httpUrl)
|
||||
.method(request.method(), body)
|
||||
.method(request.method, body)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ class FloorActivity : BaseActivity() {
|
|||
hasMore = false
|
||||
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
|
||||
recyclerViewAdapter!!.setData(subFloorListBean)
|
||||
refreshLayout.isRefreshing = false
|
||||
|
|
|
@ -53,7 +53,6 @@ public class ForumAdapter extends MultiBaseAdapter<ForumPageBean.ThreadBean> {
|
|||
public static final int TYPE_THREAD_VIDEO = 14;
|
||||
private ForumPageBean data;
|
||||
private Map<String, ForumPageBean.UserBean> userBeanMap;
|
||||
private NavigationHelper navigationHelper;
|
||||
private GoodClassifyAdapter goodClassifyAdapter;
|
||||
private List<Long> ids;
|
||||
private boolean good;
|
||||
|
@ -62,7 +61,6 @@ public class ForumAdapter extends MultiBaseAdapter<ForumPageBean.ThreadBean> {
|
|||
super(context, null, true);
|
||||
ids = new ArrayList<>();
|
||||
userBeanMap = new HashMap<>();
|
||||
navigationHelper = NavigationHelper.newInstance(mContext);
|
||||
good = isGood;
|
||||
if (isGood) {
|
||||
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.setLayoutParams(getLayoutParams((RelativeLayout.LayoutParams) videoPlayerStandard.getLayoutParams()));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ public class PersonalizedFeedAdapter extends MultiBaseAdapter<PersonalizedBean.T
|
|||
VideoPlayerStandard videoPlayerStandard = viewHolder.getView(R.id.forum_item_content_video);
|
||||
videoPlayerStandard.setLayoutParams(getLayoutParams((RelativeLayout.LayoutParams) videoPlayerStandard.getLayoutParams()));
|
||||
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;
|
||||
}
|
||||
if (!TextUtils.isEmpty(threadBean.getForumName()))
|
||||
|
|
|
@ -847,7 +847,7 @@ public class RecyclerThreadAdapter extends MultiBaseAdapter<ThreadContentBean.Po
|
|||
videoPlayerStandard.setUp(contentBean.getLink(), "");
|
||||
videoPlayerStandard.setLayoutParams(getLayoutParams(contentBean, postListItemBean.getFloor()));
|
||||
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);
|
||||
} else {
|
||||
MyImageView videoImageView = new MyImageView(mContext);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</FrameLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/thumb"
|
||||
android:id="@+id/poster"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentStart="true"
|
||||
|
@ -274,7 +274,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="15dp"
|
||||
android:background="@drawable/retry_bg"
|
||||
android:background="@drawable/jz_retry"
|
||||
android:paddingLeft="9dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingRight="9dp"
|
||||
|
|
Loading…
Reference in New Issue