X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/684ae90ca7f9eab8cbd14bc28bab5af265d0a9ac..2b00ff1c7eb24dffcd70ced6c33db8ecf90e3f57:/src/eu/alefzero/owncloud/files/services/FileUploader.java diff --git a/src/eu/alefzero/owncloud/files/services/FileUploader.java b/src/eu/alefzero/owncloud/files/services/FileUploader.java index 30d91e1c..ee63d8bd 100644 --- a/src/eu/alefzero/owncloud/files/services/FileUploader.java +++ b/src/eu/alefzero/owncloud/files/services/FileUploader.java @@ -1,10 +1,14 @@ package eu.alefzero.owncloud.files.services; import java.io.File; +import java.net.URLDecoder; import eu.alefzero.owncloud.AccountUtils; import eu.alefzero.owncloud.R; import eu.alefzero.owncloud.authenticator.AccountAuthenticator; +import eu.alefzero.owncloud.datamodel.FileDataStorageManager; +import eu.alefzero.owncloud.datamodel.OCFile; +import eu.alefzero.owncloud.files.interfaces.OnDatatransferProgressListener; import eu.alefzero.owncloud.utils.OwnCloudVersion; import eu.alefzero.webdav.OnUploadProgressListener; import eu.alefzero.webdav.WebdavClient; @@ -26,7 +30,7 @@ import android.webkit.MimeTypeMap; import android.widget.RemoteViews; import android.widget.Toast; -public class FileUploader extends Service implements OnUploadProgressListener { +public class FileUploader extends Service implements OnDatatransferProgressListener { public static final String KEY_LOCAL_FILE = "LOCAL_FILE"; public static final String KEY_REMOTE_FILE = "REMOTE_FILE"; @@ -133,6 +137,7 @@ public class FileUploader extends Service implements OnUploadProgressListener { String username = mAccount.name.substring(0, mAccount.name.lastIndexOf('@')); String password = mAccountManager.getPassword(mAccount); + FileDataStorageManager storageManager = new FileDataStorageManager(mAccount, getContentResolver()); mTotalDataToSend = mSendData = mPreviousPercent = 0; @@ -147,8 +152,8 @@ public class FileUploader extends Service implements OnUploadProgressListener { mNotificationManager.notify(42, mNotification); WebdavClient wc = new WebdavClient(ocUri); - wc.allowUnsignedCertificates(); - wc.setUploadListener(this); + wc.allowSelfsignedCertificates(); + wc.setDataTransferProgressListener(this); wc.setCredentials(username, password); for (int i = 0; i < mLocalPaths.length; ++i) { @@ -167,6 +172,15 @@ public class FileUploader extends Service implements OnUploadProgressListener { mCurrentIndexUpload = i; if (wc.putFile(mLocalPaths[i], mRemotePaths[i], mimeType)) { mResult |= true; + OCFile new_file = new OCFile(mRemotePaths[i]); + new_file.setMimetype(mimeType); + new_file.setFileLength(new File(mLocalPaths[i]).length()); + new_file.setModificationTimestamp(System.currentTimeMillis()); + new_file.setLastSyncDate(0); + new_file.setStoragePath(mLocalPaths[i]); + File f = new File(URLDecoder.decode(mRemotePaths[i])); + new_file.setParentId(storageManager.getFileByPath(f.getParent().endsWith("/")?f.getParent():f.getParent()+"/").getFileId()); + storageManager.saveFile(new_file); } } // notification.contentView.setProgressBar(R.id.status_progress, @@ -176,9 +190,9 @@ public class FileUploader extends Service implements OnUploadProgressListener { } @Override - public void OnUploadProgress(long currentProgress) { - mSendData += currentProgress; - int percent = (int)(100*mSendData/mTotalDataToSend); + public void transferProgress(long progressRate) { + mSendData += progressRate; + int percent = (int)(100*((double)mSendData)/((double)mTotalDataToSend)); if (percent != mPreviousPercent) { String text = String.format("%d%% Uploading %s file", percent, new File(mLocalPaths[mCurrentIndexUpload]).getName()); mNotification.contentView.setProgressBar(R.id.status_progress, 100, percent, false);