Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring Large Method getCoverByThumbnailSize in AbstractManager #116

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions 0001-Refactoring-Large-Method-Class-AbstractManager.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
From 5642a0158aef466b308722e91c611ae313905a07 Mon Sep 17 00:00:00 2001
From: Samer El-Achkar <[email protected]>
Date: Fri, 28 Nov 2014 14:24:55 -0500
Subject: [PATCH 1/1] Refactoring Large Method Class AbstractManager

Extract method getCoverByThumbnailSize() from getCover()
---
.../android/remote/business/AbstractManager.java | 37 ++++++++++++++--------
1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/org/xbmc/android/remote/business/AbstractManager.java b/src/org/xbmc/android/remote/business/AbstractManager.java
index a73c825..2ab116b 100644
--- a/src/org/xbmc/android/remote/business/AbstractManager.java
+++ b/src/org/xbmc/android/remote/business/AbstractManager.java
@@ -176,26 +176,35 @@ public abstract class AbstractManager implements INotifiableManager {
mHandler.post(new Runnable() {
public void run() {
if (cover.getCrc() != 0L) {
- // first, try mem cache (only if size = small, other sizes aren't mem-cached.
- if (thumbSize == ThumbSize.SMALL || thumbSize == ThumbSize.MEDIUM) {
- if (DEBUG) Log.i(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] Trying memory (" + Crc32.formatAsHexLowerCase(cover.getCrc()) + ")");
- getCoverFromMem(response, cover, thumbSize, defaultCover, context, getFromCacheOnly);
- } else {
- if (getFromCacheOnly) {
- Log.e(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] ERROR: NOT downloading big covers is a bad idea because they are not cached!");
- response.value = null;
- onFinish(response);
- } else {
- if (DEBUG) Log.i(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] Downloading directly");
- getCoverFromNetwork(response, cover, thumbSize, context);
- }
- }
+
+ getCoverByThumbnailSize(response, cover, thumbSize,
+ defaultCover, context, getFromCacheOnly);
} else {
if (DEBUG) Log.i(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] no crc, skipping.");
response.value = null;
onFinish(response);
}
}
+
+ private void getCoverByThumbnailSize(
+ final DataResponse<Bitmap> response, final ICoverArt cover,
+ final int thumbSize, final Bitmap defaultCover,
+ final Context context, final boolean getFromCacheOnly) {
+ // first, try mem cache (only if size = small, other sizes aren't mem-cached.
+ if (thumbSize == ThumbSize.SMALL || thumbSize == ThumbSize.MEDIUM) {
+ if (DEBUG) Log.i(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] Trying memory (" + Crc32.formatAsHexLowerCase(cover.getCrc()) + ")");
+ getCoverFromMem(response, cover, thumbSize, defaultCover, context, getFromCacheOnly);
+ } else {
+ if (getFromCacheOnly) {
+ Log.e(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] ERROR: NOT downloading big covers is a bad idea because they are not cached!");
+ response.value = null;
+ onFinish(response);
+ } else {
+ if (DEBUG) Log.i(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] Downloading directly");
+ getCoverFromNetwork(response, cover, thumbSize, context);
+ }
+ }
+ }
});
}

--
1.9.4.msysgit.2

37 changes: 23 additions & 14 deletions src/org/xbmc/android/remote/business/AbstractManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,35 @@ public void getCover(final DataResponse<Bitmap> response, final ICoverArt cover,
mHandler.post(new Runnable() {
public void run() {
if (cover.getCrc() != 0L) {
// first, try mem cache (only if size = small, other sizes aren't mem-cached.
if (thumbSize == ThumbSize.SMALL || thumbSize == ThumbSize.MEDIUM) {
if (DEBUG) Log.i(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] Trying memory (" + Crc32.formatAsHexLowerCase(cover.getCrc()) + ")");
getCoverFromMem(response, cover, thumbSize, defaultCover, context, getFromCacheOnly);
} else {
if (getFromCacheOnly) {
Log.e(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] ERROR: NOT downloading big covers is a bad idea because they are not cached!");
response.value = null;
onFinish(response);
} else {
if (DEBUG) Log.i(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] Downloading directly");
getCoverFromNetwork(response, cover, thumbSize, context);
}
}

getCoverByThumbnailSize(response, cover, thumbSize,
defaultCover, context, getFromCacheOnly);
} else {
if (DEBUG) Log.i(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] no crc, skipping.");
response.value = null;
onFinish(response);
}
}

private void getCoverByThumbnailSize(
final DataResponse<Bitmap> response, final ICoverArt cover,
final int thumbSize, final Bitmap defaultCover,
final Context context, final boolean getFromCacheOnly) {
// first, try mem cache (only if size = small, other sizes aren't mem-cached.
if (thumbSize == ThumbSize.SMALL || thumbSize == ThumbSize.MEDIUM) {
if (DEBUG) Log.i(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] Trying memory (" + Crc32.formatAsHexLowerCase(cover.getCrc()) + ")");
getCoverFromMem(response, cover, thumbSize, defaultCover, context, getFromCacheOnly);
} else {
if (getFromCacheOnly) {
Log.e(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] ERROR: NOT downloading big covers is a bad idea because they are not cached!");
response.value = null;
onFinish(response);
} else {
if (DEBUG) Log.i(TAG, "[" + cover.getId() + ThumbSize.getDir(thumbSize) + "] Downloading directly");
getCoverFromNetwork(response, cover, thumbSize, context);
}
}
}
});
}

Expand Down