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 OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
|
||||
OwnCloudClient getClientFor(OwnCloudAccount account, Context context)
|
||||
throws AccountNotFoundException, OperationCanceledException, AuthenticatorException,
|
||||
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,
|
||||
IOException, OperationCanceledException;
|
||||
|
||||
|
@ -39,31 +39,29 @@ import okhttp3.Protocol;
|
||||
*/
|
||||
public class HttpClient {
|
||||
|
||||
private static OkHttpClient mOkHttpClient;
|
||||
private static HttpInterceptor mOkHttpInterceptor;
|
||||
private static OkHttpClient sOkHttpClient;
|
||||
private static HttpInterceptor sOkHttpInterceptor;
|
||||
|
||||
public static OkHttpClient getOkHttpClient() {
|
||||
if (mOkHttpClient == null) {
|
||||
|
||||
mOkHttpClient = new OkHttpClient.Builder()
|
||||
.addInterceptor(mOkHttpInterceptor)
|
||||
if (sOkHttpClient == null) {
|
||||
sOkHttpClient = new OkHttpClient.Builder()
|
||||
.addInterceptor(getOkHttpInterceptor())
|
||||
.protocols(Arrays.asList(Protocol.HTTP_1_1))
|
||||
.followRedirects(false)
|
||||
.build();
|
||||
}
|
||||
|
||||
return mOkHttpClient;
|
||||
return sOkHttpClient;
|
||||
}
|
||||
|
||||
public static HttpInterceptor getOkHttpInterceptor() {
|
||||
if(mOkHttpInterceptor == null) {
|
||||
mOkHttpInterceptor = new HttpInterceptor()
|
||||
if (sOkHttpInterceptor == null) {
|
||||
sOkHttpInterceptor = new HttpInterceptor()
|
||||
.addRequestInterceptor(new UserAgentInterceptor(
|
||||
// TODO Try to get rid of this dependency
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/// perform remote operation
|
||||
RemoteOperationResult result = null;
|
||||
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.http.HttpConstants;
|
||||
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.OnDatatransferProgressListener;
|
||||
import com.owncloud.android.lib.common.network.ProgressiveDataTransferer;
|
||||
@ -157,7 +158,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
||||
MediaType mediaType = MediaType.parse(mMimeType);
|
||||
|
||||
mPutMethod.setRequestBody(
|
||||
RequestBody.create(mediaType, fileToUpload)
|
||||
FileRequestBody.create(mediaType, fileToUpload)
|
||||
);
|
||||
|
||||
int status = client.executeHttpMethod(mPutMethod);
|
||||
|
@ -175,7 +175,6 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation {
|
||||
} catch (IOException o) {
|
||||
Log_OC.e(TAG, "Unexpected exception closing output stream ", o);
|
||||
}
|
||||
client.exhaustResponse(getMethod.getResponseAsStream());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user