X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/b00957b5fa28651b588292b9696648af6dc52636..b246cf7075c829a7662047e89a927c0b6cc18ac5:/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 10916917..2abf92ed 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -11,13 +11,12 @@ import java.util.Vector; import com.owncloud.android.authenticator.AccountAuthenticator; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.files.PhotoTakenBroadcastReceiver; +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.utils.OwnCloudVersion; -import eu.alefzero.webdav.ChunkFromFileChannelRequestEntity; import eu.alefzero.webdav.OnDatatransferProgressListener; import com.owncloud.android.network.OwnCloudClientUtils; @@ -38,7 +37,6 @@ import android.os.Process; import android.util.Log; import android.widget.RemoteViews; -import com.owncloud.android.AccountUtils; import com.owncloud.android.R; import eu.alefzero.webdav.WebdavClient; @@ -64,17 +62,20 @@ public class FileUploader extends Service implements OnDatatransferProgressListe private static final String TAG = FileUploader.class.getSimpleName(); - private NotificationManager mNotificationManager; private Looper mServiceLooper; private ServiceHandler mServiceHandler; + private AbstractList mAccounts = new Vector(); - private AbstractList mUploads = new Vector(); + private AbstractList mUploads = new Vector(); + private int mCurrentIndexUpload; + + private NotificationManager mNotificationManager; private Notification mNotification; + private RemoteViews mDefaultNotificationContentView; private long mTotalDataToSend, mSendData; - private int mTotalFilesToSend; - private int mCurrentIndexUpload, mPreviousPercent; + private int mTotalFilesToSend, mPreviousPercent; private int mSuccessCounter; - private RemoteViews mDefaultNotificationContentView; + /** * Static map with the files being download and the path to the temporal file were are download @@ -109,23 +110,9 @@ public class FileUploader extends Service implements OnDatatransferProgressListe - @Override - public IBinder onBind(Intent arg0) { - return null; - } - - private final class ServiceHandler extends Handler { - public ServiceHandler(Looper looper) { - super(looper); - } - - @Override - public void handleMessage(Message msg) { - uploadFile(); - stopSelf(msg.arg1); - } - } - + /** + * Service initialization + */ @Override public void onCreate() { super.onCreate(); @@ -137,6 +124,13 @@ public class FileUploader extends Service implements OnDatatransferProgressListe mServiceHandler = new ServiceHandler(mServiceLooper); } + + /** + * Entry point to add one or several files to the queue of uploads. + * + * New uploads are added calling to startService(), resulting in a call to this method. This ensures the service will keep on working + * although the caller activity goes away. + */ @Override public int onStartCommand(Intent intent, int flags, int startId) { if (!intent.hasExtra(KEY_ACCOUNT) && !intent.hasExtra(KEY_UPLOAD_TYPE)) { @@ -194,6 +188,37 @@ public class FileUploader extends Service implements OnDatatransferProgressListe /** + * Provides a binder object that clients can use to perform operations on the queue of uploads, excepting the addition of new files. + * + * Implemented to perform cancellation, pause and resume of existing uploads. + */ + @Override + public IBinder onBind(Intent arg0) { + return null; + } + + + /** + * Upload worker. Performs the pending uploads in the order they were requested. + * + * Created with the Looper of a new thread, started in {@link FileUploader#onCreate()}. + */ + private final class ServiceHandler extends Handler { + public ServiceHandler(Looper looper) { + super(looper); + } + + @Override + public void handleMessage(Message msg) { + uploadFile(); + stopSelf(msg.arg1); + } + } + + + + + /** * Core upload method: sends the file(s) to upload */ public void uploadFile() { @@ -268,10 +293,10 @@ public class FileUploader extends Service implements OnDatatransferProgressListe */ private boolean createRemoteFolderForInstantUploads(WebdavClient client, FileDataStorageManager storageManager) { boolean result = true; - OCFile instantUploadDir = storageManager.getFileByPath(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR); + OCFile instantUploadDir = storageManager.getFileByPath(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR); if (instantUploadDir == null) { - result = client.createDirectory(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR); // fail could just mean that it already exists, but local database is not synchronized; the upload will be started anyway - OCFile newDir = new OCFile(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR); + result = client.createDirectory(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR); // fail could just mean that it already exists, but local database is not synchronized; the upload will be started anyway + OCFile newDir = new OCFile(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR); newDir.setMimetype("DIR"); newDir.setParentId(storageManager.getFileByPath(OCFile.PATH_SEPARATOR).getFileId()); storageManager.saveFile(newDir); @@ -383,7 +408,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe * Callback method to update the progress bar in the status notification. */ @Override - public void transferProgress(long progressRate) { + public void onTransferProgress(long progressRate) { mSendData += progressRate; int percent = (int)(100*((double)mSendData)/((double)mTotalDataToSend)); if (percent != mPreviousPercent) { @@ -394,4 +419,11 @@ public class FileUploader extends Service implements OnDatatransferProgressListe } mPreviousPercent = percent; } + + @Override + public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String fileName) { + // TODO Maybe replace the other transferProgress with this + } + + }