Skip to content

Commit

Permalink
Fix scroll lagging for auto-upload files. (NMC-2589)
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder-tsys committed Aug 5, 2024
1 parent fec82c1 commit 6f88232
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.net.URLEncoder;
import java.util.List;

import androidx.annotation.DimenRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
Expand Down Expand Up @@ -158,9 +159,19 @@ protected Void doInBackground(File... params) {
* @return int
*/
public static int getThumbnailDimension() {
return getThumbnailDimension(R.dimen.file_icon_size_grid);
}

/**
* Converts size of file icon from dp to pixel
* this function is required for custom thumbnail sizes
* @param thumbnailDimension dimension to be converted
* @return int
*/
public static int getThumbnailDimension(@DimenRes int thumbnailDimension) {
// Converts dp to pixel
Resources r = MainApp.getAppContext().getResources();
return Math.round(r.getDimension(R.dimen.file_icon_size_grid));
return Math.round(r.getDimension(thumbnailDimension));
}

/**
Expand Down Expand Up @@ -815,14 +826,25 @@ private enum Type {IMAGE, VIDEO}
private String mImageKey;
private final Context mContext;
private final ViewThemeUtils viewThemeUtils;
@DimenRes
private final int thumbnailDimension;

public MediaThumbnailGenerationTask(ImageView imageView,
Context context,
ViewThemeUtils viewThemeUtils) {
this(imageView, context, R.dimen.file_icon_size_grid, viewThemeUtils);
}

// constructor to generate thumbnails for the requested size
public MediaThumbnailGenerationTask(ImageView imageView,
Context context,
@DimenRes int thumbnailDimension,
ViewThemeUtils viewThemeUtils) {
// Use a WeakReference to ensure the ImageView can be garbage collected
mImageViewReference = new WeakReference<>(imageView);
mContext = context;
this.viewThemeUtils = viewThemeUtils;
this.thumbnailDimension = thumbnailDimension;
}

@Override
Expand All @@ -837,9 +859,9 @@ protected Bitmap doInBackground(Object... params) {
}

if (MimeTypeUtil.isImage(mFile)) {
thumbnail = doFileInBackground(mFile, Type.IMAGE);
thumbnail = doFileInBackground(mFile, Type.IMAGE, thumbnailDimension);
} else if (MimeTypeUtil.isVideo(mFile)) {
thumbnail = doFileInBackground(mFile, Type.VIDEO);
thumbnail = doFileInBackground(mFile, Type.VIDEO, thumbnailDimension);
}
}
} // the app should never break due to a problem with thumbnails
Expand Down Expand Up @@ -885,7 +907,7 @@ protected void onPostExecute(Bitmap bitmap) {
}
}

private Bitmap doFileInBackground(File file, Type type) {
private Bitmap doFileInBackground(File file, Type type, @DimenRes int thumbnailDimension) {
final String imageKey;

if (mImageKey != null) {
Expand All @@ -901,7 +923,7 @@ private Bitmap doFileInBackground(File file, Type type) {
if (thumbnail == null) {

if (Type.IMAGE == type) {
int px = getThumbnailDimension();
int px = getThumbnailDimension(thumbnailDimension);

Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(file.getAbsolutePath(), px, px);

Expand All @@ -927,7 +949,7 @@ private Bitmap doFileInBackground(File file, Type type) {

if (thumbnail != null) {
// Scale down bitmap if too large.
int px = getThumbnailDimension();
int px = getThumbnailDimension(thumbnailDimension);
int width = thumbnail.getWidth();
int height = thumbnail.getHeight();
int max = Math.max(width, height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ public void onBindViewHolder(SectionedViewHolder commonHolder, int section, int
ThumbnailsCacheManager.MediaThumbnailGenerationTask task =
new ThumbnailsCacheManager.MediaThumbnailGenerationTask(holder.binding.thumbnail,
context,
// due to 512dp(NMC) thumb size there was scroll lagging in auto upload
// so for auto upload we have to use different thumb size (NMC-2589)
R.dimen.auto_upload_file_thumb_size,
viewThemeUtils);

ThumbnailsCacheManager.AsyncMediaThumbnailDrawable asyncDrawable =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ public Integer getUploadActionInteger() {
switch (uploadAction) {
case FileUploadWorker.LOCAL_BEHAVIOUR_FORGET:
return 0;
case FileUploadWorker.LOCAL_BEHAVIOUR_MOVE:
return 1;
// NMC customization: No required move
/*case FileUploadWorker.LOCAL_BEHAVIOUR_MOVE:
return 1;*/
case FileUploadWorker.LOCAL_BEHAVIOUR_DELETE:
return 2;
return 1;
}
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-sw600dp/dims.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
<resources>
<integer name="media_grid_width">6</integer>
<dimen name="file_icon_size_grid">512dp</dimen>
<dimen name="auto_upload_file_thumb_size">512dp</dimen>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/dims.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<dimen name="synced_folders_item_type_layout_right_end_margin">24dp</dimen>
<dimen name="synced_folders_recycler_view_layout_margin">-3dp</dimen>
<dimen name="synced_folders_control_width">80dp</dimen>
<dimen name="auto_upload_file_thumb_size">128dp</dimen>
<dimen name="bottom_sheet_text_size">16sp</dimen>
<dimen name="permission_dialog_text_size">18sp</dimen>
<dimen name="button_corner_radius">24dp</dimen>
Expand Down

0 comments on commit 6f88232

Please sign in to comment.