1
0
mirror of https://github.com/owncloud/android-library.git synced 2026-08-20 21:02:53 +00:00

Code refactoring

This commit is contained in:
davigonz
2018-06-05 17:40:05 +02:00
parent dfab453e6b
commit 1cf44a9fff
7 changed files with 117 additions and 69 deletions
@@ -1,5 +1,18 @@
package com.owncloud.android.lib.common.methods;
public interface HttpBaseMethod {
int execute() throws Exception;
import okhttp3.Request;
import okhttp3.Response;
public abstract class HttpBaseMethod {
public abstract int execute() throws Exception;
protected Request mRequest;
protected Response mResponse;
public Request getRequest() {
return mRequest;
}
public Response getResponse() {
return mResponse;
}
}
@@ -8,19 +8,18 @@ import okhttp3.Response;
public class GetMethod extends HttpMethod {
public GetMethod(OkHttpClient okHttpClient, String url) {
super(okHttpClient, url);
public GetMethod(OkHttpClient okHttpClient, Request requestBase) {
super(okHttpClient, requestBase);
}
@Override
public int execute() throws IOException {
final Request request =
new Request.Builder()
.url(mUrl)
final Request request = mBaseRequest
.newBuilder()
.get()
.build();
Response response = mOkHttpClient.newCall(request).execute();
return response.code();
mResponse = mOkHttpClient.newCall(request).execute();
return mResponse.code();
}
}
@@ -3,14 +3,15 @@ package com.owncloud.android.lib.common.methods.nonwebdav;
import com.owncloud.android.lib.common.methods.HttpBaseMethod;
import okhttp3.OkHttpClient;
import okhttp3.Request;
public abstract class HttpMethod implements HttpBaseMethod {
public abstract class HttpMethod extends HttpBaseMethod {
protected OkHttpClient mOkHttpClient;
protected String mUrl;
protected Request mBaseRequest;
public HttpMethod (OkHttpClient okHttpClient, String url) {
public HttpMethod (OkHttpClient okHttpClient, Request baseRequest) {
mOkHttpClient = okHttpClient;
mUrl = url;
mBaseRequest = baseRequest;
}
}
@@ -2,13 +2,16 @@ package com.owncloud.android.lib.common.methods.webdav;
import com.owncloud.android.lib.common.methods.HttpBaseMethod;
import at.bitfire.dav4android.DavOCResource;
import at.bitfire.dav4android.DavResource;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
public abstract class DavMethod implements HttpBaseMethod {
public abstract class DavMethod extends HttpBaseMethod {
protected DavResource mDavResource;
public DavMethod(DavResource davResource) {
mDavResource = davResource;
public DavMethod(OkHttpClient okHttpClient, HttpUrl httpUrl) {
mDavResource = new DavOCResource(okHttpClient, httpUrl);
}
}
@@ -1,28 +1,51 @@
package com.owncloud.android.lib.common.methods.webdav;
import java.io.IOException;
import com.owncloud.android.lib.common.network.WebdavUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Set;
import at.bitfire.dav4android.DavOCResource;
import at.bitfire.dav4android.DavResource;
import at.bitfire.dav4android.PropertyUtils;
import at.bitfire.dav4android.exception.DavException;
import at.bitfire.dav4android.exception.HttpException;
import at.bitfire.dav4android.exception.UnauthorizedException;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
public class PropfindMethod extends DavMethod {
private int mDepth;
private Set<DavResource> mMembers;
public PropfindMethod(DavResource davResource, int depth) {
super(davResource);
public PropfindMethod(OkHttpClient okHttpClient, HttpUrl httpUrl, int depth) {
super(okHttpClient, httpUrl);
mDepth = depth;
};
@Override
public int execute() throws IOException, HttpException, DavException {
try {
mDavResource.propfind(mDepth, PropertyUtils.INSTANCE.getAllPropSet());
mMembers = mDavResource.getMembers();
} catch (UnauthorizedException davException) {
return 401;
// Do nothing, we will use the 401 code to handle the situation
}
return mDavResource.getResponse().code();
mRequest = mDavResource.getRequest();
mResponse = mDavResource.getResponse();
return mResponse.code();
}
public int getDepth() {
return mDepth;
}
public Set<DavResource> getMembers() {
return mMembers;
}
}