mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
Review behaviour of failed uploads: list in uploads view
This commit is contained in:
parent
f11646bc6e
commit
66ec45f633
5 changed files with 100 additions and 53 deletions
|
@ -3,6 +3,7 @@
|
||||||
*
|
*
|
||||||
* @author LukeOwncloud
|
* @author LukeOwncloud
|
||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
|
* @author masensio
|
||||||
* Copyright (C) 2015 ownCloud Inc.
|
* Copyright (C) 2015 ownCloud Inc.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
@ -152,6 +153,7 @@ public class UploadsStorageManager extends Observable {
|
||||||
ContentValues cv = new ContentValues();
|
ContentValues cv = new ContentValues();
|
||||||
cv.put(ProviderTableMeta.UPLOADS_PATH, ocUpload.getLocalPath());
|
cv.put(ProviderTableMeta.UPLOADS_PATH, ocUpload.getLocalPath());
|
||||||
cv.put(ProviderTableMeta.UPLOADS_STATUS, ocUpload.getUploadStatus().value);
|
cv.put(ProviderTableMeta.UPLOADS_STATUS, ocUpload.getUploadStatus().value);
|
||||||
|
cv.put(ProviderTableMeta.UPLOADS_LAST_RESULT, ocUpload.getLastResult().getValue());
|
||||||
|
|
||||||
int result = getDB().update(ProviderTableMeta.CONTENT_URI_UPLOADS,
|
int result = getDB().update(ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||||
cv,
|
cv,
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class OCUpload {
|
||||||
mUploadTimestamp = -1;
|
mUploadTimestamp = -1;
|
||||||
mAccountName = "";
|
mAccountName = "";
|
||||||
mUploadStatus = UploadStatus.UPLOAD_LATER;
|
mUploadStatus = UploadStatus.UPLOAD_LATER;
|
||||||
mLastResult = UploadResult.UPLOADED;
|
mLastResult = UploadResult.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters & Setters
|
// Getters & Setters
|
||||||
|
@ -140,7 +140,7 @@ public class OCUpload {
|
||||||
*/
|
*/
|
||||||
public void setUploadStatus(UploadStatus uploadStatus) {
|
public void setUploadStatus(UploadStatus uploadStatus) {
|
||||||
this.mUploadStatus = uploadStatus;
|
this.mUploadStatus = uploadStatus;
|
||||||
setLastResult(null);
|
setLastResult(UploadResult.UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,8 +1,27 @@
|
||||||
|
/**
|
||||||
|
* ownCloud Android client application
|
||||||
|
*
|
||||||
|
* @author masensio
|
||||||
|
* Copyright (C) 2015 ownCloud Inc.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.db;
|
package com.owncloud.android.db;
|
||||||
|
|
||||||
/**
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
* Created by masensio on 14/12/2015.
|
|
||||||
*/
|
|
||||||
public enum UploadResult {
|
public enum UploadResult {
|
||||||
UPLOADED(0),
|
UPLOADED(0),
|
||||||
NETWORK_CONNECTION(1),
|
NETWORK_CONNECTION(1),
|
||||||
|
@ -11,7 +30,8 @@ public enum UploadResult {
|
||||||
CONFLICT_ERROR(4),
|
CONFLICT_ERROR(4),
|
||||||
FILE_ERROR(5),
|
FILE_ERROR(5),
|
||||||
PRIVILEDGES_ERROR(6),
|
PRIVILEDGES_ERROR(6),
|
||||||
CANCELLED(7);
|
CANCELLED(7),
|
||||||
|
UNKNOWN(8);
|
||||||
|
|
||||||
private final int value;
|
private final int value;
|
||||||
|
|
||||||
|
@ -22,10 +42,8 @@ public enum UploadResult {
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
public static UploadResult fromValue(int value)
|
public static UploadResult fromValue(int value) {
|
||||||
{
|
switch (value) {
|
||||||
switch (value)
|
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
return UPLOADED;
|
return UPLOADED;
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -42,6 +60,35 @@ public enum UploadResult {
|
||||||
return PRIVILEDGES_ERROR;
|
return PRIVILEDGES_ERROR;
|
||||||
case 7:
|
case 7:
|
||||||
return CANCELLED;
|
return CANCELLED;
|
||||||
|
case 8:
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UploadResult fromOperationResult(RemoteOperationResult result){
|
||||||
|
switch (result.getCode()){
|
||||||
|
case UNKNOWN_ERROR:
|
||||||
|
return UNKNOWN;
|
||||||
|
case OK:
|
||||||
|
return UPLOADED;
|
||||||
|
case NO_NETWORK_CONNECTION:
|
||||||
|
case HOST_NOT_AVAILABLE:
|
||||||
|
case TIMEOUT:
|
||||||
|
case WRONG_CONNECTION:
|
||||||
|
return NETWORK_CONNECTION;
|
||||||
|
case ACCOUNT_EXCEPTION:
|
||||||
|
return CREDENTIAL_ERROR;
|
||||||
|
// case
|
||||||
|
// return FOLDER_ERROR;
|
||||||
|
case CONFLICT:
|
||||||
|
return CONFLICT_ERROR;
|
||||||
|
case FILE_NOT_FOUND:
|
||||||
|
return FILE_ERROR;
|
||||||
|
case UNAUTHORIZED:
|
||||||
|
return PRIVILEDGES_ERROR;
|
||||||
|
case CANCELLED:
|
||||||
|
return CANCELLED;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1307,6 +1307,8 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateDatabaseUploadResult(uploadResult, mCurrentUpload);
|
||||||
|
|
||||||
if(!uploadResult.isSuccess()){
|
if(!uploadResult.isSuccess()){
|
||||||
//in case of failure, do not show details file view (because there is no file!)
|
//in case of failure, do not show details file view (because there is no file!)
|
||||||
Intent showUploadListIntent = new Intent(this, UploadListActivity.class);
|
Intent showUploadListIntent = new Intent(this, UploadListActivity.class);
|
||||||
|
@ -1326,7 +1328,7 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
||||||
// db.removeIUPendingFile(mCurrentUpload.getOriginalStoragePath());
|
// db.removeIUPendingFile(mCurrentUpload.getOriginalStoragePath());
|
||||||
// db.close();
|
// db.close();
|
||||||
mPendingUploads.remove(upload.getAccount(), upload.getFile().getRemotePath());
|
mPendingUploads.remove(upload.getAccount(), upload.getFile().getRemotePath());
|
||||||
updateDatabaseUploadResult(uploadResult, mCurrentUpload);
|
//updateDatabaseUploadResult(uploadResult, mCurrentUpload);
|
||||||
// remove success notification, with a delay of 2 seconds
|
// remove success notification, with a delay of 2 seconds
|
||||||
NotificationDelayer.cancelWithDelay(mNotificationManager, R.string.uploader_upload_succeeded_ticker,
|
NotificationDelayer.cancelWithDelay(mNotificationManager, R.string.uploader_upload_succeeded_ticker,
|
||||||
2000);
|
2000);
|
||||||
|
@ -1356,39 +1358,40 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// TODO: Disable for testing of menu actions in uploads view
|
// TODO: Disable for testing of menu actions in uploads view
|
||||||
// if (shouldRetryFailedUpload(uploadResult)) {
|
if (shouldRetryFailedUpload(uploadResult)) {
|
||||||
// mUploadsStorageManager.updateUploadStatus(
|
mUploadsStorageManager.updateUploadStatus(
|
||||||
// upload.getOriginalStoragePath(), UploadStatus.UPLOAD_FAILED_RETRY, uploadResult
|
upload.getOriginalStoragePath(), UploadStatus.UPLOAD_FAILED_RETRY,
|
||||||
// );
|
UploadResult.fromOperationResult(uploadResult));
|
||||||
// } else {
|
} else {
|
||||||
// mUploadsStorageManager.updateUploadStatus(upload.getOriginalStoragePath(),
|
mUploadsStorageManager.updateUploadStatus(upload.getOriginalStoragePath(),
|
||||||
// UploadsStorageManager.UploadStatus.UPLOAD_FAILED_GIVE_UP, uploadResult);
|
UploadsStorageManager.UploadStatus.UPLOAD_FAILED_GIVE_UP,
|
||||||
// }
|
UploadResult.fromOperationResult(uploadResult));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Disable for testing of menu actions in uploads view
|
// TODO: Disable for testing of menu actions in uploads view
|
||||||
//
|
|
||||||
// /**
|
/**
|
||||||
// * Determines whether with given uploadResult the upload should be retried later.
|
* Determines whether with given uploadResult the upload should be retried later.
|
||||||
// * @param uploadResult
|
* @param uploadResult
|
||||||
// * @return true if upload should be retried later, false if is should be abandoned.
|
* @return true if upload should be retried later, false if is should be abandoned.
|
||||||
// */
|
*/
|
||||||
// private boolean shouldRetryFailedUpload(RemoteOperationResult uploadResult) {
|
private boolean shouldRetryFailedUpload(RemoteOperationResult uploadResult) {
|
||||||
// if (uploadResult.isSuccess()) {
|
if (uploadResult.isSuccess()) {
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
// switch (uploadResult.getCode()) {
|
switch (uploadResult.getCode()) {
|
||||||
// case HOST_NOT_AVAILABLE:
|
case HOST_NOT_AVAILABLE:
|
||||||
// case NO_NETWORK_CONNECTION:
|
case NO_NETWORK_CONNECTION:
|
||||||
// case TIMEOUT:
|
case TIMEOUT:
|
||||||
// case WRONG_CONNECTION: // SocketException
|
case WRONG_CONNECTION: // SocketException
|
||||||
// return true;
|
return true;
|
||||||
// default:
|
default:
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the persistent upload database that upload is in progress.
|
* Updates the persistent upload database that upload is in progress.
|
||||||
|
@ -1396,7 +1399,8 @@ public class FileUploadService extends Service implements OnDatatransferProgress
|
||||||
private void updateDatabaseUploadStart(UploadFileOperation upload) {
|
private void updateDatabaseUploadStart(UploadFileOperation upload) {
|
||||||
mUploadsStorageManager.updateUploadStatus(
|
mUploadsStorageManager.updateUploadStatus(
|
||||||
upload.getOriginalStoragePath(),
|
upload.getOriginalStoragePath(),
|
||||||
UploadStatus.UPLOAD_IN_PROGRESS, null
|
UploadStatus.UPLOAD_IN_PROGRESS,
|
||||||
|
UploadResult.UNKNOWN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* ownCloud Android client application
|
* ownCloud Android client application
|
||||||
*
|
*
|
||||||
* @author LukeOwncloud
|
* @author LukeOwncloud
|
||||||
|
* @author masensio
|
||||||
* Copyright (C) 2015 ownCloud Inc.
|
* Copyright (C) 2015 ownCloud Inc.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
@ -40,12 +41,12 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||||
import com.owncloud.android.datamodel.UploadsStorageManager;
|
import com.owncloud.android.datamodel.UploadsStorageManager;
|
||||||
import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus;
|
import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus;
|
||||||
import com.owncloud.android.db.OCUpload;
|
import com.owncloud.android.db.OCUpload;
|
||||||
|
import com.owncloud.android.db.UploadResult;
|
||||||
import com.owncloud.android.files.services.FileUploadService;
|
import com.owncloud.android.files.services.FileUploadService;
|
||||||
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import com.owncloud.android.operations.UploadFileOperation;
|
import com.owncloud.android.operations.UploadFileOperation;
|
||||||
import com.owncloud.android.ui.activity.FileActivity;
|
import com.owncloud.android.ui.activity.FileActivity;
|
||||||
import com.owncloud.android.utils.BitmapUtils;
|
|
||||||
import com.owncloud.android.utils.DisplayUtils;
|
import com.owncloud.android.utils.DisplayUtils;
|
||||||
import com.owncloud.android.utils.MimetypeIconUtil;
|
import com.owncloud.android.utils.MimetypeIconUtil;
|
||||||
|
|
||||||
|
@ -198,13 +199,6 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
|
||||||
if(mParentActivity.getFileUploaderBinder() != null) {
|
if(mParentActivity.getFileUploaderBinder() != null) {
|
||||||
mParentActivity.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener,
|
mParentActivity.getFileUploaderBinder().addDatatransferProgressListener(mProgressListener,
|
||||||
mParentActivity.getAccount(), uploadOCFile);
|
mParentActivity.getAccount(), uploadOCFile);
|
||||||
// mCurrentUpload = mParentActivity.getFileUploaderBinder().getCurrentUploadOperation();
|
|
||||||
// if(mCurrentUpload != null) {
|
|
||||||
// mCurrentUpload.addDatatransferProgressListener(mProgressListener);
|
|
||||||
// Log_OC.d(TAG, "added progress listener for current upload: " + mCurrentUpload);
|
|
||||||
// } else {
|
|
||||||
// Log_OC.w(TAG, "getFileUploaderBinder().getCurrentUploadOperation() return null. That is odd.");
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
Log_OC.e(TAG, "UploadBinder == null. It should have been created on creating mParentActivity"
|
Log_OC.e(TAG, "UploadBinder == null. It should have been created on creating mParentActivity"
|
||||||
+ " which inherits from FileActivity. Fix that!");
|
+ " which inherits from FileActivity. Fix that!");
|
||||||
|
@ -219,12 +213,12 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UPLOAD_FAILED_RETRY:
|
case UPLOAD_FAILED_RETRY:
|
||||||
if(upload.getLastResult() != null){
|
// if(upload.getLastResult() != UploadResult.UNKNOWN){
|
||||||
status = "Last failure: "
|
// status = "Last failure: "
|
||||||
+ upload.getLastResult().toString();
|
// + upload.getLastResult().toString();
|
||||||
} else {
|
// } else {
|
||||||
status = "Upload will be retried shortly.";
|
status = "Upload will be retried shortly.";
|
||||||
}
|
// }
|
||||||
String laterReason = FileUploadService.getUploadLaterReason(mParentActivity, upload);
|
String laterReason = FileUploadService.getUploadLaterReason(mParentActivity, upload);
|
||||||
if(laterReason != null) {
|
if(laterReason != null) {
|
||||||
//Upload failed once but is delayed now, show reason.
|
//Upload failed once but is delayed now, show reason.
|
||||||
|
|
Loading…
Reference in a new issue