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

Commit f89cfd9

Browse files
committed
Reformat some code thanks to code review
1 parent 6949764 commit f89cfd9

File tree

13 files changed

+49
-60
lines changed

13 files changed

+49
-60
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ public int executeHttpMethod(HttpBaseMethod method) throws Exception {
101101

102102
// Header to allow tracing requests in apache and ownCloud logs
103103
Timber.d("Executing in request with id %s", requestId);
104-
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID,requestId);
104+
method.setRequestHeader(HttpConstants.OC_X_REQUEST_ID, requestId);
105105
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
106106
method.setRequestHeader(HttpConstants.PARAM_SINGLE_COOKIE_HEADER, "true");
107107
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
108-
if(mCredentials.getHeaderAuth()!=null){
109-
method.setRequestHeader(HttpConstants.AUTHORIZATION_HEADER,mCredentials.getHeaderAuth());
108+
if (mCredentials.getHeaderAuth() != null) {
109+
method.setRequestHeader(HttpConstants.AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
110110
}
111111
status = method.execute();
112112

@@ -133,12 +133,12 @@ private int executeRedirectedHttpMethod(HttpBaseMethod method) throws Exception
133133

134134
// Header to allow tracing requests in apache and ownCloud logs
135135
Timber.d("Executing in request with id %s", requestId);
136-
method.setRequestHeader(OC_X_REQUEST_ID,requestId);
136+
method.setRequestHeader(OC_X_REQUEST_ID, requestId);
137137
method.setRequestHeader(HttpConstants.USER_AGENT_HEADER, SingleSessionManager.getUserAgent());
138138
method.setRequestHeader(HttpConstants.PARAM_SINGLE_COOKIE_HEADER, "true");
139139
method.setRequestHeader(HttpConstants.ACCEPT_ENCODING_HEADER, HttpConstants.ACCEPT_ENCODING_IDENTITY);
140-
if(mCredentials.getHeaderAuth()!=null){
141-
method.setRequestHeader(HttpConstants.AUTHORIZATION_HEADER,mCredentials.getHeaderAuth());
140+
if (mCredentials.getHeaderAuth() != null) {
141+
method.setRequestHeader(HttpConstants.AUTHORIZATION_HEADER, mCredentials.getHeaderAuth());
142142
}
143143
status = method.execute();
144144

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ abstract class HttpBaseMethod constructor(url: URL) {
1919
var httpUrl: HttpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
2020
var request: Request
2121
var requestBody: RequestBody? = null
22-
lateinit var response: Response
23-
private var responseBodyString: String? = null
22+
abstract var response: Response
2423

2524
var call: Call? = null
2625

@@ -100,12 +99,7 @@ abstract class HttpBaseMethod constructor(url: URL) {
10099
}
101100

102101
// Body
103-
fun getResponseBodyAsString(): String? {
104-
if (responseBodyString == null && response.body != null) {
105-
responseBodyString = response.body?.string()
106-
}
107-
return responseBodyString
108-
}
102+
fun getResponseBodyAsString(): String? = response.body?.string()
109103

110104
open fun getResponseBodyAsStream(): InputStream? {
111105
return response.body?.byteStream()

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/nonwebdav/HttpMethod.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@
2323
*/
2424
package com.owncloud.android.lib.common.http.methods.nonwebdav
2525

26-
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
27-
28-
import java.io.IOException;
29-
import java.net.URL;
26+
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
27+
import okhttp3.Response
28+
import java.net.URL
3029

3130
/**
3231
* Wrapper to perform OkHttp calls
3332
*
3433
* @author David González Verdugo
3534
*/
36-
abstract class HttpMethod(url: URL) : HttpBaseMethod(url) {
37-
@Throws(IOException::class)
35+
abstract class HttpMethod(
36+
url: URL
37+
) : HttpBaseMethod(url) {
38+
39+
override lateinit var response: Response
40+
3841
public override fun onExecute(): Int {
3942
call = okHttpClient.newCall(request)
4043
call?.let { response = it.execute() }

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/nonwebdav/PutMethod.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ import java.net.URL
3232
*
3333
* @author David González Verdugo
3434
*/
35-
class PutMethod(url: URL, private val putRequestBody: RequestBody) : HttpMethod(url) {
35+
class PutMethod(
36+
url: URL,
37+
private val putRequestBody: RequestBody
38+
) : HttpMethod(url) {
3639
@Throws(IOException::class)
3740
override fun onExecute(): Int {
3841
requestBody = putRequestBody

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
@@ -39,7 +39,7 @@ class CopyMethod(
3939
) : DavMethod(url) {
4040
@Throws(Exception::class)
4141
public override fun onExecute(): Int {
42-
mDavResource.copy(
42+
davResource.copy(
4343
destinationUrl,
4444
forceOverride,
4545
super.getRequestHeadersAsHashMap()

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ import java.util.concurrent.TimeUnit
4444
* @author David González Verdugo
4545
*/
4646
abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
47-
protected var mDavResource: DavOCResource
47+
protected var davResource: DavOCResource
48+
49+
override lateinit var response: Response
4850

4951
init {
5052
val httpUrl = url.toHttpUrlOrNull() ?: throw MalformedURLException()
51-
mDavResource = DavOCResource(
53+
davResource = DavOCResource(
5254
okHttpClient,
5355
httpUrl,
5456
log
5557
)
5658
}
5759

5860
override fun abort() {
59-
mDavResource.cancelCall()
61+
davResource.cancelCall()
6062
}
6163

6264
@Throws(Exception::class)
@@ -79,8 +81,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
7981
// The check below should be included in okhttp library, method ResponseBody.create(
8082
// TODO check most recent versions of okhttp to see if this is already fixed and try to update if so
8183
if (response.body?.contentType() != null) {
82-
val responseBody = (httpException.responseBody ?: ""
83-
).toResponseBody(response.body?.contentType())
84+
val responseBody = (httpException.responseBody ?: "").toResponseBody(response.body?.contentType())
8485
response = response.newBuilder()
8586
.body(responseBody)
8687
.build()
@@ -96,7 +97,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
9697
// Connection parameters
9798
override fun setReadTimeout(readTimeout: Long, timeUnit: TimeUnit) {
9899
super.setReadTimeout(readTimeout, timeUnit)
99-
mDavResource = DavOCResource(
100+
davResource = DavOCResource(
100101
okHttpClient,
101102
httpUrl,
102103
log
@@ -108,7 +109,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
108109
timeUnit: TimeUnit
109110
) {
110111
super.setConnectionTimeout(connectionTimeout, timeUnit)
111-
mDavResource = DavOCResource(
112+
davResource = DavOCResource(
112113
okHttpClient,
113114
httpUrl,
114115
log
@@ -117,7 +118,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
117118

118119
override fun setFollowRedirects(followRedirects: Boolean) {
119120
super.setFollowRedirects(followRedirects)
120-
mDavResource = DavOCResource(
121+
davResource = DavOCResource(
121122
okHttpClient,
122123
httpUrl,
123124
log
@@ -126,7 +127,7 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
126127

127128
override fun setUrl(url: HttpUrl) {
128129
super.setUrl(url)
129-
mDavResource = DavOCResource(
130+
davResource = DavOCResource(
130131
okHttpClient,
131132
httpUrl,
132133
log
@@ -135,30 +136,26 @@ abstract class DavMethod protected constructor(url: URL) : HttpBaseMethod(url) {
135136

136137
override fun setRequestHeader(name: String, value: String) {
137138
super.setRequestHeader(name, value)
138-
mDavResource = DavOCResource(
139+
davResource = DavOCResource(
139140
okHttpClient,
140141
httpUrl,
141142
log
142143
)
143144
}
144145

145-
fun getRetryOnConnectionFailure(): Boolean {
146-
return false //TODO: implement me
147-
}
148-
149146
//////////////////////////////
150147
// Getter
151148
//////////////////////////////
152149
override fun setRetryOnConnectionFailure(retryOnConnectionFailure: Boolean) {
153150
super.setRetryOnConnectionFailure(retryOnConnectionFailure)
154-
mDavResource = DavOCResource(
151+
davResource = DavOCResource(
155152
okHttpClient,
156153
httpUrl,
157154
log
158155
)
159156
}
160157

161158
override val isAborted: Boolean
162-
get() = mDavResource.isCallAborted()
159+
get() = davResource.isCallAborted()
163160

164-
}
161+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import java.net.URL
3535
class MkColMethod(url: URL) : DavMethod(url) {
3636
@Throws(Exception::class)
3737
public override fun onExecute(): Int {
38-
mDavResource.mkCol(
38+
davResource.mkCol(
3939
xmlBody = null,
4040
listOfHeaders = super.getRequestHeadersAsHashMap()
4141
) { callBackResponse: Response ->

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424
package com.owncloud.android.lib.common.http.methods.webdav
2525

26-
import com.owncloud.android.lib.common.http.HttpConstants
2726
import okhttp3.Response
2827
import java.net.URL
2928

@@ -40,7 +39,7 @@ class MoveMethod(
4039
) : DavMethod(url) {
4140
@Throws(Exception::class)
4241
public override fun onExecute(): Int {
43-
mDavResource.move(
42+
davResource.move(
4443
destinationUrl,
4544
forceOverride,
4645
super.getRequestHeadersAsHashMap()

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import at.bitfire.dav4jvm.Response.HrefRelation
2929
import at.bitfire.dav4jvm.exception.DavException
3030
import java.io.IOException
3131
import java.net.URL
32-
import java.util.ArrayList
3332

3433
/**
3534
* Propfind calls wrapper
@@ -38,42 +37,36 @@ import java.util.ArrayList
3837
*/
3938
class PropfindMethod(
4039
url: URL,
41-
// request
42-
val depth: Int,
43-
private val mPropertiesToRequest: Array<Property.Name>
40+
private val depth: Int,
41+
private val propertiesToRequest: Array<Property.Name>
4442
) : DavMethod(url) {
4543

4644
// response
47-
private val mMembers: MutableList<Response>
45+
val members: MutableList<Response>
4846
var root: Response?
4947
private set
5048

5149
@Throws(IOException::class, DavException::class)
5250
public override fun onExecute(): Int {
53-
mDavResource.propfind(
51+
davResource.propfind(
5452
depth = depth,
55-
reqProp = *mPropertiesToRequest,
53+
reqProp = *propertiesToRequest,
5654
listOfHeaders = super.getRequestHeadersAsHashMap(),
5755
callback = { response: Response, hrefRelation: HrefRelation? ->
5856
when (hrefRelation) {
59-
HrefRelation.MEMBER -> mMembers.add(response)
57+
HrefRelation.MEMBER -> members.add(response)
6058
HrefRelation.SELF -> this.root = response
6159
HrefRelation.OTHER -> {
6260
}
63-
else -> {
64-
}
6561
}
6662
}, rawCallback = { callBackResponse: okhttp3.Response ->
6763
response = callBackResponse
6864
})
6965
return statusCode
7066
}
7167

72-
val members: List<Response>
73-
get() = mMembers
74-
7568
init {
76-
mMembers = ArrayList()
69+
members = arrayListOf()
7770
this.root = null
7871
}
7972
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PutMethod(
3838
) : DavMethod(url) {
3939
@Throws(IOException::class, HttpException::class)
4040
public override fun onExecute(): Int {
41-
mDavResource.put(
41+
davResource.put(
4242
requestBody!!,
4343
super.getRequestHeader(HttpConstants.IF_MATCH_HEADER),
4444
getRequestHeadersAsHashMap()

0 commit comments

Comments
 (0)