From 7af62564ebd58e98261616093aa0c4e6d2f49f10 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Sun, 15 May 2022 19:19:00 +0200 Subject: [PATCH] quick improvements (#1133) As title Co-authored-by: M M Arif Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1133 --- .../org/mian/gitnex/clients/PicassoService.java | 13 +++++++------ .../org/mian/gitnex/clients/RetrofitClient.java | 4 ++-- .../java/org/mian/gitnex/helpers/AlertDialogs.java | 4 ++-- .../java/org/mian/gitnex/helpers/PicassoCache.java | 14 ++++++-------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/clients/PicassoService.java b/app/src/main/java/org/mian/gitnex/clients/PicassoService.java index fce5157d..4ebae272 100644 --- a/app/src/main/java/org/mian/gitnex/clients/PicassoService.java +++ b/app/src/main/java/org/mian/gitnex/clients/PicassoService.java @@ -9,6 +9,7 @@ import org.mian.gitnex.helpers.PicassoCache; import org.mian.gitnex.helpers.ssl.MemorizingTrustManager; import java.io.File; import java.security.SecureRandom; +import java.util.Objects; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.X509TrustManager; @@ -41,12 +42,12 @@ public class PicassoService { .hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())); builder.downloader(new OkHttp3Downloader(okHttpClient.build())); -// builder.listener((picasso, uri, exception) -> { -// -// Log.e("PicassoService", Objects.requireNonNull(uri.toString())); -// Log.e("PicassoService", exception.toString()); -// -// }); + builder.listener((picasso, uri, exception) -> { + + Log.e("PicassoService", Objects.requireNonNull(uri.toString())); + Log.e("PicassoService", exception.toString()); + + }); picasso = builder.memoryCache(new PicassoCache(cachePath, context)).build(); 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 99410a7e..26f82b00 100644 --- a/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java +++ b/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java @@ -134,7 +134,7 @@ public class RetrofitClient { synchronized(RetrofitClient.class) { if(!apiInterfaces.containsKey(key)) { - ApiInterface apiInterface = createRetrofit(context, url, true, token, cacheFile).create(ApiInterface.class); + ApiInterface apiInterface = Objects.requireNonNull(createRetrofit(context, url, true, token, cacheFile)).create(ApiInterface.class); apiInterfaces.put(key, apiInterface); return apiInterface; @@ -153,7 +153,7 @@ public class RetrofitClient { synchronized(RetrofitClient.class) { if(!webInterfaces.containsKey(key)) { - WebApi webInterface = createRetrofit(context, url, false, token, cacheFile).create(WebApi.class); + WebApi webInterface = Objects.requireNonNull(createRetrofit(context, url, false, token, cacheFile)).create(WebApi.class); webInterfaces.put(key, webInterface); return webInterface; diff --git a/app/src/main/java/org/mian/gitnex/helpers/AlertDialogs.java b/app/src/main/java/org/mian/gitnex/helpers/AlertDialogs.java index b385df92..4800ba71 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/AlertDialogs.java +++ b/app/src/main/java/org/mian/gitnex/helpers/AlertDialogs.java @@ -86,7 +86,7 @@ public class AlertDialogs { public static void addRepoDialog(final Context context, final String orgName, String repo, int teamId, String teamName) { new AlertDialog.Builder(context) - .setTitle(context.getResources().getString(R.string.addTeamMember) + repo) + .setTitle(context.getResources().getString(R.string.addTeamMember, repo)) .setMessage(context.getResources().getString(R.string.repoAddToTeamMessage, repo, orgName, teamName)) .setPositiveButton(context.getResources().getString(R.string.addButton), (dialog, whichButton) -> TeamActions.addTeamRepo(context, orgName, teamId, repo)) .setNeutralButton(context.getResources().getString(R.string.cancelButton), null).show(); @@ -96,7 +96,7 @@ public class AlertDialogs { public static void removeRepoDialog(final Context context, final String orgName, String repo, int teamId, String teamName) { new AlertDialog.Builder(context) - .setTitle(context.getResources().getString(R.string.removeTeamMember) + repo) + .setTitle(context.getResources().getString(R.string.removeTeamMember, repo)) .setMessage(context.getResources().getString(R.string.repoRemoveTeamMessage, repo, teamName)) .setPositiveButton(context.getResources().getString(R.string.removeButton), (dialog, whichButton) -> TeamActions.removeTeamRepo(context, orgName, teamId, repo)) .setNeutralButton(context.getResources().getString(R.string.cancelButton), null).show(); diff --git a/app/src/main/java/org/mian/gitnex/helpers/PicassoCache.java b/app/src/main/java/org/mian/gitnex/helpers/PicassoCache.java index 469c07ce..833080a8 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/PicassoCache.java +++ b/app/src/main/java/org/mian/gitnex/helpers/PicassoCache.java @@ -14,16 +14,17 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.UUID; /** - * Author opyale + * @author opyale */ public class PicassoCache implements Cache { private Context ctx; - private String TAG = "PicassoCache"; + private final String TAG = "PicassoCache"; private static final Bitmap.CompressFormat COMPRESS_FORMAT = Bitmap.CompressFormat.PNG; private static final int COMPRESSION_QUALITY = 50; // 0 = high compression (low file size) | 100 = no compression @@ -56,24 +57,21 @@ public class PicassoCache implements Cache { if(cacheMap.containsKey(key)) { - FileInputStream fileInputStream = new FileInputStream(new File(cachePath, cacheMap.get(key))); + FileInputStream fileInputStream = new FileInputStream(new File(cachePath, Objects.requireNonNull(cacheMap.get(key)))); Bitmap bitmap = BitmapFactory.decodeStream(fileInputStream); fileInputStream.close(); return bitmap; - } } catch(IOException e) { Log.e(TAG, e.toString()); - } return null; - } @Override @@ -109,7 +107,7 @@ public class PicassoCache implements Cache { for(String key : cacheMap.keySet()) { - currentSize += new File(cachePath, cacheMap.get(key)).length(); + currentSize += new File(cachePath, Objects.requireNonNull(cacheMap.get(key))).length(); } @@ -163,7 +161,7 @@ public class PicassoCache implements Cache { if(match) { //noinspection ResultOfMethodCallIgnored - new File(cachePath, cacheMap.get(key)).delete(); + new File(cachePath, Objects.requireNonNull(cacheMap.get(key))).delete(); cacheMap.remove(key); }