mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-18 21:28:28 +00:00
Add OkHttp cache
This commit is contained in:
parent
b37d7e0500
commit
5a49bd3ac9
@ -9,15 +9,18 @@ import com.topjohnwu.magisk.ktx.precomputedText
|
|||||||
import com.topjohnwu.magisk.utils.MarkwonImagePlugin
|
import com.topjohnwu.magisk.utils.MarkwonImagePlugin
|
||||||
import io.noties.markwon.Markwon
|
import io.noties.markwon.Markwon
|
||||||
import io.noties.markwon.html.HtmlPlugin
|
import io.noties.markwon.html.HtmlPlugin
|
||||||
|
import okhttp3.Cache
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.logging.HttpLoggingInterceptor
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||||
import retrofit2.converter.scalars.ScalarsConverterFactory
|
import retrofit2.converter.scalars.ScalarsConverterFactory
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
fun createOkHttpClient(context: Context): OkHttpClient {
|
fun createOkHttpClient(context: Context): OkHttpClient {
|
||||||
val builder = OkHttpClient.Builder()
|
val appCache = Cache(File(context.cacheDir, "okhttp"), 10 * 1024 * 1024)
|
||||||
|
val builder = OkHttpClient.Builder().cache(appCache)
|
||||||
|
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
builder.addInterceptor(HttpLoggingInterceptor().apply {
|
builder.addInterceptor(HttpLoggingInterceptor().apply {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user