X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/ceb3dfdd059dd4f2aca8a784476fb60e610b78f6..48f13c8adc5c4b9bc4ca96bf13939a7d7cfae562:/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 298c93b2..e66181be 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -10,7 +10,8 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.PhotoTakenBroadcastReceiver; import eu.alefzero.webdav.OnDatatransferProgressListener; -import com.owncloud.android.utils.OwnCloudClientUtils; + +import com.owncloud.android.network.OwnCloudClientUtils; import android.accounts.Account; import android.app.Notification; @@ -42,6 +43,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe public static final String KEY_REMOTE_FILE = "REMOTE_FILE"; public static final String KEY_ACCOUNT = "ACCOUNT"; public static final String KEY_UPLOAD_TYPE = "UPLOAD_TYPE"; + public static final String KEY_FORCE_OVERWRITE = "KEY_FORCE_OVERWRITE"; public static final String ACCOUNT_NAME = "ACCOUNT_NAME"; public static final String KEY_MIME_TYPE = "MIME_TYPE"; public static final String KEY_INSTANT_UPLOAD = "INSTANT_UPLOAD"; @@ -97,7 +99,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe @Override public void handleMessage(Message msg) { - uploadFile(); + uploadFile(msg.arg2==1?true:false); stopSelf(msg.arg1); } } @@ -146,6 +148,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; + msg.arg2 = intent.getBooleanExtra(KEY_FORCE_OVERWRITE, false)?1:0; mServiceHandler.sendMessage(msg); return Service.START_NOT_STICKY; @@ -155,7 +158,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe /** * Core upload method: sends the file(s) to upload */ - public void uploadFile() { + public void uploadFile(boolean force_override) { FileDataStorageManager storageManager = new FileDataStorageManager(mAccount, getContentResolver()); mTotalDataToSend = mSendData = mPreviousPercent = 0; @@ -213,9 +216,12 @@ public class FileUploader extends Service implements OnDatatransferProgressListe mCurrentIndexUpload = i; long parentDirId = -1; boolean uploadResult = false; - String availablePath = getAvailableRemotePath(wc, mRemotePaths[i]); + String availablePath = mRemotePaths[i]; + if (!force_override) + availablePath = getAvailableRemotePath(wc, mRemotePaths[i]); try { File f = new File(mRemotePaths[i]); + long size = localFiles[i].length(); parentDirId = storageManager.getFileByPath(f.getParent().endsWith("/")?f.getParent():f.getParent()+"/").getFileId(); if(availablePath != null) { mRemotePaths[i] = availablePath; @@ -223,11 +229,13 @@ public class FileUploader extends Service implements OnDatatransferProgressListe if (wc.putFile(mLocalPaths[i], mRemotePaths[i], mimeType)) { OCFile new_file = new OCFile(mRemotePaths[i]); new_file.setMimetype(mimeType); - new_file.setFileLength(localFiles[i].length()); + new_file.setFileLength(size); new_file.setModificationTimestamp(System.currentTimeMillis()); new_file.setLastSyncDate(0); new_file.setStoragePath(mLocalPaths[i]); new_file.setParentId(parentDirId); + if (force_override) + new_file.setKeepInSync(true); storageManager.saveFile(new_file); mSuccessCounter++; uploadResult = true;