quick improvements (#1133)

As title

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1133
This commit is contained in:
M M Arif 2022-05-15 19:19:00 +02:00
parent 7ae2619603
commit 7af62564eb
4 changed files with 17 additions and 18 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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();

View File

@ -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);
}