Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.29] Nmc/2136 Auto upload behaviour #207

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -35,6 +35,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import androidx.core.content.res.ResourcesCompat;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;

Expand Down Expand Up @@ -337,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 Expand Up @@ -445,7 +449,9 @@ private MainViewHolder(GridSyncItemBinding binding) {
private void setSyncButtonActiveIcon(ImageButton syncStatusButton, boolean enabled) {
if (enabled) {
syncStatusButton.setImageDrawable(
viewThemeUtils.platform.tintPrimaryDrawable(context, R.drawable.ic_cloud_sync_on)
viewThemeUtils.platform.colorDrawable(ResourcesCompat.getDrawable(context.getResources(),
R.drawable.ic_cloud_sync_on, null),
ResourcesCompat.getColor(context.getResources(), R.color.primary, null))
);
} else {
syncStatusButton.setImageResource(R.drawable.ic_cloud_sync_off);
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>
6 changes: 4 additions & 2 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
<resources>
<string-array name="pref_behaviour_entries" translatable="false">
<item>@string/pref_behaviour_entries_keep_file</item>
<item>@string/pref_behaviour_entries_move</item>
<!-- not required for NMC -->
<!-- <item>@string/pref_behaviour_entries_move</item> -->
<item>@string/pref_behaviour_entries_delete_file</item>
</string-array>

<string-array name="pref_behaviour_entryValues" translatable="false">
<item>LOCAL_BEHAVIOUR_FORGET</item>
<item>LOCAL_BEHAVIOUR_MOVE</item>
<!-- not required for NMC -->
<!-- <item>LOCAL_BEHAVIOUR_MOVE</item> -->
<item>LOCAL_BEHAVIOUR_DELETE</item>
</string-array>

Expand Down
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