mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Include user agent in OCContext and start implementing the generic put operation
This commit is contained in:
parent
77c7c5195b
commit
2ba891df15
@ -93,7 +93,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
|
||||
getString(R.string.username),
|
||||
getString(R.string.password)));
|
||||
|
||||
mOCContext = new OCContext(ocAccount);
|
||||
mOCContext = new OCContext(ocAccount, getString(R.string.user_agent));
|
||||
|
||||
mFilesAdapter = new FilesArrayAdapter(this, R.layout.file_in_list);
|
||||
((ListView)findViewById(R.id.list_view)).setAdapter(mFilesAdapter);
|
||||
|
@ -4,11 +4,6 @@ import com.owncloud.android.lib.refactor.account.OCAccount;
|
||||
|
||||
public class OCContext {
|
||||
private static final String TAG = OCContext.class.toString();
|
||||
|
||||
public static final String WEBDAV_PATH_4_0 = "/remote.php/dav";
|
||||
public static final String STATUS_PATH = "/status.php";
|
||||
public static final String FILES_WEB_PATH = "/index.php/apps/files";
|
||||
|
||||
private static final int MAX_REDIRECTIONS_COUNT = 3;
|
||||
private static final int MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS = 1;
|
||||
private static final String PARAM_SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header";
|
||||
@ -16,12 +11,18 @@ public class OCContext {
|
||||
private static final String PARAM_PROTOCOL_VERSION = "http.protocol.version";
|
||||
|
||||
private OCAccount mOCAccount;
|
||||
private String mUserAgent;
|
||||
|
||||
public OCContext(OCAccount account) {
|
||||
public OCContext(OCAccount account, String userAgent) {
|
||||
mOCAccount = account;
|
||||
mUserAgent = userAgent;
|
||||
}
|
||||
|
||||
public OCAccount getOCAccount() {
|
||||
return mOCAccount;
|
||||
}
|
||||
|
||||
public String getUserAgent() {
|
||||
return mUserAgent;
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@ import okhttp3.Request;
|
||||
|
||||
public abstract class RemoteOperation {
|
||||
private final OCContext mContext;
|
||||
// TODO Move to a constants file
|
||||
private static final String USER_AGENT_HEADER = "User-Agent";
|
||||
private static final String WEBDAV_PATH_4_0 = "remote.php/dav/files";
|
||||
private static OkHttpClient mClient = null;
|
||||
|
||||
@ -37,6 +39,7 @@ public abstract class RemoteOperation {
|
||||
chain.proceed(
|
||||
addRequestCredentials(
|
||||
chain.request())
|
||||
.addHeader(USER_AGENT_HEADER, mContext.getUserAgent())
|
||||
.build()))
|
||||
.followRedirects(false)
|
||||
.build();
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.owncloud.android.lib.refactor.operations;
|
||||
|
||||
import com.owncloud.android.lib.refactor.OCContext;
|
||||
import com.owncloud.android.lib.refactor.RemoteOperation;
|
||||
import com.owncloud.android.lib.refactor.RemoteOperationResult;
|
||||
|
||||
import at.bitfire.dav4android.DavOCResource;
|
||||
import at.bitfire.dav4android.DavResource;
|
||||
import at.bitfire.dav4android.PropertyUtils;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class PutOperation extends RemoteOperation {
|
||||
|
||||
private String mRemotePath;
|
||||
private String mMimeType;
|
||||
private String mTimeStamp;
|
||||
|
||||
public PutOperation(OCContext context, String remotePath, String mimetype, String timestamp) {
|
||||
super(context);
|
||||
|
||||
mRemotePath = remotePath;
|
||||
mMimeType = mimetype;
|
||||
mTimeStamp = timestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemoteOperationResult exec() {
|
||||
|
||||
try {
|
||||
|
||||
MediaType mediaType = MediaType.parse(mMimeType);
|
||||
RequestBody requestBody = RequestBody.create(mediaType, mRemotePath);
|
||||
|
||||
DavOCResource davOCResource = new DavOCResource(getClient(), getWebDavHttpUrl(mRemotePath), null);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user