Merge pull request #6886 from nextcloud/docImage

DocumentsStorageProvider: open thumbnail directly
This commit is contained in:
Tobias Kaminsky 2020-09-07 10:02:35 +02:00 committed by GitHub
commit 51cf63b79b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View file

@ -70,15 +70,17 @@ public class DiskLruImageCacheFileProvider extends ContentProvider {
@Override
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
OCFile ocFile = getFile(uri);
return getParcelFileDescriptorForOCFile(getFile(uri));
}
public static ParcelFileDescriptor getParcelFileDescriptorForOCFile(OCFile ocFile) throws FileNotFoundException {
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
String.valueOf(ThumbnailsCacheManager.PREFIX_RESIZED_IMAGE + ocFile.getRemoteId()));
ThumbnailsCacheManager.PREFIX_RESIZED_IMAGE + ocFile.getRemoteId());
// fallback to thumbnail
if (thumbnail == null) {
thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
String.valueOf(ThumbnailsCacheManager.PREFIX_THUMBNAIL + ocFile.getRemoteId()));
ThumbnailsCacheManager.PREFIX_THUMBNAIL + ocFile.getRemoteId());
}
// fallback to default image

View file

@ -76,7 +76,6 @@ import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.ui.activity.SettingsActivity;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.UriUtils;
import org.nextcloud.providers.cursors.FileCursor;
import org.nextcloud.providers.cursors.RootCursor;
@ -312,19 +311,18 @@ public class DocumentsStorageProvider extends DocumentsProvider {
throw new FileNotFoundException("Context may not be null!");
}
Document document = toDocument(documentId);
OCFile file = toDocument(documentId).getFile();
boolean exists = ThumbnailsCacheManager.containsBitmap(ThumbnailsCacheManager.PREFIX_THUMBNAIL
+ document.getFile().getRemoteId());
+ file.getRemoteId());
if (!exists) {
ThumbnailsCacheManager.generateThumbnailFromOCFile(document.getFile());
ThumbnailsCacheManager.generateThumbnailFromOCFile(file);
}
Uri uri = Uri.parse(UriUtils.URI_CONTENT_SCHEME + context.getResources().getString(
R.string.image_cache_provider_authority) + document.getRemotePath());
Log.d(TAG, "open thumbnail, uri=" + uri);
return context.getContentResolver().openAssetFileDescriptor(uri, "r");
return new AssetFileDescriptor(DiskLruImageCacheFileProvider.getParcelFileDescriptorForOCFile(file),
0,
file.getFileLength());
}
@Override