From 30ab5a6b57d4f9ab2189482bd8969adb08340a1f Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Sat, 25 Jun 2016 16:23:43 +0200 Subject: [PATCH] code review: use string instead of object to not having to do instance of checks --- .../datamodel/ThumbnailsCacheManager.java | 43 +++---------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index e762a109ef..c41795a76f 100644 --- a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@ -350,11 +350,11 @@ public class ThumbnailsCacheManager { } - public static class AvatarGenerationTask extends AsyncTask { + public static class AvatarGenerationTask extends AsyncTask { private final WeakReference mAvatarGenerationListener; private final Object mCallContext; private Account mAccount; - private Object mUsername; + private String mUsername; public AvatarGenerationTask(AvatarGenerationListener avatarGenerationListener, Object callContext, @@ -367,7 +367,7 @@ public class ThumbnailsCacheManager { } @Override - protected Bitmap doInBackground(Object... params) { + protected Bitmap doInBackground(String... params) { Bitmap thumbnail = null; try { @@ -379,10 +379,7 @@ public class ThumbnailsCacheManager { } mUsername = params[0]; - - if (mUsername instanceof String) { - thumbnail = doAvatarInBackground(); - } + thumbnail = doAvatarInBackground(); } catch(Throwable t){ // the app should never break due to a problem with avatars @@ -401,12 +398,8 @@ public class ThumbnailsCacheManager { AvatarGenerationListener listener = mAvatarGenerationListener.get(); AvatarGenerationTask avatarWorkerTask = getAvatarWorkerTask(mCallContext); if (this == avatarWorkerTask) { - String tagId = ""; - if (mUsername instanceof String) { - tagId = (String) mUsername; - if (listener.shouldCallGeneratedCallback(tagId, mCallContext)) { - listener.avatarGenerated(new BitmapDrawable(bitmap), mCallContext); - } + if (listener.shouldCallGeneratedCallback(mUsername, mCallContext)) { + listener.avatarGenerated(new BitmapDrawable(bitmap), mCallContext); } } } @@ -495,30 +488,6 @@ public class ThumbnailsCacheManager { } return avatar; } - - private Bitmap doFileInBackground() { - File file = (File) mUsername; - - final String imageKey = String.valueOf(file.hashCode()); - - // Check disk cache in background thread - Bitmap thumbnail = getBitmapFromDiskCache(imageKey); - - // Not found in disk cache - if (thumbnail == null) { - - int px = getAvatarDimension(); - - Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile( - file.getAbsolutePath(), px, px); - - if (bitmap != null) { - thumbnail = addThumbnailToCache(imageKey, bitmap, file.getPath(), px); - } - } - return thumbnail; - } - } public static boolean cancelPotentialThumbnailWork(Object file, ImageView imageView) {