mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 18:28:59 +03:00
If no thumbnail exists, check if resized version exist and generate thumbnail out of it
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
81681f495a
commit
5ca5555fe6
1 changed files with 37 additions and 31 deletions
|
@ -529,10 +529,16 @@ public class ThumbnailsCacheManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Download thumbnail from server
|
// check if resized version is available
|
||||||
OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount);
|
String resizedImageKey = PREFIX_RESIZED_IMAGE + String.valueOf(file.getRemoteId());
|
||||||
|
Bitmap resizedImage = getBitmapFromDiskCache(resizedImageKey);
|
||||||
|
|
||||||
if (mClient != null) {
|
if (resizedImage != null) {
|
||||||
|
thumbnail = ThumbnailUtils.extractThumbnail(resizedImage, pxW, pxH);
|
||||||
|
} else {
|
||||||
|
//Download thumbnail from server
|
||||||
|
OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount);
|
||||||
|
if (mClient != null) {
|
||||||
if (serverOCVersion.supportsRemoteThumbnails()) {
|
if (serverOCVersion.supportsRemoteThumbnails()) {
|
||||||
getMethod = null;
|
getMethod = null;
|
||||||
try {
|
try {
|
||||||
|
@ -545,40 +551,40 @@ public class ThumbnailsCacheManager {
|
||||||
getMethod.setRequestHeader("Cookie",
|
getMethod.setRequestHeader("Cookie",
|
||||||
"nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
|
"nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
|
||||||
|
|
||||||
getMethod.setRequestHeader(RemoteOperation.OCS_API_HEADER,
|
getMethod.setRequestHeader(RemoteOperation.OCS_API_HEADER,
|
||||||
RemoteOperation.OCS_API_HEADER_VALUE);
|
RemoteOperation.OCS_API_HEADER_VALUE);
|
||||||
|
|
||||||
int status = mClient.executeMethod(getMethod);
|
int status = mClient.executeMethod(getMethod);
|
||||||
if (status == HttpStatus.SC_OK) {
|
if (status == HttpStatus.SC_OK) {
|
||||||
InputStream inputStream = getMethod.getResponseBodyAsStream();
|
InputStream inputStream = getMethod.getResponseBodyAsStream();
|
||||||
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
|
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
|
||||||
thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH);
|
thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH);
|
||||||
} else {
|
} else {
|
||||||
mClient.exhaustResponse(getMethod.getResponseBodyAsStream());
|
mClient.exhaustResponse(getMethod.getResponseBodyAsStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle PNG
|
// Handle PNG
|
||||||
if (file.getMimetype().equalsIgnoreCase(PNG_MIMETYPE)) {
|
if (file.getMimetype().equalsIgnoreCase(PNG_MIMETYPE)) {
|
||||||
thumbnail = handlePNG(thumbnail, pxW, pxH);
|
thumbnail = handlePNG(thumbnail, pxW, pxH);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
// Add thumbnail to cache
|
Log_OC.d(TAG, e.getMessage(), e);
|
||||||
if (thumbnail != null) {
|
} finally {
|
||||||
Log_OC.d(TAG, "add thumbnail to cache: " + file.getFileName());
|
if (getMethod != null) {
|
||||||
addBitmapToCache(imageKey, thumbnail);
|
getMethod.releaseConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log_OC.d(TAG, e.getMessage(), e);
|
|
||||||
} finally {
|
|
||||||
if (getMethod != null) {
|
|
||||||
getMethod.releaseConnection();
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log_OC.d(TAG, "Server too old");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Log_OC.d(TAG, "Server too old");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add thumbnail to cache
|
||||||
|
if (thumbnail != null) {
|
||||||
|
Log_OC.d(TAG, "add thumbnail to cache: " + file.getFileName());
|
||||||
|
addBitmapToCache(imageKey, thumbnail);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue