Remove last references to the old http manager

This commit is contained in:
Shinokuni 2020-10-19 22:54:29 +02:00
parent 725cb291ef
commit f3330ba07d
7 changed files with 16 additions and 79 deletions

View File

@ -52,6 +52,7 @@ dependencies {
androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.8.1'
testImplementation "org.koin:koin-test:2.1.6"
implementation 'com.gitlab.mvysny.konsume-xml:konsume-xml:0.12'

View File

@ -4,13 +4,13 @@ import android.accounts.NetworkErrorException
import android.content.Context
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.readrops.api.utils.HttpManager
import com.readrops.api.utils.LibUtils
import com.readrops.api.utils.ParseException
import com.readrops.api.utils.UnknownFormatException
import junit.framework.TestCase.*
import okhttp3.Headers
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okio.Buffer
@ -28,7 +28,7 @@ class LocalRSSDataSourceTest {
private lateinit var url: HttpUrl
private val mockServer: MockWebServer = MockWebServer()
private val localRSSDataSource = LocalRSSDataSource(HttpManager.getInstance().okHttpClient)
private val localRSSDataSource = LocalRSSDataSource(OkHttpClient())
@Before
fun before() {

View File

@ -1,52 +0,0 @@
package com.readrops.api.utils;
import androidx.annotation.Nullable;
import com.readrops.api.services.Credentials;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
public class HttpManager {
private OkHttpClient okHttpClient;
private Credentials credentials;
public HttpManager() {
buildOkHttp();
}
private void buildOkHttp() {
okHttpClient = new OkHttpClient.Builder()
.callTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.HOURS)
.build();
}
public OkHttpClient getOkHttpClient() {
return okHttpClient;
}
public void setCredentials(@Nullable Credentials credentials) {
this.credentials = credentials;
}
public Credentials getCredentials() {
return credentials;
}
private static HttpManager instance;
public static HttpManager getInstance() {
if (instance == null) {
instance = new HttpManager();
}
return instance;
}
public static void setInstance(OkHttpClient client) {
instance.okHttpClient = client;
}
}

View File

@ -13,13 +13,10 @@ import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
import com.facebook.flipper.plugins.inspector.DescriptorMapping;
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
import com.facebook.flipper.plugins.navigation.NavigationFlipperPlugin;
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
import com.facebook.soloader.SoLoader;
import com.icapps.niddler.core.AndroidNiddler;
import com.icapps.niddler.interceptor.okhttp.NiddlerOkHttpInterceptor;
import com.readrops.api.utils.HttpManager;
public class ReadropsDebugApp extends ReadropsApp implements Configuration.Provider {
@ -40,13 +37,6 @@ public class ReadropsDebugApp extends ReadropsApp implements Configuration.Provi
NetworkFlipperPlugin networkPlugin = new NetworkFlipperPlugin();
client.addPlugin(networkPlugin);
HttpManager.setInstance(
HttpManager.getInstance()
.getOkHttpClient()
.newBuilder()
.addInterceptor(new FlipperOkhttpInterceptor(networkPlugin))
.build());
client.addPlugin(new DatabasesFlipperPlugin(this));
client.addPlugin(CrashReporterPlugin.getInstance());
client.addPlugin(NavigationFlipperPlugin.getInstance());
@ -65,12 +55,6 @@ public class ReadropsDebugApp extends ReadropsApp implements Configuration.Provi
niddler.attachToApplication(this);
HttpManager.setInstance(HttpManager.getInstance().
getOkHttpClient().
newBuilder().
addInterceptor(new NiddlerOkHttpInterceptor(niddler, "default"))
.build());
niddler.start();
}

View File

@ -6,18 +6,19 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.readrops.api.localfeed.LocalRSSHelper;
import com.readrops.api.utils.HttpManager;
import com.readrops.api.utils.LibUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.koin.java.KoinJavaComponent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
@ -83,7 +84,7 @@ public final class HtmlParser {
long start = System.currentTimeMillis();
try {
Response response = HttpManager.getInstance().getOkHttpClient()
Response response = KoinJavaComponent.get(OkHttpClient.class)
.newCall(new Request.Builder().url(url).build()).execute();
if (response.header("Content-Type").contains(LibUtils.HTML_CONTENT_TYPE)) {
@ -98,6 +99,7 @@ public final class HtmlParser {
return null;
}
} catch (Exception e) {
Log.d(TAG, e.getMessage());
return null;
}

View File

@ -7,15 +7,17 @@ import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader
import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.module.AppGlideModule
import com.readrops.api.utils.HttpManager
import okhttp3.OkHttpClient
import org.koin.core.KoinComponent
import org.koin.core.get
import java.io.InputStream
@GlideModule
class ReadropsGlideModule : AppGlideModule() {
class ReadropsGlideModule : AppGlideModule(), KoinComponent {
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
val factory = OkHttpUrlLoader.Factory(HttpManager.getInstance().okHttpClient)
val factory = OkHttpUrlLoader.Factory(get<OkHttpClient>())
glide.registry.replace(GlideUrl::class.java, InputStream::class.java, factory)
}
}

View File

@ -15,7 +15,8 @@ import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import com.google.android.material.snackbar.Snackbar;
import com.readrops.api.utils.HttpManager;
import org.koin.java.KoinJavaComponent;
import java.io.InputStream;
import java.util.Locale;
@ -34,10 +35,9 @@ public final class Utils {
public static Bitmap getImageFromUrl(String url) {
try {
OkHttpClient okHttpClient = HttpManager.getInstance().getOkHttpClient();
Request request = new Request.Builder().url(url).build();
Response response = okHttpClient.newCall(request).execute();
Response response = KoinJavaComponent.get(OkHttpClient.class).newCall(request).execute();
if (response.isSuccessful()) {
InputStream inputStream = response.body().byteStream();