mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-28 10:16:35 +00:00
apply requested changes
This commit is contained in:
parent
09375ce053
commit
105830e4f0
@ -1,58 +0,0 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* Copyright (C) 2020 ownCloud GmbH.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.lib.common;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.owncloud.android.lib.common.http.HttpClient;
|
||||
import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation;
|
||||
|
||||
public class OwnCloudClientFactory {
|
||||
|
||||
/**
|
||||
* Creates a OwnCloudClient to access a URL and sets the desired parameters for ownCloud
|
||||
* client connections.
|
||||
*
|
||||
* @param uri URL to the ownCloud server; BASE ENTRY POINT, not WebDavPATH
|
||||
* @return A OwnCloudClient object ready to be used
|
||||
*/
|
||||
public static OwnCloudClient createOwnCloudClient(Uri uri,
|
||||
ConnectionValidator connectionValidator,
|
||||
boolean followRedirects,
|
||||
SingleSessionManager singleSessionManager,
|
||||
Context context) {
|
||||
OwnCloudClient client = new OwnCloudClient(uri, connectionValidator, true, singleSessionManager, context);
|
||||
|
||||
client.setFollowRedirects(followRedirects);
|
||||
retrieveCookiesFromMiddleware(client);
|
||||
return client;
|
||||
}
|
||||
|
||||
private static void retrieveCookiesFromMiddleware(OwnCloudClient client) {
|
||||
final GetRemoteStatusOperation statusOperation = new GetRemoteStatusOperation();
|
||||
statusOperation.run(client);
|
||||
}
|
||||
}
|
@ -61,15 +61,14 @@ public class HttpClient {
|
||||
private OkHttpClient mOkHttpClient = null;
|
||||
|
||||
protected HttpClient(Context context) {
|
||||
if(context == null) {
|
||||
Timber.e("Context may not be NULL!");
|
||||
throw new NullPointerException("Context may not be NULL!");
|
||||
}
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public OkHttpClient getOkHttpClient() {
|
||||
if (mContext == null) {
|
||||
Timber.e("Context not initialized call HttpClient.setContext(applicationContext) in the MainApp.onCrate()");
|
||||
throw new RuntimeException("Context not initialized call HttpClient.setContext(applicationContext) in the" +
|
||||
" MainApp.onCrate()");
|
||||
}
|
||||
if (mOkHttpClient == null) {
|
||||
try {
|
||||
final X509TrustManager trustManager = new AdvancedX509TrustManager(
|
||||
|
@ -60,8 +60,8 @@ abstract class HttpBaseMethod constructor(url: URL) {
|
||||
@Throws(Exception::class)
|
||||
open fun execute(httpClient: HttpClient): Int {
|
||||
val okHttpClient = httpClient.okHttpClient.newBuilder().apply {
|
||||
retryOnConnectionFailure?.let { retryOnConnectionFailure(it) }
|
||||
followRedirects?.let { followRedirects(it) }
|
||||
retryOnConnectionFailure.let { retryOnConnectionFailure(it) }
|
||||
followRedirects.let { followRedirects(it) }
|
||||
readTimeoutUnit?.let { unit ->
|
||||
readTimeoutVal?.let { readTimeout(it, unit) }
|
||||
}
|
||||
@ -152,12 +152,7 @@ abstract class HttpBaseMethod constructor(url: URL) {
|
||||
// Setter
|
||||
//////////////////////////////
|
||||
// Connection parameters
|
||||
/*
|
||||
open fun setRetryOnConnectionFailure(retryOnConnectionFailure: Boolean) {
|
||||
retryOnConnectionFailureVal = true
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
open fun setReadTimeout(readTimeout: Long, timeUnit: TimeUnit) {
|
||||
readTimeoutVal = readTimeout
|
||||
|
@ -74,7 +74,6 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
Timber.plant(new DebugTree());
|
||||
mHandler = new Handler();
|
||||
|
||||
final Uri serverUri = Uri.parse(getString(R.string.server_base_url));
|
||||
@ -86,8 +85,6 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
|
||||
true,
|
||||
SingleSessionManager.getDefaultSingleton());
|
||||
|
||||
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
|
||||
|
||||
mClient.setCredentials(
|
||||
OwnCloudCredentialsFactory.newBasicCredentials(
|
||||
getString(R.string.username),
|
||||
|
Loading…
x
Reference in New Issue
Block a user