Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 359e591

Browse files
authored
Merge pull request #339 from owncloud/new_arch/synchronization
[New arch] Synchronization
2 parents c2f7426 + f9bc792 commit 359e591

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2004
-2202
lines changed

owncloudComLibrary/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-kapt'
4+
apply plugin: 'kotlin-parcelize'
45

56
dependencies {
67
api 'com.squareup.okhttp3:okhttp:4.6.0'

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.owncloud.android.lib.common.http.HttpConstants;
3737
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
3838
import com.owncloud.android.lib.common.utils.RandomUtils;
39-
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
4039
import okhttp3.Cookie;
4140
import okhttp3.HttpUrl;
4241
import timber.log.Timber;
@@ -59,7 +58,6 @@ public class OwnCloudClient extends HttpClient {
5958
private OwnCloudCredentials mCredentials = null;
6059
private int mInstanceNumber;
6160
private Uri mBaseUri;
62-
private OwnCloudVersion mVersion = null;
6361
private OwnCloudAccount mAccount;
6462
private final ConnectionValidator mConnectionValidator;
6563
private Object mRequestMutex = new Object();
@@ -185,7 +183,7 @@ public Uri getUserFilesWebDavUri() {
185183
return (mCredentials instanceof OwnCloudAnonymousCredentials || mAccount == null)
186184
? Uri.parse(mBaseUri + WEBDAV_FILES_PATH_4_0)
187185
: Uri.parse(mBaseUri + WEBDAV_FILES_PATH_4_0 + AccountUtils.getUserId(
188-
mAccount.getSavedAccount(), getContext()
186+
mAccount.getSavedAccount(), getContext()
189187
)
190188
);
191189
}
@@ -194,7 +192,7 @@ public Uri getUploadsWebDavUri() {
194192
return mCredentials instanceof OwnCloudAnonymousCredentials
195193
? Uri.parse(mBaseUri + WEBDAV_UPLOADS_PATH_4_0)
196194
: Uri.parse(mBaseUri + WEBDAV_UPLOADS_PATH_4_0 + AccountUtils.getUserId(
197-
mAccount.getSavedAccount(), getContext()
195+
mAccount.getSavedAccount(), getContext()
198196
)
199197
);
200198
}
@@ -241,14 +239,6 @@ public List<Cookie> getCookiesForBaseUri() {
241239
HttpUrl.parse(mBaseUri.toString()));
242240
}
243241

244-
public OwnCloudVersion getOwnCloudVersion() {
245-
return mVersion;
246-
}
247-
248-
public void setOwnCloudVersion(OwnCloudVersion version) {
249-
mVersion = version;
250-
}
251-
252242
public OwnCloudAccount getAccount() {
253243
return mAccount;
254244
}
@@ -260,4 +250,4 @@ public void setAccount(OwnCloudAccount account) {
260250
public void setFollowRedirects(boolean followRedirects) {
261251
this.mFollowRedirects = followRedirects;
262252
}
263-
}
253+
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,6 @@ public static String getUsernameForAccount(Account account) {
9494
return username;
9595
}
9696

97-
/**
98-
* Get the stored server version corresponding to an OC account.
99-
*
100-
* @param account An OC account
101-
* @param context Application context
102-
* @return Version of the OC server, according to last check
103-
*/
104-
public static OwnCloudVersion getServerVersionForAccount(Account account, Context context) {
105-
AccountManager ama = AccountManager.get(context);
106-
OwnCloudVersion version = null;
107-
try {
108-
String versionString = ama.getUserData(account, Constants.KEY_OC_VERSION);
109-
version = new OwnCloudVersion(versionString);
110-
111-
} catch (Exception e) {
112-
Timber.e(e, "Couldn't get a the server version for an account");
113-
}
114-
return version;
115-
}
116-
11797
/**
11898
* @return
11999
* @throws IOException
@@ -209,11 +189,6 @@ public Account getFailedAccount() {
209189
}
210190

211191
public static class Constants {
212-
/**
213-
* Version should be 3 numbers separated by dot so it can be parsed by
214-
* {@link OwnCloudVersion}
215-
*/
216-
public static final String KEY_OC_VERSION = "oc_version";
217192
/**
218193
* Base url should point to owncloud installation without trailing / ie:
219194
* http://server/path or https://owncloud.server

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/CopyMethod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import java.net.URL
3636
class CopyMethod(
3737
val url: URL,
3838
private val destinationUrl: String,
39-
private val forceOverride: Boolean
39+
private val forceOverride: Boolean = false
4040
) : DavMethod(url) {
4141
@Throws(Exception::class)
4242
public override fun onDavExecute(davResource: DavOCResource): Int {

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/MoveMethod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import java.net.URL
3636
class MoveMethod(
3737
url: URL,
3838
private val destinationUrl: String,
39-
private val forceOverride: Boolean
39+
private val forceOverride: Boolean = false
4040
) : DavMethod(url) {
4141
@Throws(Exception::class)
4242
override fun onDavExecute(davResource: DavOCResource): Int {

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/webdav/PropfindMethod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class PropfindMethod(
5353
depth = depth,
5454
reqProp = propertiesToRequest,
5555
listOfHeaders = super.getRequestHeadersAsHashMap(),
56-
callback = { response: Response, hrefRelation: HrefRelation? ->
56+
callback = { response: Response, hrefRelation: HrefRelation ->
5757
when (hrefRelation) {
5858
HrefRelation.MEMBER -> members.add(response)
5959
HrefRelation.SELF -> this.root = response

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/ChunkFromFileRequestBody.java

Lines changed: 0 additions & 114 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/* ownCloud Android Library is available under MIT license
2+
* Copyright (C) 2022 ownCloud GmbH.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*
23+
*/
24+
package com.owncloud.android.lib.common.network
25+
26+
import com.owncloud.android.lib.resources.files.chunks.ChunkedUploadFromFileSystemOperation.Companion.CHUNK_SIZE
27+
import okhttp3.MediaType
28+
import okio.BufferedSink
29+
import timber.log.Timber
30+
import java.io.File
31+
import java.nio.ByteBuffer
32+
import java.nio.channels.FileChannel
33+
34+
/**
35+
* A Request body that represents a file chunk and include information about the progress when uploading it
36+
*
37+
* @author David González Verdugo
38+
*/
39+
class ChunkFromFileRequestBody(
40+
file: File,
41+
contentType: MediaType?,
42+
private val channel: FileChannel,
43+
private val chunkSize: Long = CHUNK_SIZE
44+
) : FileRequestBody(file, contentType) {
45+
46+
private var offset: Long = 0
47+
private var alreadyTransferred: Long = 0
48+
private val buffer = ByteBuffer.allocate(4_096)
49+
50+
init {
51+
require(chunkSize > 0) { "Chunk size must be greater than zero" }
52+
}
53+
54+
override fun contentLength(): Long {
55+
return chunkSize.coerceAtMost(channel.size() - channel.position())
56+
}
57+
58+
override fun writeTo(sink: BufferedSink) {
59+
var readCount: Int
60+
var iterator: Iterator<OnDatatransferProgressListener>
61+
try {
62+
channel.position(offset)
63+
64+
val maxCount = (offset + chunkSize).coerceAtMost(channel.size())
65+
while (channel.position() < maxCount) {
66+
readCount = channel.read(buffer)
67+
val bytesToWriteInBuffer = readCount.toLong().coerceAtMost(file.length() - alreadyTransferred).toInt()
68+
sink.buffer.write(buffer.array(), 0, bytesToWriteInBuffer)
69+
sink.flush()
70+
buffer.clear()
71+
72+
if (alreadyTransferred < maxCount) { // condition to avoid accumulate progress for repeated chunks
73+
alreadyTransferred += readCount.toLong()
74+
}
75+
76+
synchronized(dataTransferListeners) {
77+
iterator = dataTransferListeners.iterator()
78+
while (iterator.hasNext()) {
79+
iterator.next().onTransferProgress(readCount.toLong(), alreadyTransferred, file.length(), file.absolutePath)
80+
}
81+
}
82+
}
83+
} catch (exception: Exception) {
84+
Timber.e(exception, "Transferred " + alreadyTransferred + " bytes from a total of " + file.length())
85+
}
86+
}
87+
88+
fun setOffset(newOffset: Long) {
89+
offset = newOffset
90+
}
91+
92+
}

0 commit comments

Comments
 (0)