Fixed formatting.

This commit is contained in:
anonTree1417
2020-03-31 16:41:50 +02:00
parent 2b6d22ed94
commit e1ccb4e404
6 changed files with 38 additions and 30 deletions

View File

@@ -1,6 +1,7 @@
package org.mian.gitnex.clients;
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
import org.mian.gitnex.ssl.MemorizingTrustManager;
import org.mian.gitnex.util.AppUtil;
@@ -25,10 +26,10 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class IssuesService {
public static <S> S createService(Class<S> serviceClass, String instanceURL, Context context) {
public static <S> S createService(Class<S> serviceClass, String instanceURL, Context ctx) {
final boolean connToInternet = AppUtil.haveNetworkConnection(context);
File httpCacheDirectory = new File(context.getCacheDir(), "responses");
final boolean connToInternet = AppUtil.haveNetworkConnection(ctx);
File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
int cacheSize = 50 * 1024 * 1024; // 50MB
Cache cache = new Cache(httpCacheDirectory, cacheSize);
@@ -38,7 +39,7 @@ public class IssuesService {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(context);
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache).sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager).hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())).addInterceptor(new Interceptor() {
@@ -62,8 +63,9 @@ public class IssuesService {
Retrofit retrofit = builder.build();
return retrofit.create(serviceClass);
} catch(Exception e) {
e.printStackTrace();
}
catch(Exception e) {
Log.e("onFailure", e.toString());
}
return null;

View File

@@ -1,6 +1,7 @@
package org.mian.gitnex.clients;
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
import org.mian.gitnex.ssl.MemorizingTrustManager;
import org.mian.gitnex.util.AppUtil;
@@ -25,10 +26,10 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class PullRequestsService {
public static <S> S createService(Class<S> serviceClass, String instanceURL, Context context) {
public static <S> S createService(Class<S> serviceClass, String instanceURL, Context ctx) {
final boolean connToInternet = AppUtil.haveNetworkConnection(context);
File httpCacheDirectory = new File(context.getCacheDir(), "responses");
final boolean connToInternet = AppUtil.haveNetworkConnection(ctx);
File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
int cacheSize = 50 * 1024 * 1024; // 50MB
Cache cache = new Cache(httpCacheDirectory, cacheSize);
@@ -38,7 +39,7 @@ public class PullRequestsService {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(context);
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache).sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager).hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())).addInterceptor(new Interceptor() {
@@ -62,8 +63,9 @@ public class PullRequestsService {
Retrofit retrofit = builder.build();
return retrofit.create(serviceClass);
} catch(Exception e) {
e.printStackTrace();
}
catch(Exception e) {
Log.e("onFailure", e.toString());
}
return null;

View File

@@ -1,6 +1,7 @@
package org.mian.gitnex.clients;
import android.content.Context;
import android.util.Log;
import org.mian.gitnex.interfaces.ApiInterface;
import org.mian.gitnex.ssl.MemorizingTrustManager;
import org.mian.gitnex.util.AppUtil;
@@ -25,10 +26,10 @@ public class RetrofitClient {
private Retrofit retrofit;
private RetrofitClient(String instanceUrl, Context context) {
final boolean connToInternet = AppUtil.haveNetworkConnection(context);
private RetrofitClient(String instanceUrl, Context ctx) {
final boolean connToInternet = AppUtil.haveNetworkConnection(ctx);
int cacheSize = 50 * 1024 * 1024; // 50MB
File httpCacheDirectory = new File(context.getCacheDir(), "responses");
File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
Cache cache = new Cache(httpCacheDirectory, cacheSize);
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
@@ -37,21 +38,23 @@ public class RetrofitClient {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(context);
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
sslContext.init(null, new X509TrustManager[] { memorizingTrustManager }, new SecureRandom());
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder()
.cache(cache)
//.addInterceptor(logging)
.sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager)
.hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()))
.addInterceptor(chain -> {
Request request = chain.request();
request = (connToInternet) ?
request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build() :
request.newBuilder().header("Cache-Control",
"public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
if(connToInternet) {
request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
}
else {
request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
}
return chain.proceed(request);
});
@@ -63,8 +66,9 @@ public class RetrofitClient {
retrofit = builder.build();
} catch(Exception e) {
e.printStackTrace();
}
catch(Exception e) {
Log.e("onFailure", e.toString());
}
}