diff --git a/owncloudApp/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java b/owncloudApp/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index 7cb065a63eb..da5629c8c5a 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/owncloudApp/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@ -37,13 +37,11 @@ import androidx.core.content.ContextCompat; import com.owncloud.android.MainApp; import com.owncloud.android.R; -import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.SingleSessionManager; import com.owncloud.android.lib.common.http.HttpConstants; import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.ui.adapter.DiskLruImageCache; import com.owncloud.android.utils.BitmapUtils; import timber.log.Timber; @@ -52,6 +50,7 @@ import java.io.InputStream; import java.lang.ref.WeakReference; import java.net.URL; +import java.util.Locale; /** * Manager for concurrent access to thumbnails cache. @@ -69,6 +68,8 @@ public class ThumbnailsCacheManager { private static final int mCompressQuality = 70; private static OwnCloudClient mClient = null; + private static final String PREVIEW_URI = "%s/remote.php/dav/files/%s%s?x=%d&y=%d&c=%s&preview=1"; + public static Bitmap mDefaultImg = BitmapFactory.decodeResource( MainApp.Companion.getAppContext().getResources(), @@ -249,6 +250,17 @@ private int getThumbnailDimension() { return Math.round(r.getDimension(R.dimen.file_icon_size_grid)); } + private String getPreviewUrl(OCFile ocFile, Account account) { + return String.format(Locale.ROOT, + PREVIEW_URI, + mClient.getBaseUri(), + account.name.split("@")[0], + Uri.encode(ocFile.getRemotePath(), "/"), + getThumbnailDimension(), + getThumbnailDimension(), + ocFile.getEtag()); + } + private Bitmap doOCFileInBackground() { OCFile file = (OCFile) mFile; @@ -281,13 +293,10 @@ private Bitmap doOCFileInBackground() { } else { // Download thumbnail from server - OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount); - if (mClient != null && serverOCVersion != null) { + if (mClient != null) { GetMethod get; try { - String uri = mClient.getBaseUri() + "" + - "/index.php/apps/files/api/v1/thumbnail/" + - px + "/" + px + Uri.encode(file.getRemotePath(), "/"); + String uri = getPreviewUrl(file, mAccount); Timber.d("URI: %s", uri); get = new GetMethod(new URL(uri)); int status = mClient.executeHttpMethod(get); diff --git a/owncloudApp/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java b/owncloudApp/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java index fb0f8a4fbd2..f382204b632 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/owncloudApp/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -354,7 +354,6 @@ private void mergeRemoteFolder(ArrayList remoteFolderAndFiles) // remote eTag will not be set unless file CONTENTS are synchronized updatedLocalFile.setEtag(localFile.getEtag()); if (!updatedLocalFile.isFolder() && - remoteFile.isImage() && remoteFile.getModificationTimestamp() != localFile.getModificationTimestamp()) { updatedLocalFile.setNeedsUpdateThumbnail(true); } diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java b/owncloudApp/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java index 27d583e2498..4bc58b55755 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -80,8 +80,6 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { private Account mAccount; private ComponentsGetter mTransferServiceGetter; - private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM} - public FileListListAdapter( boolean justFolders, boolean onlyAvailableOffline, @@ -283,7 +281,9 @@ public View getView(int position, View convertView, ViewGroup parent) { file.isSharedWithMe() || file.isSharedWithSharee(), file.isSharedViaLink())); } else { - if (file.isImage() && file.getRemoteId() != null) { + // Set file icon depending on its mimetype. Ask for thumbnail later. + fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(file.getMimetype(), file.getFileName())); + if (file.getRemoteId() != null) { // Thumbnail in Cache? Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(file.getRemoteId()); if (thumbnail != null && !file.needsUpdateThumbnail()) { @@ -295,16 +295,16 @@ public View getView(int position, View convertView, ViewGroup parent) { new ThumbnailsCacheManager.ThumbnailGenerationTask( fileIcon, mStorageManager, mAccount ); - if (thumbnail == null) { - thumbnail = ThumbnailsCacheManager.mDefaultImg; - } final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable = new ThumbnailsCacheManager.AsyncThumbnailDrawable( mContext.getResources(), thumbnail, task ); - fileIcon.setImageDrawable(asyncDrawable); + // If drawable is not visible, do not update it. + if (asyncDrawable.getMinimumHeight() > 0 && asyncDrawable.getMinimumWidth() > 0) { + fileIcon.setImageDrawable(asyncDrawable); + } task.execute(file); } } @@ -314,9 +314,6 @@ public View getView(int position, View convertView, ViewGroup parent) { .getColor(R.color.background_color)); } - } else { - fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(file.getMimetype(), - file.getFileName())); } } @@ -501,4 +498,6 @@ public void clearFilterBySearch() { mFiles = (Vector) mImmutableFilesList.clone(); notifyDataSetChanged(); } + + private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM} }