X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/f76498047437fd53aa383dcc1fecb438f319da6d..58c569b968a829975b4767b7396d4b55c896fd03:/src/com/owncloud/android/files/services/FileUploader.java diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index eaaea010..3de51b6e 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -54,12 +54,12 @@ import com.owncloud.android.authenticator.AccountAuthenticator; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.db.DbHandler; -import com.owncloud.android.files.InstantUploadBroadcastReceiver; import com.owncloud.android.network.OwnCloudClientUtils; import com.owncloud.android.operations.ChunkedUploadFileOperation; import com.owncloud.android.operations.RemoteOperationResult; import com.owncloud.android.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.operations.UploadFileOperation; +import com.owncloud.android.ui.activity.FailedUploadActivity; import com.owncloud.android.ui.activity.FileDetailActivity; import com.owncloud.android.ui.activity.InstantUploadActivity; import com.owncloud.android.ui.fragment.FileDetailFragment; @@ -422,28 +422,10 @@ public class FileUploader extends Service implements OnDatatransferProgressListe // / create remote folder for instant uploads if (mCurrentUpload.isRemoteFolderToBeCreated()) { - mUploadClient.createDirectory(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR); // ignoring - // result; - // fail - // could - // just - // mean - // that - // it - // already - // exists, - // but - // local - // database - // is - // not - // synchronized; - // the - // upload - // will - // be - // tried - // anyway + mUploadClient.createDirectory(InstantUploadService.INSTANT_UPLOAD_DIR); + // ignoring result fail could just mean that it already exists, + // but local database is not synchronized the upload will be + // tried anyway } // / perform the upload @@ -543,11 +525,11 @@ public class FileUploader extends Service implements OnDatatransferProgressListe } private boolean checkAndFixInstantUploadDirectory(FileDataStorageManager storageManager) { - OCFile instantUploadDir = storageManager.getFileByPath(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR); + OCFile instantUploadDir = storageManager.getFileByPath(InstantUploadService.INSTANT_UPLOAD_DIR); if (instantUploadDir == null) { // first instant upload in the account, or never account not // synchronized after the remote InstantUpload folder was created - OCFile newDir = new OCFile(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR); + OCFile newDir = new OCFile(InstantUploadService.INSTANT_UPLOAD_DIR); newDir.setMimetype("DIR"); OCFile path = storageManager.getFileByPath(OCFile.PATH_SEPARATOR); @@ -715,12 +697,6 @@ public class FileUploader extends Service implements OnDatatransferProgressListe getString(R.string.uploader_upload_failed_ticker), System.currentTimeMillis()); finalNotification.flags |= Notification.FLAG_AUTO_CANCEL; - Intent detailUploudIntent = new Intent(this, InstantUploadActivity.class); - detailUploudIntent.putExtra(FileUploader.KEY_ACCOUNT, upload.getAccount()); - finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), - (int) System.currentTimeMillis(), detailUploudIntent, PendingIntent.FLAG_UPDATE_CURRENT - | PendingIntent.FLAG_ONE_SHOT); - String content = null; if (uploadResult.getCode() == ResultCode.LOCAL_STORAGE_FULL || uploadResult.getCode() == ResultCode.LOCAL_STORAGE_NOT_COPIED) { @@ -728,21 +704,50 @@ public class FileUploader extends Service implements OnDatatransferProgressListe // from a RemoteOperationResult and a RemoteOperation content = String.format(getString(R.string.error__upload__local_file_not_copied), upload.getFileName(), getString(R.string.app_name)); + } else if (uploadResult.getCode() == ResultCode.QUOTA_EXCEEDED) { + content = getString(R.string.failed_upload_quota_exceeded_text); } else { content = String .format(getString(R.string.uploader_upload_failed_content_single), upload.getFileName()); } - finalNotification.setLatestEventInfo(getApplicationContext(), - getString(R.string.uploader_upload_failed_ticker), content, finalNotification.contentIntent); - mNotificationManager.notify(R.string.uploader_upload_failed_ticker, finalNotification); + // we add only for instant-uploads the InstantUploadActivity and the + // db entry + Intent detailUploadIntent = null; + if (upload.isInstant()) { + detailUploadIntent = new Intent(this, InstantUploadActivity.class); + detailUploadIntent.putExtra(FileUploader.KEY_ACCOUNT, upload.getAccount()); + } else { + detailUploadIntent = new Intent(this, FailedUploadActivity.class); + detailUploadIntent.putExtra(FailedUploadActivity.MESSAGE, content); + } + finalNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), + (int) System.currentTimeMillis(), detailUploadIntent, PendingIntent.FLAG_UPDATE_CURRENT + | PendingIntent.FLAG_ONE_SHOT); - DbHandler db = new DbHandler(this.getBaseContext()); - if (db.updateFileState(upload.getOriginalStoragePath(), DbHandler.UPLOAD_STATUS_UPLOAD_FAILED) == 0) { - db.putFileForLater(upload.getOriginalStoragePath(), upload.getAccount().name); + if (upload.isInstant()) { + DbHandler db = null; + try { + db = new DbHandler(this.getBaseContext()); + String message = uploadResult.getLogMessage() + " errorCode: " + uploadResult.getCode(); + Log.e(TAG, message + " Http-Code: " + uploadResult.getHttpCode()); + if (uploadResult.getCode() == ResultCode.QUOTA_EXCEEDED) { + message = getString(R.string.failed_upload_quota_exceeded_text); + } + if (db.updateFileState(upload.getOriginalStoragePath(), DbHandler.UPLOAD_STATUS_UPLOAD_FAILED, + message) == 0) { + db.putFileForLater(upload.getOriginalStoragePath(), upload.getAccount().name, message); + } + } finally { + if (db != null) { + db.close(); + } + } } - db.close(); + finalNotification.setLatestEventInfo(getApplicationContext(), + getString(R.string.uploader_upload_failed_ticker), content, finalNotification.contentIntent); + mNotificationManager.notify(R.string.uploader_upload_failed_ticker, finalNotification); } }