mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Abort upload [WIP]
This commit is contained in:
		
							parent
							
								
									f110992489
								
							
						
					
					
						commit
						e261b1df2f
					
				| @ -1 +1 @@ | ||||
| Subproject commit aec2f98c69e4e86d148226c7ff00fe5dd2be49e4 | ||||
| Subproject commit fab24c4727d4a201cbb0bb1e7f2f45bc5b5e0756 | ||||
| @ -30,6 +30,7 @@ import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| import okhttp3.Call; | ||||
| import okhttp3.Headers; | ||||
| import okhttp3.HttpUrl; | ||||
| import okhttp3.OkHttpClient; | ||||
| @ -50,6 +51,7 @@ public abstract class HttpBaseMethod { | ||||
|     protected Request mRequest; | ||||
|     protected RequestBody mRequestBody; | ||||
|     protected Response mResponse; | ||||
|     protected Call mCall; | ||||
| 
 | ||||
|     protected HttpBaseMethod (HttpUrl httpUrl) { | ||||
|         mOkHttpClient = HttpClient.getOkHttpClient(); | ||||
| @ -125,4 +127,12 @@ public abstract class HttpBaseMethod { | ||||
|     public String getResponseHeader(String headerName) { | ||||
|         return mResponse.header(headerName); | ||||
|     } | ||||
| 
 | ||||
|     public void abort() { | ||||
|         mCall.cancel(); | ||||
|     } | ||||
| 
 | ||||
|     public boolean isAborted() { | ||||
|         return mCall.isCanceled(); | ||||
|     } | ||||
| } | ||||
| @ -46,5 +46,4 @@ public class GetMethod extends HttpMethod { | ||||
| 
 | ||||
|         return super.execute(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -38,8 +38,6 @@ import okhttp3.HttpUrl; | ||||
|  */ | ||||
| public abstract class HttpMethod extends HttpBaseMethod { | ||||
| 
 | ||||
|     private Call mCall; | ||||
| 
 | ||||
|     public HttpMethod(HttpUrl httpUrl) { | ||||
|         super(httpUrl); | ||||
|     } | ||||
| @ -50,8 +48,4 @@ public abstract class HttpMethod extends HttpBaseMethod { | ||||
|         mResponse = mCall.execute(); | ||||
|         return super.getStatusCode(); | ||||
|     } | ||||
| 
 | ||||
|     public void abort() { | ||||
|         mCall.cancel(); | ||||
|     } | ||||
| } | ||||
| @ -49,4 +49,14 @@ public abstract class DavMethod extends HttpBaseMethod { | ||||
|     public DavResource getDavResource() { | ||||
|         return mDavResource; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void abort() { | ||||
|         mDavResource.cancelCall(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean isAborted() { | ||||
|         return mDavResource.isCallAborted(); | ||||
|     } | ||||
| } | ||||
| @ -24,16 +24,6 @@ | ||||
| 
 | ||||
| package com.owncloud.android.lib.resources.files; | ||||
| 
 | ||||
| import java.io.BufferedInputStream; | ||||
| import java.io.File; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.util.Date; | ||||
| import java.util.HashSet; | ||||
| import java.util.Iterator; | ||||
| import java.util.Set; | ||||
| import java.util.concurrent.atomic.AtomicBoolean; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.OwnCloudClient; | ||||
| import com.owncloud.android.lib.common.http.HttpConstants; | ||||
| import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod; | ||||
| @ -44,6 +34,16 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| 
 | ||||
| import java.io.BufferedInputStream; | ||||
| import java.io.File; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.util.Date; | ||||
| import java.util.HashSet; | ||||
| import java.util.Iterator; | ||||
| import java.util.Set; | ||||
| import java.util.concurrent.atomic.AtomicBoolean; | ||||
| 
 | ||||
| import okhttp3.HttpUrl; | ||||
| 
 | ||||
| /** | ||||
| @ -98,7 +98,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | ||||
| 
 | ||||
| 
 | ||||
|     private RemoteOperationResult downloadFile(OwnCloudClient client, File targetFile) throws | ||||
|         IOException, OperationCancelledException { | ||||
|             Exception { | ||||
| 
 | ||||
|         RemoteOperationResult result; | ||||
|         int status; | ||||
| @ -174,9 +174,6 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | ||||
|             result = isSuccess(status) | ||||
|                     ? new RemoteOperationResult(RemoteOperationResult.ResultCode.OK) | ||||
|                     : new RemoteOperationResult(mGet); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             return new RemoteOperationResult(e); | ||||
|         } finally { | ||||
|             if (fos != null) fos.close(); | ||||
|             if (bis != null) bis.close(); | ||||
|  | ||||
| @ -113,13 +113,13 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
| //            if (mPutMethod != null && mPutMethod.isAborted()) { | ||||
| //                result = new RemoteOperationResult(new OperationCancelledException()); | ||||
| // | ||||
| //            } else { | ||||
| //                result = new RemoteOperationResult(e); | ||||
| //            } | ||||
|             if (mPutMethod != null && mPutMethod.isAborted()) { | ||||
|                 result = new RemoteOperationResult(new OperationCancelledException()); | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(e); | ||||
|             } | ||||
|         } finally { | ||||
|             // TODO | ||||
|             // reset previous retry handler | ||||
| //            client.getParams().setParameter( | ||||
| //                HttpMethodParams.RETRY_HANDLER, | ||||
| @ -129,9 +129,8 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { | ||||
|         RemoteOperationResult result; | ||||
|         try { | ||||
|     protected RemoteOperationResult uploadFile(OwnCloudClient client) throws Exception { | ||||
| 
 | ||||
|         File fileToUpload = new File(mLocalPath); | ||||
| 
 | ||||
|         MediaType mediaType = MediaType.parse(mMimeType); | ||||
| @ -160,16 +159,11 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
|         int status = client.executeHttpMethod(mPutMethod); | ||||
| 
 | ||||
|         if (isSuccess(status)) { | ||||
|                 result = new RemoteOperationResult(OK); | ||||
|             return new RemoteOperationResult(OK); | ||||
| 
 | ||||
|         } else { // synchronization failed | ||||
|                 result = new RemoteOperationResult(mPutMethod); | ||||
|             return new RemoteOperationResult(mPutMethod); | ||||
|         } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     public Set<OnDatatransferProgressListener> getDataTransferListeners() { | ||||
| @ -195,11 +189,11 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
|     } | ||||
|      | ||||
|     public void cancel() { | ||||
| //        synchronized (mCancellationRequested) { | ||||
| //            mCancellationRequested.set(true); | ||||
| //            if (mPutMethod != null) | ||||
| //                mPutMethod.abort(); | ||||
| //        } | ||||
|         synchronized (mCancellationRequested) { | ||||
|             mCancellationRequested.set(true); | ||||
|             if (mPutMethod != null) | ||||
|                 mPutMethod.abort(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public boolean isSuccess(int status) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user