mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 07:05:49 +03:00
extracted method and improved code
Signed-off-by: camillo-positano <camillo.positano@hotmail.it>
This commit is contained in:
parent
d42198a96f
commit
92d641eabc
1 changed files with 46 additions and 39 deletions
|
@ -296,27 +296,20 @@ public final class ThumbnailsCacheManager {
|
|||
if (file.getRemoteId() != null || file.isPreviewAvailable()) {
|
||||
// Thumbnail in cache?
|
||||
thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
||||
ThumbnailsCacheManager.PREFIX_RESIZED_IMAGE + file.getRemoteId()
|
||||
);
|
||||
ThumbnailsCacheManager.PREFIX_RESIZED_IMAGE + file.getRemoteId());
|
||||
|
||||
if (thumbnail != null && !file.isUpdateThumbnailNeeded()) {
|
||||
Float size = (float) ThumbnailsCacheManager.getThumbnailDimension();
|
||||
if (thumbnail != null && !file.isUpdateThumbnailNeeded())
|
||||
return getThumbnailFromCache(thumbnail);
|
||||
|
||||
// resized dimensions
|
||||
ImageDimension imageDimension = file.getImageDimension();
|
||||
if (imageDimension == null ||
|
||||
imageDimension.getWidth() != size ||
|
||||
imageDimension.getHeight() != size) {
|
||||
file.setImageDimension(new ImageDimension(thumbnail.getWidth(), thumbnail.getHeight()));
|
||||
storageManager.saveFile(file);
|
||||
return getThumbnailFromServerAndAddToCache(thumbnail);
|
||||
}
|
||||
|
||||
if (MimeTypeUtil.isVideo(file)) {
|
||||
return ThumbnailsCacheManager.addVideoOverlay(thumbnail, MainApp.getAppContext());
|
||||
} else {
|
||||
return thumbnail;
|
||||
Log_OC.d(TAG, "File cannot be previewed");
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
|
||||
@Nullable
|
||||
private Bitmap getThumbnailFromServerAndAddToCache(Bitmap thumbnail) {
|
||||
try {
|
||||
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(user.toOwnCloudAccount(),
|
||||
MainApp.getAppContext());
|
||||
|
@ -337,10 +330,24 @@ public final class ThumbnailsCacheManager {
|
|||
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
private Bitmap getThumbnailFromCache(Bitmap thumbnail) {
|
||||
float size = (float) ThumbnailsCacheManager.getThumbnailDimension();
|
||||
|
||||
// resized dimensions
|
||||
ImageDimension imageDimension = file.getImageDimension();
|
||||
if (imageDimension == null ||
|
||||
imageDimension.getWidth() != size ||
|
||||
imageDimension.getHeight() != size) {
|
||||
file.setImageDimension(new ImageDimension(thumbnail.getWidth(), thumbnail.getHeight()));
|
||||
storageManager.saveFile(file);
|
||||
}
|
||||
|
||||
Log_OC.d(TAG, "File cannot be previewed");
|
||||
return null;
|
||||
if (MimeTypeUtil.isVideo(file)) {
|
||||
return ThumbnailsCacheManager.addVideoOverlay(thumbnail, MainApp.getAppContext());
|
||||
} else {
|
||||
return thumbnail;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onPostExecute(Bitmap bitmap) {
|
||||
|
|
Loading…
Reference in a new issue