动态tab栏UI调整
- 移除不安全的HttpClient,使用安全的HttpClient - 动态tab栏非激活状态颜色调整
This commit is contained in:
@@ -11,51 +11,19 @@ import okhttp3.OkHttpClient
|
||||
import okhttp3.Response
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import java.security.cert.CertificateException
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import javax.net.ssl.SSLContext
|
||||
import javax.net.ssl.TrustManager
|
||||
import javax.net.ssl.X509TrustManager
|
||||
|
||||
fun getUnsafeOkHttpClient(
|
||||
fun getSafeOkHttpClient(
|
||||
authInterceptor: AuthInterceptor? = null
|
||||
): OkHttpClient {
|
||||
return try {
|
||||
// Create a trust manager that does not validate certificate chains
|
||||
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkClientTrusted(chain: Array<java.security.cert.X509Certificate>, authType: String) {
|
||||
}
|
||||
|
||||
@Throws(CertificateException::class)
|
||||
override fun checkServerTrusted(chain: Array<java.security.cert.X509Certificate>, authType: String) {
|
||||
}
|
||||
|
||||
override fun getAcceptedIssuers(): Array<java.security.cert.X509Certificate> {
|
||||
return arrayOf()
|
||||
}
|
||||
})
|
||||
|
||||
// Install the all-trusting trust manager
|
||||
val sslContext = SSLContext.getInstance("SSL")
|
||||
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
|
||||
|
||||
// Create an ssl socket factory with our all-trusting manager
|
||||
val sslSocketFactory = sslContext.socketFactory
|
||||
|
||||
OkHttpClient.Builder()
|
||||
.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
|
||||
.hostnameVerifier { _, _ -> true }
|
||||
return OkHttpClient.Builder()
|
||||
.apply {
|
||||
authInterceptor?.let {
|
||||
addInterceptor(it)
|
||||
}
|
||||
}
|
||||
.build()
|
||||
} catch (e: Exception) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
}
|
||||
|
||||
class AuthInterceptor() : Interceptor {
|
||||
@@ -87,7 +55,7 @@ class AuthInterceptor() : Interceptor {
|
||||
val client = Retrofit.Builder()
|
||||
.baseUrl(ApiClient.RETROFIT_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.client(getUnsafeOkHttpClient())
|
||||
.client(getSafeOkHttpClient())
|
||||
.build()
|
||||
.create(RaveNowAPI::class.java)
|
||||
|
||||
@@ -106,7 +74,7 @@ object ApiClient {
|
||||
const val RETROFIT_URL = "${BASE_API_URL}/"
|
||||
const val TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"
|
||||
private val okHttpClient: OkHttpClient by lazy {
|
||||
getUnsafeOkHttpClient(authInterceptor = AuthInterceptor())
|
||||
getSafeOkHttpClient(authInterceptor = AuthInterceptor())
|
||||
}
|
||||
private val retrofit: Retrofit by lazy {
|
||||
Retrofit.Builder()
|
||||
|
||||
@@ -98,7 +98,7 @@ fun MomentsList() {
|
||||
Text(
|
||||
text = stringResource(R.string.index_worldwide),
|
||||
fontSize = if (pagerState.currentPage == 0)18.sp else 16.sp,
|
||||
color = if (pagerState.currentPage == 0) AppColors.text else Color(0X993c3c43),
|
||||
color = if (pagerState.currentPage == 0) AppColors.text else AppColors.nonActiveText,
|
||||
fontWeight = FontWeight.W600)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
@@ -128,7 +128,7 @@ fun MomentsList() {
|
||||
Text(
|
||||
text = stringResource(R.string.index_dynamic),
|
||||
fontSize = if (pagerState.currentPage == 1)18.sp else 16.sp,
|
||||
color = if (pagerState.currentPage == 1) AppColors.text else Color(0X993c3c43),
|
||||
color = if (pagerState.currentPage == 1) AppColors.text else AppColors.nonActiveText,
|
||||
fontWeight = FontWeight.W600)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
@@ -162,7 +162,7 @@ fun MomentsList() {
|
||||
Text(
|
||||
text = stringResource(R.string.index_following),
|
||||
fontSize = if (pagerState.currentPage == 2)18.sp else 16.sp,
|
||||
color = if (pagerState.currentPage == 2) AppColors.text else Color(0X993c3c43),
|
||||
color = if (pagerState.currentPage == 2) AppColors.text else AppColors.nonActiveText,
|
||||
fontWeight = FontWeight.W600)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
@@ -195,7 +195,7 @@ fun MomentsList() {
|
||||
Text(
|
||||
text = stringResource(R.string.index_hot),
|
||||
fontSize = if ((AppStore.isGuest && pagerState.currentPage == 2) || (!AppStore.isGuest && pagerState.currentPage == 3)) 18.sp else 16.sp,
|
||||
color = if ((AppStore.isGuest && pagerState.currentPage == 2) || (!AppStore.isGuest && pagerState.currentPage == 3)) AppColors.text else Color(0X993c3c43),
|
||||
color = if ((AppStore.isGuest && pagerState.currentPage == 2) || (!AppStore.isGuest && pagerState.currentPage == 3)) AppColors.text else AppColors.nonActiveText,
|
||||
fontWeight = FontWeight.W600)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import android.net.Uri
|
||||
import coil.ImageLoader
|
||||
import coil.request.CachePolicy
|
||||
import com.aiosman.ravenow.data.api.AuthInterceptor
|
||||
import com.aiosman.ravenow.data.api.getUnsafeOkHttpClient
|
||||
import com.aiosman.ravenow.data.api.getSafeOkHttpClient
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.util.Date
|
||||
@@ -30,7 +30,7 @@ object Utils {
|
||||
val existing = sharedImageLoader
|
||||
if (existing != null) return existing
|
||||
|
||||
val okHttpClient = getUnsafeOkHttpClient(authInterceptor = AuthInterceptor())
|
||||
val okHttpClient = getSafeOkHttpClient(authInterceptor = AuthInterceptor())
|
||||
val loader = ImageLoader.Builder(appContext)
|
||||
.okHttpClient(okHttpClient)
|
||||
.memoryCachePolicy(CachePolicy.ENABLED)
|
||||
|
||||
Reference in New Issue
Block a user