mirror of https://github.com/readrops/Readrops.git
Use okHttpClient as a singleton
This commit is contained in:
parent
f32b711be2
commit
245719e2f6
|
@ -14,8 +14,8 @@ import com.readrops.app.utils.FeedInsertionResult;
|
|||
import com.readrops.app.utils.Utils;
|
||||
import com.readrops.app.utils.HtmlParser;
|
||||
import com.readrops.app.utils.ParsingResult;
|
||||
import com.readrops.readropslibrary.Utils.LibUtils;
|
||||
import com.readrops.readropslibrary.Utils.UnknownFormatException;
|
||||
import com.readrops.readropslibrary.utils.LibUtils;
|
||||
import com.readrops.readropslibrary.utils.UnknownFormatException;
|
||||
import com.readrops.readropslibrary.localfeed.AFeed;
|
||||
import com.readrops.readropslibrary.localfeed.RSSQuery;
|
||||
import com.readrops.readropslibrary.localfeed.RSSQueryResult;
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.readrops.app.utils;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import com.readrops.readropslibrary.Utils.LibUtils;
|
||||
import com.readrops.readropslibrary.utils.LibUtils;
|
||||
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
|
|
|
@ -8,7 +8,7 @@ import android.webkit.WebView;
|
|||
|
||||
import com.readrops.app.R;
|
||||
import com.readrops.app.database.pojo.ItemWithFeed;
|
||||
import com.readrops.readropslibrary.Utils.LibUtils;
|
||||
import com.readrops.readropslibrary.utils.LibUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package com.readrops.readropslibrary;
|
||||
|
||||
import com.readrops.readropslibrary.localfeed.AFeed;
|
||||
import com.readrops.readropslibrary.localfeed.RSSQuery;
|
||||
|
||||
public interface QueryCallback {
|
||||
|
||||
void onSyncSuccess(AFeed feed, RSSQuery.RSSType type);
|
||||
|
||||
void onSyncFailure(Exception e);
|
||||
|
||||
}
|
|
@ -4,9 +4,9 @@ import android.accounts.NetworkErrorException;
|
|||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.readrops.readropslibrary.QueryCallback;
|
||||
import com.readrops.readropslibrary.Utils.LibUtils;
|
||||
import com.readrops.readropslibrary.Utils.UnknownFormatException;
|
||||
import com.readrops.readropslibrary.utils.LibOkHttpClient;
|
||||
import com.readrops.readropslibrary.utils.LibUtils;
|
||||
import com.readrops.readropslibrary.utils.UnknownFormatException;
|
||||
import com.readrops.readropslibrary.localfeed.atom.ATOMFeed;
|
||||
import com.readrops.readropslibrary.localfeed.json.JSONFeed;
|
||||
import com.readrops.readropslibrary.localfeed.rss.RSSFeed;
|
||||
|
@ -22,8 +22,6 @@ import java.util.Map;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
@ -75,7 +73,7 @@ public class RSSQuery {
|
|||
}
|
||||
|
||||
private Response query(String url, Map<String, String> headers) throws IOException {
|
||||
OkHttpClient okHttpClient = new OkHttpClient();
|
||||
OkHttpClient okHttpClient = LibOkHttpClient.getInstance();
|
||||
|
||||
Request.Builder builder = new Request.Builder().url(url);
|
||||
for (String header : headers.keySet()) {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package com.readrops.readropslibrary.utils;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public final class LibOkHttpClient {
|
||||
|
||||
private static OkHttpClient okhttpClient;
|
||||
|
||||
public static OkHttpClient getInstance() {
|
||||
if (okhttpClient == null)
|
||||
okhttpClient = createOkHttpInstance();
|
||||
|
||||
return okhttpClient;
|
||||
}
|
||||
|
||||
private static OkHttpClient createOkHttpInstance() {
|
||||
return new OkHttpClient.Builder()
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.readrops.readropslibrary.Utils;
|
||||
package com.readrops.readropslibrary.utils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
|
@ -1,4 +1,4 @@
|
|||
package com.readrops.readropslibrary.Utils;
|
||||
package com.readrops.readropslibrary.utils;
|
||||
|
||||
public class UnknownFormatException extends Exception {
|
||||
|
Loading…
Reference in New Issue