diff --git a/src/main/java/com/owncloud/android/files/services/FileUploader.java b/src/main/java/com/owncloud/android/files/services/FileUploader.java index 0540acab4c..6f67dea872 100644 --- a/src/main/java/com/owncloud/android/files/services/FileUploader.java +++ b/src/main/java/com/owncloud/android/files/services/FileUploader.java @@ -37,6 +37,7 @@ import android.content.Context; import android.content.Intent; import android.graphics.BitmapFactory; import android.os.Binder; +import android.os.Build; import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; @@ -124,10 +125,6 @@ public class FileUploader extends Service public static final String KEY_REMOTE_FILE = "REMOTE_FILE"; public static final String KEY_MIME_TYPE = "MIME_TYPE"; - private Notification mNotification; - - @Inject UserAccountManager accountManager; - /** * Call this Service with only this Intent key if all pending uploads are to be retried. */ @@ -175,13 +172,16 @@ public class FileUploader extends Service public static final int LOCAL_BEHAVIOUR_FORGET = 2; public static final int LOCAL_BEHAVIOUR_DELETE = 3; + + private Notification mNotification; private Looper mServiceLooper; private ServiceHandler mServiceHandler; private IBinder mBinder; private OwnCloudClient mUploadClient; private Account mCurrentAccount; private FileDataStorageManager mStorageManager; - //since there can be only one instance of an Android service, there also just one db connection. + + @Inject UserAccountManager accountManager; @Inject UploadsStorageManager mUploadsStorageManager; @Inject ConnectivityService connectivityService; @Inject PowerManagementService powerManagementService; @@ -189,7 +189,8 @@ public class FileUploader extends Service private IndexedForest mPendingUploads = new IndexedForest<>(); /** - * {@link UploadFileOperation} object of ongoing upload. Can be null. Note: There can only be one concurrent upload! + * {@link UploadFileOperation} object of ongoing upload. Can be null. Note: There can only be one concurrent + * upload! */ private UploadFileOperation mCurrentUpload; @@ -197,17 +198,6 @@ public class FileUploader extends Service private NotificationCompat.Builder mNotificationBuilder; private int mLastPercent; - public static String getUploadsAddedMessage() { - return FileUploader.class.getName() + UPLOADS_ADDED_MESSAGE; - } - - public static String getUploadStartMessage() { - return FileUploader.class.getName() + UPLOAD_START_MESSAGE; - } - - public static String getUploadFinishMessage() { - return FileUploader.class.getName() + UPLOAD_FINISH_MESSAGE; - } @Override public void onRenameUpload() { @@ -215,249 +205,6 @@ public class FileUploader extends Service sendBroadcastUploadStarted(mCurrentUpload); } - /** - * Helper class providing methods to ease requesting commands to {@link FileUploader} . - * - * Avoids the need of checking once and again what extras are needed or optional - * in the {@link Intent} to pass to {@link Context#startService(Intent)}. - */ - public static class UploadRequester { - - /** - * Call to upload several new files - */ - public void uploadNewFile( - Context context, - Account account, - String[] localPaths, - String[] remotePaths, - String[] mimeTypes, - Integer behaviour, - Boolean createRemoteFolder, - int createdBy, - boolean requiresWifi, - boolean requiresCharging - ) { - Intent intent = new Intent(context, FileUploader.class); - - intent.putExtra(FileUploader.KEY_ACCOUNT, account); - intent.putExtra(FileUploader.KEY_LOCAL_FILE, localPaths); - intent.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths); - intent.putExtra(FileUploader.KEY_MIME_TYPE, mimeTypes); - intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour); - intent.putExtra(FileUploader.KEY_CREATE_REMOTE_FOLDER, createRemoteFolder); - intent.putExtra(FileUploader.KEY_CREATED_BY, createdBy); - intent.putExtra(FileUploader.KEY_WHILE_ON_WIFI_ONLY, requiresWifi); - intent.putExtra(FileUploader.KEY_WHILE_CHARGING_ONLY, requiresCharging); - - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - context.startForegroundService(intent); - } else { - context.startService(intent); - } - } - - public void uploadFileWithNameCollisionPolicy( - Context context, - Account account, - String[] localPaths, - String[] remotePaths, - String[] mimeTypes, - Integer behaviour, - Boolean createRemoteFolder, - int createdBy, - boolean requiresWifi, - boolean requiresCharging, - NameCollisionPolicy nameCollisionPolicy - ) { - Intent intent = new Intent(context, FileUploader.class); - - intent.putExtra(FileUploader.KEY_ACCOUNT, account); - intent.putExtra(FileUploader.KEY_LOCAL_FILE, localPaths); - intent.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths); - intent.putExtra(FileUploader.KEY_MIME_TYPE, mimeTypes); - intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour); - intent.putExtra(FileUploader.KEY_CREATE_REMOTE_FOLDER, createRemoteFolder); - intent.putExtra(FileUploader.KEY_CREATED_BY, createdBy); - intent.putExtra(FileUploader.KEY_WHILE_ON_WIFI_ONLY, requiresWifi); - intent.putExtra(FileUploader.KEY_WHILE_CHARGING_ONLY, requiresCharging); - intent.putExtra(FileUploader.KEY_NAME_COLLISION_POLICY, nameCollisionPolicy); - - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - context.startForegroundService(intent); - } else { - context.startService(intent); - } - } - - /** - * Call to upload a file - */ - public void uploadFileWithNameCollisionPolicy(Context context, Account account, String localPath, String remotePath, int - behaviour, String mimeType, boolean createRemoteFile, int createdBy, boolean requiresWifi, - boolean requiresCharging, NameCollisionPolicy nameCollisionPolicy) { - - uploadFileWithNameCollisionPolicy( - context, - account, - new String[]{localPath}, - new String[]{remotePath}, - new String[]{mimeType}, - behaviour, - createRemoteFile, - createdBy, - requiresWifi, - requiresCharging, - nameCollisionPolicy - ); - } - - /** - * Call to upload a new single file - */ - public void uploadNewFile(Context context, Account account, String localPath, String remotePath, int - behaviour, String mimeType, boolean createRemoteFile, int createdBy, boolean requiresWifi, - boolean requiresCharging) { - - uploadNewFile( - context, - account, - new String[]{localPath}, - new String[]{remotePath}, - new String[]{mimeType}, - behaviour, - createRemoteFile, - createdBy, - requiresWifi, - requiresCharging - ); - } - - /** - * Call to update multiple files already uploaded - */ - public void uploadUpdate(Context context, Account account, OCFile[] existingFiles, Integer behaviour, - NameCollisionPolicy nameCollisionPolicy) { - Intent intent = new Intent(context, FileUploader.class); - - intent.putExtra(FileUploader.KEY_ACCOUNT, account); - intent.putExtra(FileUploader.KEY_FILE, existingFiles); - intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour); - intent.putExtra(FileUploader.KEY_NAME_COLLISION_POLICY, nameCollisionPolicy); - - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - context.startForegroundService(intent); - } else { - context.startService(intent); - } - } - - /** - * Call to update a dingle file already uploaded - */ - public void uploadUpdate(Context context, Account account, OCFile existingFile, Integer behaviour, - NameCollisionPolicy nameCollisionPolicy) { - - uploadUpdate(context, account, new OCFile[]{existingFile}, behaviour, nameCollisionPolicy); - } - - - /** - * Call to retry upload identified by remotePath - */ - public void retry (Context context, UserAccountManager accountManager, OCUpload upload) { - if (upload != null && context != null) { - Account account = accountManager.getAccountByName(upload.getAccountName()); - retry(context, account, upload); - } else { - throw new IllegalArgumentException("Null parameter!"); - } - } - - private boolean checkIfUploadCanBeRetried(OCUpload ocUpload, boolean gotWifi, boolean isCharging) { - boolean needsWifi = ocUpload.isUseWifiOnly(); - boolean needsCharging = ocUpload.isWhileChargingOnly(); - - return new File(ocUpload.getLocalPath()).exists() && !(needsCharging && !isCharging) && - !(needsWifi && !gotWifi); - - } - - /** - * Retry a subset of all the stored failed uploads. - * - * @param context Caller {@link Context} - * @param account If not null, only failed uploads to this OC account will be retried; otherwise, - * uploads of all accounts will be retried. - * @param uploadResult If not null, only failed uploads with the result specified will be retried; - * otherwise, failed uploads due to any result will be retried. - */ - public void retryFailedUploads( - @NonNull final Context context, - @Nullable final Account account, - @NonNull final UploadsStorageManager uploadsStorageManager, - @NonNull final ConnectivityService connectivityService, - @NonNull final UserAccountManager accountManager, - @NonNull final PowerManagementService powerManagementService, - @Nullable final UploadResult uploadResult - ) { - OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads(); - Account currentAccount = null; - boolean resultMatch; - boolean accountMatch; - - boolean gotNetwork = connectivityService.getActiveNetworkType() != JobRequest.NetworkType.ANY && - !connectivityService.isInternetWalled(); - boolean gotWifi = gotNetwork && Device.getNetworkType(context).equals(JobRequest.NetworkType.UNMETERED); - boolean charging = Device.getBatteryStatus(context).isCharging(); - boolean isPowerSaving = powerManagementService.isPowerSavingEnabled(); - - for ( OCUpload failedUpload: failedUploads) { - accountMatch = account == null || account.name.equals(failedUpload.getAccountName()); - resultMatch = uploadResult == null || uploadResult.equals(failedUpload.getLastResult()); - if (accountMatch && resultMatch) { - if (currentAccount == null || !currentAccount.name.equals(failedUpload.getAccountName())) { - currentAccount = failedUpload.getAccount(accountManager); - } - - if (!new File(failedUpload.getLocalPath()).exists()) { - if (!failedUpload.getLastResult().equals(UploadResult.FILE_NOT_FOUND)) { - failedUpload.setLastResult(UploadResult.FILE_NOT_FOUND); - uploadsStorageManager.updateUpload(failedUpload); - } - } else { - charging = charging || Device.getBatteryStatus(context).getBatteryPercent() == 1; - if (!isPowerSaving && gotNetwork && checkIfUploadCanBeRetried(failedUpload, gotWifi, charging)) { - retry(context, currentAccount, failedUpload); - } - } - } - } - } - - /** - * Private implementation of retry. - * - * @param context - * @param account - * @param upload - */ - private void retry(Context context, Account account, OCUpload upload) { - if (upload != null) { - Intent i = new Intent(context, FileUploader.class); - i.putExtra(FileUploader.KEY_RETRY, true); - i.putExtra(FileUploader.KEY_ACCOUNT, account); - i.putExtra(FileUploader.KEY_RETRY_UPLOAD, upload); - - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - context.startForegroundService(i); - } else { - context.startService(i); - } - } - } - } - /** * Service initialization */ @@ -1359,13 +1106,207 @@ public class FileUploader extends Service /** * Remove and 'forgets' pending uploads of an account. * - * @param account Account which uploads will be cancelled + * @param account Account which uploads will be cancelled */ private void cancelUploadsForAccount(Account account) { mPendingUploads.remove(account.name); mUploadsStorageManager.removeUploads(account.name); } + + /** + * Upload a new file + */ + public static void uploadNewFile( + Context context, + Account account, + String localPath, + String remotePath, + int behaviour, + String mimeType, + boolean createRemoteFile, + int createdBy, + boolean requiresWifi, + boolean requiresCharging, + NameCollisionPolicy nameCollisionPolicy + ) { + uploadNewFile( + context, + account, + new String[]{localPath}, + new String[]{remotePath}, + new String[]{mimeType}, + behaviour, + createRemoteFile, + createdBy, + requiresWifi, + requiresCharging, + nameCollisionPolicy + ); + } + + /** + * Upload multiple new files + */ + public static void uploadNewFile( + Context context, + Account account, + String[] localPaths, + String[] remotePaths, + String[] mimeTypes, + Integer behaviour, + Boolean createRemoteFolder, + int createdBy, + boolean requiresWifi, + boolean requiresCharging, + NameCollisionPolicy nameCollisionPolicy + ) { + Intent intent = new Intent(context, FileUploader.class); + + intent.putExtra(FileUploader.KEY_ACCOUNT, account); + intent.putExtra(FileUploader.KEY_LOCAL_FILE, localPaths); + intent.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths); + intent.putExtra(FileUploader.KEY_MIME_TYPE, mimeTypes); + intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour); + intent.putExtra(FileUploader.KEY_CREATE_REMOTE_FOLDER, createRemoteFolder); + intent.putExtra(FileUploader.KEY_CREATED_BY, createdBy); + intent.putExtra(FileUploader.KEY_WHILE_ON_WIFI_ONLY, requiresWifi); + intent.putExtra(FileUploader.KEY_WHILE_CHARGING_ONLY, requiresCharging); + intent.putExtra(FileUploader.KEY_NAME_COLLISION_POLICY, nameCollisionPolicy); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + context.startForegroundService(intent); + } else { + context.startService(intent); + } + } + + /** + * Upload and overwrite an already uploaded file + */ + public static void uploadUpdateFile( + Context context, + Account account, + OCFile existingFile, + Integer behaviour, + NameCollisionPolicy nameCollisionPolicy + ) { + uploadUpdateFile(context, account, new OCFile[]{existingFile}, behaviour, nameCollisionPolicy); + } + + /** + * Upload and overwrite already uploaded files + */ + public static void uploadUpdateFile( + Context context, + Account account, + OCFile[] existingFiles, + Integer behaviour, + NameCollisionPolicy nameCollisionPolicy + ) { + Intent intent = new Intent(context, FileUploader.class); + + intent.putExtra(FileUploader.KEY_ACCOUNT, account); + intent.putExtra(FileUploader.KEY_FILE, existingFiles); + intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour); + intent.putExtra(FileUploader.KEY_NAME_COLLISION_POLICY, nameCollisionPolicy); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + context.startForegroundService(intent); + } else { + context.startService(intent); + } + } + + /** + * Retry a failed {@link OCUpload} identified by {@link OCUpload#getRemotePath()} + */ + public static void retryUpload(@NonNull Context context, @NonNull Account account, @NonNull OCUpload upload) { + Intent i = new Intent(context, FileUploader.class); + i.putExtra(FileUploader.KEY_RETRY, true); + i.putExtra(FileUploader.KEY_ACCOUNT, account); + i.putExtra(FileUploader.KEY_RETRY_UPLOAD, upload); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + context.startForegroundService(i); + } else { + context.startService(i); + } + } + + /** + * Retry a subset of all the stored failed uploads. + * + * @param context Caller {@link Context} + * @param account If not null, only failed uploads to this OC account will be retried; otherwise, uploads of + * all accounts will be retried. + * @param uploadResult If not null, only failed uploads with the result specified will be retried; otherwise, failed + * uploads due to any result will be retried. + */ + public static void retryFailedUploads( + @NonNull final Context context, + @Nullable final Account account, + @NonNull final UploadsStorageManager uploadsStorageManager, + @NonNull final ConnectivityService connectivityService, + @NonNull final UserAccountManager accountManager, + @NonNull final PowerManagementService powerManagementService, + @Nullable final UploadResult uploadResult + ) { + OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads(); + Account currentAccount = null; + boolean resultMatch; + boolean accountMatch; + + boolean gotNetwork = connectivityService.getActiveNetworkType() != JobRequest.NetworkType.ANY && + !connectivityService.isInternetWalled(); + boolean gotWifi = gotNetwork && Device.getNetworkType(context).equals(JobRequest.NetworkType.UNMETERED); + boolean charging = Device.getBatteryStatus(context).isCharging(); + boolean isPowerSaving = powerManagementService.isPowerSavingEnabled(); + + for (OCUpload failedUpload : failedUploads) { + accountMatch = account == null || account.name.equals(failedUpload.getAccountName()); + resultMatch = uploadResult == null || uploadResult.equals(failedUpload.getLastResult()); + if (accountMatch && resultMatch) { + if (currentAccount == null || !currentAccount.name.equals(failedUpload.getAccountName())) { + currentAccount = failedUpload.getAccount(accountManager); + } + + if (!new File(failedUpload.getLocalPath()).exists()) { + if (!failedUpload.getLastResult().equals(UploadResult.FILE_NOT_FOUND)) { + failedUpload.setLastResult(UploadResult.FILE_NOT_FOUND); + uploadsStorageManager.updateUpload(failedUpload); + } + } else { + charging = charging || Device.getBatteryStatus(context).getBatteryPercent() == 1; + if (!isPowerSaving && gotNetwork && canUploadBeRetried(failedUpload, gotWifi, charging)) { + retryUpload(context, currentAccount, failedUpload); + } + } + } + } + } + + private static boolean canUploadBeRetried(OCUpload upload, boolean gotWifi, boolean isCharging) { + File file = new File(upload.getLocalPath()); + boolean needsWifi = upload.isUseWifiOnly(); + boolean needsCharging = upload.isWhileChargingOnly(); + + return file.exists() && (!needsWifi || gotWifi) && (!needsCharging || isCharging); + } + + public static String getUploadsAddedMessage() { + return FileUploader.class.getName() + UPLOADS_ADDED_MESSAGE; + } + + public static String getUploadStartMessage() { + return FileUploader.class.getName() + UPLOAD_START_MESSAGE; + } + + public static String getUploadFinishMessage() { + return FileUploader.class.getName() + UPLOAD_FINISH_MESSAGE; + } + + public enum NameCollisionPolicy { CANCEL, RENAME, diff --git a/src/main/java/com/owncloud/android/jobs/ContactsBackupJob.java b/src/main/java/com/owncloud/android/jobs/ContactsBackupJob.java index 1036be620c..67918cfaac 100644 --- a/src/main/java/com/owncloud/android/jobs/ContactsBackupJob.java +++ b/src/main/java/com/owncloud/android/jobs/ContactsBackupJob.java @@ -169,18 +169,18 @@ public class ContactsBackupJob extends Job { } } - FileUploader.UploadRequester requester = new FileUploader.UploadRequester(); - requester.uploadNewFile( - getContext(), - user.toPlatformAccount(), - file.getAbsolutePath(), - backupFolder + filename, - FileUploader.LOCAL_BEHAVIOUR_MOVE, - null, - true, - UploadFileOperation.CREATED_BY_USER, - false, - false + FileUploader.uploadNewFile( + getContext(), + user.toPlatformAccount(), + file.getAbsolutePath(), + backupFolder + filename, + FileUploader.LOCAL_BEHAVIOUR_MOVE, + null, + true, + UploadFileOperation.CREATED_BY_USER, + false, + false, + FileUploader.NameCollisionPolicy.ASK_USER ); } diff --git a/src/main/java/com/owncloud/android/jobs/FilesSyncJob.java b/src/main/java/com/owncloud/android/jobs/FilesSyncJob.java index 527749607f..f507fa2244 100644 --- a/src/main/java/com/owncloud/android/jobs/FilesSyncJob.java +++ b/src/main/java/com/owncloud/android/jobs/FilesSyncJob.java @@ -141,12 +141,11 @@ public class FilesSyncJob extends Job { Locale currentLocale = context.getResources().getConfiguration().locale; SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", currentLocale); sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID())); - FileUploader.UploadRequester requester = new FileUploader.UploadRequester(); for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) { if ((syncedFolder.isEnabled()) && (!skipCustom || MediaFolderType.CUSTOM != syncedFolder.getType())) { syncFolder(context, resources, lightVersion, filesystemDataProvider, currentLocale, sFormatter, - requester, syncedFolder); + syncedFolder); } } @@ -157,10 +156,15 @@ public class FilesSyncJob extends Job { return Result.SUCCESS; } - private void syncFolder(Context context, Resources resources, boolean lightVersion, - FilesystemDataProvider filesystemDataProvider, Locale currentLocale, - SimpleDateFormat sFormatter, FileUploader.UploadRequester requester, - SyncedFolder syncedFolder) { + private void syncFolder( + Context context, + Resources resources, + boolean lightVersion, + FilesystemDataProvider filesystemDataProvider, + Locale currentLocale, + SimpleDateFormat sFormatter, + SyncedFolder syncedFolder + ) { String remotePath; boolean subfolderByDate; Integer uploadAction; @@ -203,7 +207,7 @@ public class FilesSyncJob extends Job { remotePath = syncedFolder.getRemotePath(); } - requester.uploadFileWithNameCollisionPolicy( + FileUploader.uploadNewFile( context, user.toPlatformAccount(), file.getAbsolutePath(), diff --git a/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java b/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java index fc0a71ccfb..d2ed15ccdd 100644 --- a/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -291,9 +291,13 @@ public class SynchronizeFileOperation extends SyncOperation { * @param file OCFile object representing the file to upload */ private void requestForUpload(OCFile file) { - FileUploader.UploadRequester requester = new FileUploader.UploadRequester(); - requester.uploadUpdate(mContext, mAccount, file, FileUploader.LOCAL_BEHAVIOUR_MOVE, - FileUploader.NameCollisionPolicy.ASK_USER); + FileUploader.uploadUpdateFile( + mContext, + mAccount, + file, + FileUploader.LOCAL_BEHAVIOUR_MOVE, + FileUploader.NameCollisionPolicy.ASK_USER + ); mTransferWasRequested = true; } diff --git a/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.java b/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.java index 5b10384230..0be1bb2c4e 100644 --- a/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.java @@ -82,7 +82,6 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict } OCFile file = getFile(); - FileUploader.UploadRequester uploadRequester = new FileUploader.UploadRequester(); // Upload if (decision == Decision.KEEP_LOCAL || decision == Decision.KEEP_BOTH) { @@ -91,7 +90,7 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict collisionPolicy = FileUploader.NameCollisionPolicy.RENAME; } - uploadRequester.uploadUpdate(this, getAccount(), file, localBehaviour, collisionPolicy); + FileUploader.uploadUpdateFile(this, getAccount(), file, localBehaviour, collisionPolicy); if (this.conflictUpload != null) { uploadsStorageManager.removeUpload(this.conflictUpload); diff --git a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index bcc2dbc590..7815fa40e2 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1043,8 +1043,7 @@ public class FileDisplayActivity extends FileActivity break; } - FileUploader.UploadRequester requester = new FileUploader.UploadRequester(); - requester.uploadNewFile( + FileUploader.uploadNewFile( this, getAccount(), filePaths, @@ -1054,7 +1053,8 @@ public class FileDisplayActivity extends FileActivity false, // do not create parent folder if not existent UploadFileOperation.CREATED_BY_USER, false, - false + false, + FileUploader.NameCollisionPolicy.ASK_USER ); } else { diff --git a/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java b/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java index 35536bad10..034790ea2c 100755 --- a/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java @@ -888,19 +888,19 @@ public class ReceiveExternalFilesActivity extends FileActivity } public void uploadFile(String tmpName, String filename) { - FileUploader.UploadRequester requester = new FileUploader.UploadRequester(); - requester.uploadNewFile( + FileUploader.uploadNewFile( getBaseContext(), getAccount(), - tmpName, + tmpName, mFile.getRemotePath() + filename, FileUploader.LOCAL_BEHAVIOUR_COPY, null, true, UploadFileOperation.CREATED_BY_USER, false, - false - ); + false, + FileUploader.NameCollisionPolicy.ASK_USER + ); finish(); } diff --git a/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java b/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java index 7cf5933b44..492b89c9f9 100755 --- a/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java @@ -220,14 +220,15 @@ public class UploadListActivity extends FileActivity { } // retry failed uploads - FileUploader.UploadRequester requester = new FileUploader.UploadRequester(); - new Thread(() -> requester.retryFailedUploads(this, - null, - uploadsStorageManager, - connectivityService, - userAccountManager, - powerManagementService, - null)).start(); + new Thread(() -> FileUploader.retryFailedUploads( + this, + null, + uploadsStorageManager, + connectivityService, + userAccountManager, + powerManagementService, + null + )).start(); // update UI uploadListAdapter.loadUploadItemsFromDb(); diff --git a/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java index a1ef327da1..e42810dc6a 100755 --- a/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java @@ -142,16 +142,15 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter new FileUploader.UploadRequester() - .retryFailedUploads( - parentActivity, - null, - uploadsStorageManager, - connectivityService, - accountManager, - powerManagementService, - null)) - .start(); + new Thread(() -> FileUploader.retryFailedUploads( + parentActivity, + null, + uploadsStorageManager, + connectivityService, + accountManager, + powerManagementService, + null + )).start(); break; default: @@ -394,8 +393,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter { if (connectivityService.getActiveNetworkType() != JobRequest.NetworkType.ANY && !connectivityService.isInternetWalled()) { - uploadRequester.retryFailedUploads(context, - null, - uploadsStorageManager, - connectivityService, - accountManager, - powerManagementService, - null); + FileUploader.retryFailedUploads( + context, + null, + uploadsStorageManager, + connectivityService, + accountManager, + powerManagementService, + null + ); } }).start(); }