mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
no need to use owncloudClient
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
259e106308
commit
251bb3ae19
2 changed files with 5 additions and 16 deletions
|
@ -21,18 +21,16 @@
|
||||||
package com.nextcloud.client.network;
|
package com.nextcloud.client.network;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AuthenticatorException;
|
|
||||||
import android.accounts.OperationCanceledException;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
|
||||||
import com.evernote.android.job.JobRequest;
|
import com.evernote.android.job.JobRequest;
|
||||||
import com.nextcloud.client.account.UserAccountManager;
|
import com.nextcloud.client.account.UserAccountManager;
|
||||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HttpClient;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -48,7 +46,6 @@ class ConnectivityServiceImpl implements ConnectivityService {
|
||||||
|
|
||||||
private ConnectivityManager connectivityManager;
|
private ConnectivityManager connectivityManager;
|
||||||
private UserAccountManager accountManager;
|
private UserAccountManager accountManager;
|
||||||
private ClientFactory clientFactory;
|
|
||||||
private GetRequestBuilder requestBuilder;
|
private GetRequestBuilder requestBuilder;
|
||||||
|
|
||||||
static class GetRequestBuilder implements Function1<String, GetMethod> {
|
static class GetRequestBuilder implements Function1<String, GetMethod> {
|
||||||
|
@ -60,11 +57,9 @@ class ConnectivityServiceImpl implements ConnectivityService {
|
||||||
|
|
||||||
ConnectivityServiceImpl(ConnectivityManager connectivityManager,
|
ConnectivityServiceImpl(ConnectivityManager connectivityManager,
|
||||||
UserAccountManager accountManager,
|
UserAccountManager accountManager,
|
||||||
ClientFactory clientFactory,
|
|
||||||
GetRequestBuilder requestBuilder) {
|
GetRequestBuilder requestBuilder) {
|
||||||
this.connectivityManager = connectivityManager;
|
this.connectivityManager = connectivityManager;
|
||||||
this.accountManager = accountManager;
|
this.accountManager = accountManager;
|
||||||
this.clientFactory = clientFactory;
|
|
||||||
this.requestBuilder = requestBuilder;
|
this.requestBuilder = requestBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,8 +68,8 @@ class ConnectivityServiceImpl implements ConnectivityService {
|
||||||
if (isOnlineWithWifi()) {
|
if (isOnlineWithWifi()) {
|
||||||
try {
|
try {
|
||||||
Account account = accountManager.getCurrentAccount();
|
Account account = accountManager.getCurrentAccount();
|
||||||
if (account != null) {
|
OwnCloudAccount ocAccount = accountManager.getCurrentOwnCloudAccount();
|
||||||
OwnCloudAccount ocAccount = accountManager.getCurrentOwnCloudAccount();
|
if (account != null && ocAccount != null) {
|
||||||
OwnCloudVersion serverVersion = accountManager.getServerVersion(account);
|
OwnCloudVersion serverVersion = accountManager.getServerVersion(account);
|
||||||
|
|
||||||
String url;
|
String url;
|
||||||
|
@ -85,7 +80,7 @@ class ConnectivityServiceImpl implements ConnectivityService {
|
||||||
}
|
}
|
||||||
|
|
||||||
GetMethod get = requestBuilder.invoke(url);
|
GetMethod get = requestBuilder.invoke(url);
|
||||||
OwnCloudClient client = clientFactory.create(account);
|
HttpClient client = new HttpClient();
|
||||||
|
|
||||||
int status = client.executeMethod(get);
|
int status = client.executeMethod(get);
|
||||||
|
|
||||||
|
@ -110,10 +105,6 @@ class ConnectivityServiceImpl implements ConnectivityService {
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log_OC.e(TAG, "Error checking internet connection", e);
|
Log_OC.e(TAG, "Error checking internet connection", e);
|
||||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
|
|
||||||
Log_OC.e(TAG, "Account not found", e);
|
|
||||||
} catch (OperationCanceledException | AuthenticatorException e) {
|
|
||||||
Log_OC.e(TAG, e.getMessage());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return getActiveNetworkType() == JobRequest.NetworkType.ANY;
|
return getActiveNetworkType() == JobRequest.NetworkType.ANY;
|
||||||
|
|
|
@ -35,11 +35,9 @@ public class NetworkModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
ConnectivityService connectivityService(ConnectivityManager connectivityManager,
|
ConnectivityService connectivityService(ConnectivityManager connectivityManager,
|
||||||
UserAccountManager accountManager,
|
UserAccountManager accountManager) {
|
||||||
ClientFactory clientFactory) {
|
|
||||||
return new ConnectivityServiceImpl(connectivityManager,
|
return new ConnectivityServiceImpl(connectivityManager,
|
||||||
accountManager,
|
accountManager,
|
||||||
clientFactory,
|
|
||||||
new ConnectivityServiceImpl.GetRequestBuilder());
|
new ConnectivityServiceImpl.GetRequestBuilder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue