mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Working on having the upload progress
This commit is contained in:
parent
2041fb1962
commit
ff17ab6837
@ -42,13 +42,13 @@ import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundExce
|
|||||||
|
|
||||||
public interface OwnCloudClientManager {
|
public interface OwnCloudClientManager {
|
||||||
|
|
||||||
public OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
|
OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
|
||||||
throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
|
throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
|
||||||
IOException;
|
IOException;
|
||||||
|
|
||||||
public OwnCloudClient removeClientFor(OwnCloudAccount account);
|
OwnCloudClient removeClientFor(OwnCloudAccount account);
|
||||||
|
|
||||||
public void saveAllClients(Context context, String accountType)
|
void saveAllClients(Context context, String accountType)
|
||||||
throws AccountNotFoundException, AuthenticatorException,
|
throws AccountNotFoundException, AuthenticatorException,
|
||||||
IOException, OperationCanceledException;
|
IOException, OperationCanceledException;
|
||||||
|
|
||||||
|
@ -39,31 +39,29 @@ import okhttp3.Protocol;
|
|||||||
*/
|
*/
|
||||||
public class HttpClient {
|
public class HttpClient {
|
||||||
|
|
||||||
private static OkHttpClient mOkHttpClient;
|
private static OkHttpClient sOkHttpClient;
|
||||||
private static HttpInterceptor mOkHttpInterceptor;
|
private static HttpInterceptor sOkHttpInterceptor;
|
||||||
|
|
||||||
public static OkHttpClient getOkHttpClient() {
|
public static OkHttpClient getOkHttpClient() {
|
||||||
if (mOkHttpClient == null) {
|
if (sOkHttpClient == null) {
|
||||||
|
sOkHttpClient = new OkHttpClient.Builder()
|
||||||
mOkHttpClient = new OkHttpClient.Builder()
|
.addInterceptor(getOkHttpInterceptor())
|
||||||
.addInterceptor(mOkHttpInterceptor)
|
|
||||||
.protocols(Arrays.asList(Protocol.HTTP_1_1))
|
.protocols(Arrays.asList(Protocol.HTTP_1_1))
|
||||||
.followRedirects(false)
|
.followRedirects(false)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
return sOkHttpClient;
|
||||||
return mOkHttpClient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpInterceptor getOkHttpInterceptor() {
|
public static HttpInterceptor getOkHttpInterceptor() {
|
||||||
if(mOkHttpInterceptor == null) {
|
if (sOkHttpInterceptor == null) {
|
||||||
mOkHttpInterceptor = new HttpInterceptor()
|
sOkHttpInterceptor = new HttpInterceptor()
|
||||||
.addRequestInterceptor(new UserAgentInterceptor(
|
.addRequestInterceptor(new UserAgentInterceptor(
|
||||||
// TODO Try to get rid of this dependency
|
// TODO Try to get rid of this dependency
|
||||||
OwnCloudClientManagerFactory.getUserAgent()
|
OwnCloudClientManagerFactory.getUserAgent()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return mOkHttpInterceptor;
|
return sOkHttpInterceptor;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.owncloud.android.lib.common.network;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
import okio.Buffer;
|
||||||
|
import okio.BufferedSink;
|
||||||
|
import okio.Okio;
|
||||||
|
import okio.Source;
|
||||||
|
|
||||||
|
import static android.content.ContentValues.TAG;
|
||||||
|
|
||||||
|
public class FileRequestBody extends RequestBody {
|
||||||
|
|
||||||
|
MediaType mContentType;
|
||||||
|
File mFile;
|
||||||
|
|
||||||
|
FileRequestBody(MediaType contentType, File file) {
|
||||||
|
mContentType = contentType;
|
||||||
|
mFile = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MediaType contentType() {
|
||||||
|
return mContentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(BufferedSink sink) {
|
||||||
|
Source source;
|
||||||
|
try {
|
||||||
|
source = Okio.source(mFile);
|
||||||
|
//sink.writeAll(source);
|
||||||
|
Buffer buffer = new Buffer();
|
||||||
|
Long remaining = contentLength();
|
||||||
|
|
||||||
|
for (long readCount; (readCount = source.read(buffer, 2048)) != -1;) {
|
||||||
|
sink.write(buffer, readCount);
|
||||||
|
Log.d(TAG, "source size: " + contentLength() + " remaining bytes: " + (remaining -= readCount));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -105,7 +105,6 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
|
return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// perform remote operation
|
/// perform remote operation
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result = null;
|
||||||
try {
|
try {
|
||||||
|
@ -27,6 +27,7 @@ package com.owncloud.android.lib.resources.files;
|
|||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||||
import com.owncloud.android.lib.common.http.HttpUtils;
|
import com.owncloud.android.lib.common.http.HttpUtils;
|
||||||
|
import com.owncloud.android.lib.common.network.FileRequestBody;
|
||||||
import com.owncloud.android.lib.common.network.FileRequestEntity;
|
import com.owncloud.android.lib.common.network.FileRequestEntity;
|
||||||
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
|
||||||
import com.owncloud.android.lib.common.network.ProgressiveDataTransferer;
|
import com.owncloud.android.lib.common.network.ProgressiveDataTransferer;
|
||||||
@ -157,7 +158,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
|||||||
MediaType mediaType = MediaType.parse(mMimeType);
|
MediaType mediaType = MediaType.parse(mMimeType);
|
||||||
|
|
||||||
mPutMethod.setRequestBody(
|
mPutMethod.setRequestBody(
|
||||||
RequestBody.create(mediaType, fileToUpload)
|
FileRequestBody.create(mediaType, fileToUpload)
|
||||||
);
|
);
|
||||||
|
|
||||||
int status = client.executeHttpMethod(mPutMethod);
|
int status = client.executeHttpMethod(mPutMethod);
|
||||||
|
@ -175,7 +175,6 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation {
|
|||||||
} catch (IOException o) {
|
} catch (IOException o) {
|
||||||
Log_OC.e(TAG, "Unexpected exception closing output stream ", o);
|
Log_OC.e(TAG, "Unexpected exception closing output stream ", o);
|
||||||
}
|
}
|
||||||
client.exhaustResponse(getMethod.getResponseAsStream());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user