From e1ccb4e40472a27082ea1f65951036161a670803 Mon Sep 17 00:00:00 2001 From: anonTree1417 Date: Tue, 31 Mar 2020 16:41:50 +0200 Subject: [PATCH] Fixed formatting. --- .../mian/gitnex/activities/LoginActivity.java | 7 +++-- .../mian/gitnex/clients/IssuesService.java | 14 ++++++---- .../gitnex/clients/PullRequestsService.java | 14 ++++++---- .../mian/gitnex/clients/RetrofitClient.java | 28 +++++++++++-------- .../gitnex/ssl/MemorizingTrustManager.java | 1 + app/src/main/res/values/strings.xml | 4 +-- 6 files changed, 38 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java b/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java index 1b6aef02..326dca9e 100644 --- a/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java @@ -21,7 +21,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import com.tooltip.Tooltip; -import org.jetbrains.annotations.NotNull; import org.mian.gitnex.R; import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.helpers.Toasty; @@ -455,9 +454,10 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener } @Override - public void onFailure(@NonNull Call callVersion, @NotNull Throwable throwable) { - Log.e("onFailure-version", throwable.toString()); + public void onFailure(@NonNull Call callVersion, Throwable t) { + Log.e("onFailure-version", t.toString()); } + }); } @@ -481,6 +481,7 @@ public class LoginActivity extends BaseActivity implements View.OnClickListener if (response.isSuccessful()) { if (response.code() == 200) { + tinyDb.putBoolean("loggedInMode", true); assert userDetails != null; tinyDb.putString(userDetails.getLogin() + "-token", loginToken_); diff --git a/app/src/main/java/org/mian/gitnex/clients/IssuesService.java b/app/src/main/java/org/mian/gitnex/clients/IssuesService.java index d65afc57..e1600578 100644 --- a/app/src/main/java/org/mian/gitnex/clients/IssuesService.java +++ b/app/src/main/java/org/mian/gitnex/clients/IssuesService.java @@ -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 createService(Class serviceClass, String instanceURL, Context context) { + public static S createService(Class 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; diff --git a/app/src/main/java/org/mian/gitnex/clients/PullRequestsService.java b/app/src/main/java/org/mian/gitnex/clients/PullRequestsService.java index c54077ef..e5e6a29c 100644 --- a/app/src/main/java/org/mian/gitnex/clients/PullRequestsService.java +++ b/app/src/main/java/org/mian/gitnex/clients/PullRequestsService.java @@ -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 createService(Class serviceClass, String instanceURL, Context context) { + public static S createService(Class 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; diff --git a/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java b/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java index 7c19f895..a9a0102d 100644 --- a/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java +++ b/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java @@ -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()); } } diff --git a/app/src/main/java/org/mian/gitnex/ssl/MemorizingTrustManager.java b/app/src/main/java/org/mian/gitnex/ssl/MemorizingTrustManager.java index fc184b5d..fc275ef9 100644 --- a/app/src/main/java/org/mian/gitnex/ssl/MemorizingTrustManager.java +++ b/app/src/main/java/org/mian/gitnex/ssl/MemorizingTrustManager.java @@ -44,6 +44,7 @@ import javax.net.ssl.X509TrustManager; /** * Author Georg Lukas, modified by anonTree1417 */ + public class MemorizingTrustManager implements X509TrustManager { private final static String DECISION_INTENT = "de.duenndns.ssl.DECISION"; final static String DECISION_INTENT_ID = DECISION_INTENT + ".decisionId"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa2f1c16..a8d14bf7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -567,18 +567,16 @@ Changelog + Certificate Verification Accept Unknown Certificate? The server certificate is not signed by a known Certificate Authority. The server certificate is expired. Accept Mismatching Server Name? Server could not authenticate as \"%s\". The certificate is only valid for: - Do you want to connect anyway? Certificate details: - Always Once Abort - Certificate Verification