mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 13:45:35 +03:00
Customized error message for uploads when the local file cannot by copied to the ownCloud local directory
This commit is contained in:
parent
b59784af89
commit
a7535406d4
4 changed files with 26 additions and 5 deletions
|
@ -241,4 +241,7 @@
|
|||
<string name="conflict_overwrite">Overwrite</string>
|
||||
<string name="conflict_dont_upload">Don\'t upload</string>
|
||||
|
||||
<!-- we need to improve the communication of errors to the user -->
|
||||
<string name="error__upload__local_file_not_copied">%1$s could not be copied to %2$s local directory</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.owncloud.android.files.InstantUploadBroadcastReceiver;
|
|||
import com.owncloud.android.operations.ChunkedUploadFileOperation;
|
||||
import com.owncloud.android.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.operations.UploadFileOperation;
|
||||
import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
|
||||
import com.owncloud.android.ui.activity.FileDetailActivity;
|
||||
import com.owncloud.android.ui.fragment.FileDetailFragment;
|
||||
import com.owncloud.android.utils.OwnCloudVersion;
|
||||
|
@ -645,9 +646,18 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
|
|||
finalNotification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||
// TODO put something smart in the contentIntent below
|
||||
finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);
|
||||
|
||||
String content = null;
|
||||
if (uploadResult.getCode() == ResultCode.LOCAL_STORAGE_FULL ||
|
||||
uploadResult.getCode() == ResultCode.LOCAL_STORAGE_NOT_COPIED) {
|
||||
// TODO we need a class to provide error messages for the users from a RemoteOperationResult and a RemoteOperation
|
||||
content = String.format(getString(R.string.error__upload__local_file_not_copied), (new File(upload.getStoragePath())).getName(), getString(R.string.app_name));
|
||||
} else {
|
||||
content = String.format(getString(R.string.uploader_upload_failed_content_single), (new File(upload.getStoragePath())).getName());
|
||||
}
|
||||
finalNotification.setLatestEventInfo( getApplicationContext(),
|
||||
getString(R.string.uploader_upload_failed_ticker),
|
||||
String.format(getString(R.string.uploader_upload_failed_content_single), (new File(upload.getStoragePath())).getName()),
|
||||
content,
|
||||
finalNotification.contentIntent);
|
||||
|
||||
mNotificationManager.notify(R.string.uploader_upload_failed_ticker, finalNotification);
|
||||
|
|
|
@ -71,7 +71,8 @@ public class RemoteOperationResult implements Serializable {
|
|||
CONFLICT,
|
||||
SYNC_CONFLICT,
|
||||
LOCAL_STORAGE_FULL,
|
||||
LOCAL_STORAGE_NOT_MOVED
|
||||
LOCAL_STORAGE_NOT_MOVED,
|
||||
LOCAL_STORAGE_NOT_COPIED
|
||||
}
|
||||
|
||||
private boolean mSuccess = false;
|
||||
|
|
|
@ -143,7 +143,6 @@ public class UploadFileOperation extends RemoteOperation {
|
|||
mDataTransferListeners.add(listener);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected RemoteOperationResult run(WebdavClient client) {
|
||||
RemoteOperationResult result = null;
|
||||
|
@ -187,6 +186,11 @@ public class UploadFileOperation extends RemoteOperation {
|
|||
while ((len = in.read(buf)) > 0){
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_COPIED);
|
||||
return result;
|
||||
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) in.close();
|
||||
|
@ -230,8 +234,11 @@ public class UploadFileOperation extends RemoteOperation {
|
|||
}
|
||||
expectedFile = new File(mFile.getStoragePath());
|
||||
if (!expectedFile.equals(fileToMove) && !fileToMove.renameTo(expectedFile)) {
|
||||
result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_MOVED);
|
||||
return result;
|
||||
mFile.setStoragePath(null); // forget the local file
|
||||
// by now, treat this as a success; the file was uploaded; the user won't like that the local file is not linked, but this should be a veeery rare fail;
|
||||
// the best option could be show a warning message (but not a fail)
|
||||
//result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_MOVED);
|
||||
//return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue