mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
Singleton didn't work (worth a try though ^^) - Make a new constructor
instead
This commit is contained in:
parent
5282400a10
commit
eb1c63d3dc
9 changed files with 36 additions and 96 deletions
|
@ -28,15 +28,15 @@ import java.util.Vector;
|
|||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.app.Dialog;
|
||||
import android.app.ListActivity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
@ -46,21 +46,15 @@ import android.util.Log;
|
|||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.SimpleCursorAdapter;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.Toast;
|
||||
import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
|
||||
import eu.alefzero.owncloud.datamodel.DataStorageManager;
|
||||
import eu.alefzero.owncloud.datamodel.FileDataStorageManager;
|
||||
import eu.alefzero.owncloud.datamodel.OCFile;
|
||||
import eu.alefzero.owncloud.db.ProviderMeta;
|
||||
import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
|
||||
import eu.alefzero.owncloud.files.services.FileUploader;
|
||||
import eu.alefzero.owncloud.utils.OwnCloudVersion;
|
||||
import eu.alefzero.webdav.WebdavClient;
|
||||
|
||||
/**
|
||||
|
@ -74,7 +68,6 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
|
|||
|
||||
private Account mAccount;
|
||||
private AccountManager mAccountManager;
|
||||
private String mUsername, mPassword;
|
||||
private Stack<String> mParents;
|
||||
private ArrayList<Parcelable> mStreamsToUpload;
|
||||
private boolean mCreateDir;
|
||||
|
@ -298,8 +291,6 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
|
|||
}
|
||||
|
||||
private void populateDirectoryList() {
|
||||
mUsername = mAccount.name.substring(0, mAccount.name.indexOf('@'));
|
||||
mPassword = mAccountManager.getPassword(mAccount);
|
||||
setContentView(R.layout.uploader_layout);
|
||||
|
||||
String full_path = "";
|
||||
|
@ -378,15 +369,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
|
|||
}
|
||||
|
||||
public void uploadFiles() {
|
||||
OwnCloudVersion ocv = new OwnCloudVersion(mAccountManager.getUserData(mAccount,
|
||||
AccountAuthenticator.KEY_OC_VERSION));
|
||||
String base_url = mAccountManager.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL);
|
||||
String webdav_path = AccountUtils.getWebdavPath(ocv);
|
||||
Uri oc_uri = Uri.parse(base_url + webdav_path);
|
||||
|
||||
WebdavClient wdc = new WebdavClient(oc_uri);
|
||||
wdc.setCredentials(mUsername, mPassword);
|
||||
wdc.allowSelfsignedCertificates();
|
||||
WebdavClient wdc = new WebdavClient(mAccount, getApplicationContext());
|
||||
|
||||
// create last directory in path if nessesary
|
||||
if (mCreateDir) {
|
||||
|
|
|
@ -52,9 +52,7 @@ public class AuthenticationRunnable implements Runnable {
|
|||
public void run() {
|
||||
Uri uri;
|
||||
uri = Uri.parse(mUrl.toString());
|
||||
WebdavClient client = new WebdavClient(uri);
|
||||
client.setCredentials(mUsername, mPassword);
|
||||
int login_result = client.tryToLogin();
|
||||
int login_result = WebdavClient.tryToLogin(uri, mUsername, mPassword);
|
||||
switch (login_result) {
|
||||
case HttpStatus.SC_OK:
|
||||
postResult(true, uri.toString());
|
||||
|
|
|
@ -94,7 +94,7 @@ public class ConnectionCheckerRunnable implements Runnable {
|
|||
}
|
||||
|
||||
private boolean tryConnection(Uri uri) {
|
||||
WebdavClient wc = new WebdavClient(uri);
|
||||
WebdavClient wc = new WebdavClient();
|
||||
wc.allowSelfsignedCertificates();
|
||||
GetMethod get = new GetMethod(uri.toString());
|
||||
boolean retval = false;
|
||||
|
|
|
@ -11,7 +11,6 @@ import android.app.PendingIntent;
|
|||
import android.app.Service;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
|
@ -21,14 +20,10 @@ import android.os.Message;
|
|||
import android.os.Process;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
import eu.alefzero.owncloud.AccountUtils;
|
||||
import eu.alefzero.owncloud.R;
|
||||
import eu.alefzero.owncloud.R.drawable;
|
||||
import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
|
||||
import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
|
||||
import eu.alefzero.owncloud.files.interfaces.OnDatatransferProgressListener;
|
||||
import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;
|
||||
import eu.alefzero.owncloud.utils.OwnCloudVersion;
|
||||
import eu.alefzero.webdav.WebdavClient;
|
||||
|
||||
public class FileDownloader extends Service implements OnDatatransferProgressListener {
|
||||
|
@ -100,13 +95,9 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
|
|||
|
||||
void downloadFile() {
|
||||
AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
|
||||
String oc_base_url = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL);
|
||||
OwnCloudVersion ocv = new OwnCloudVersion(am
|
||||
.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));
|
||||
String webdav_path = AccountUtils.getWebdavPath(ocv);
|
||||
Uri oc_url = Uri.parse(oc_base_url+webdav_path);
|
||||
|
||||
WebdavClient wdc = new WebdavClient(Uri.parse(oc_base_url + webdav_path));
|
||||
|
||||
WebdavClient wdc = new WebdavClient(mAccount, getApplicationContext());
|
||||
|
||||
String username = mAccount.name.split("@")[0];
|
||||
String password = "";
|
||||
|
@ -143,8 +134,6 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Log.e(TAG, file.getAbsolutePath() + " " + oc_url.toString());
|
||||
Log.e(TAG, mFilePath+"");
|
||||
String message;
|
||||
if (wdc.downloadFile(mRemotePath, file)) {
|
||||
ContentValues cv = new ContentValues();
|
||||
|
|
|
@ -1,16 +1,7 @@
|
|||
package eu.alefzero.owncloud.files.services;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import eu.alefzero.owncloud.AccountUtils;
|
||||
import eu.alefzero.owncloud.R;
|
||||
import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
|
||||
import eu.alefzero.owncloud.datamodel.FileDataStorageManager;
|
||||
import eu.alefzero.owncloud.datamodel.OCFile;
|
||||
import eu.alefzero.owncloud.files.interfaces.OnDatatransferProgressListener;
|
||||
import eu.alefzero.owncloud.utils.OwnCloudVersion;
|
||||
import eu.alefzero.webdav.WebdavClient;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.Notification;
|
||||
|
@ -18,7 +9,6 @@ import android.app.NotificationManager;
|
|||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.IBinder;
|
||||
|
@ -29,6 +19,11 @@ import android.util.Log;
|
|||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.Toast;
|
||||
import eu.alefzero.owncloud.R;
|
||||
import eu.alefzero.owncloud.datamodel.FileDataStorageManager;
|
||||
import eu.alefzero.owncloud.datamodel.OCFile;
|
||||
import eu.alefzero.owncloud.files.interfaces.OnDatatransferProgressListener;
|
||||
import eu.alefzero.webdav.WebdavClient;
|
||||
|
||||
public class FileUploader extends Service implements OnDatatransferProgressListener {
|
||||
|
||||
|
@ -47,7 +42,6 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
|
|||
private NotificationManager mNotificationManager;
|
||||
private Looper mServiceLooper;
|
||||
private ServiceHandler mServiceHandler;
|
||||
private AccountManager mAccountManager;
|
||||
private Account mAccount;
|
||||
private String[] mLocalPaths, mRemotePaths;
|
||||
private int mUploadType;
|
||||
|
@ -82,7 +76,6 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
|
|||
thread.start();
|
||||
mServiceLooper = thread.getLooper();
|
||||
mServiceHandler = new ServiceHandler(mServiceLooper);
|
||||
mAccountManager = AccountManager.get(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,15 +127,6 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
|
|||
}
|
||||
|
||||
public void uploadFile() {
|
||||
String baseUrl = mAccountManager.getUserData(mAccount,
|
||||
AccountAuthenticator.KEY_OC_BASE_URL), ocVerStr = mAccountManager
|
||||
.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION);
|
||||
OwnCloudVersion ocVer = new OwnCloudVersion(ocVerStr);
|
||||
String webdav_path = AccountUtils.getWebdavPath(ocVer);
|
||||
Uri ocUri = Uri.parse(baseUrl + webdav_path);
|
||||
String username = mAccount.name.substring(0,
|
||||
mAccount.name.lastIndexOf('@'));
|
||||
String password = mAccountManager.getPassword(mAccount);
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(mAccount, getContentResolver());
|
||||
|
||||
mTotalDataToSend = mSendData = mPreviousPercent = 0;
|
||||
|
@ -160,10 +144,8 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
|
|||
|
||||
mNotificationManager.notify(42, mNotification);
|
||||
|
||||
WebdavClient wc = new WebdavClient(ocUri);
|
||||
wc.allowSelfsignedCertificates();
|
||||
WebdavClient wc = new WebdavClient(mAccount, getApplicationContext());
|
||||
wc.setDataTransferProgressListener(this);
|
||||
wc.setCredentials(username, password);
|
||||
|
||||
for (int i = 0; i < mLocalPaths.length; ++i) {
|
||||
File f = new File(mLocalPaths[i]);
|
||||
|
|
|
@ -139,7 +139,7 @@ public class InstantUploadService extends Service {
|
|||
String oc_version = am.getUserData(account, AccountAuthenticator.KEY_OC_VERSION);
|
||||
OwnCloudVersion ocv = new OwnCloudVersion(oc_version);
|
||||
String webdav_path = AccountUtils.getWebdavPath(ocv);
|
||||
WebdavClient wdc = new WebdavClient(Uri.parse(oc_base_url + webdav_path));
|
||||
WebdavClient wdc = new WebdavClient(account, getApplicationContext());
|
||||
wdc.allowSelfsignedCertificates();
|
||||
wdc.setCredentials(username, password);
|
||||
|
||||
|
|
|
@ -149,18 +149,11 @@ public abstract class AbstractOwnCloudSyncAdapter extends
|
|||
protected WebdavClient getClient() throws OperationCanceledException,
|
||||
AuthenticatorException, IOException {
|
||||
if (mClient == null) {
|
||||
String username = getAccount().name.split("@")[0];
|
||||
String password = this.getAccountManager().blockingGetAuthToken(
|
||||
getAccount(), AccountAuthenticator.AUTH_TOKEN_TYPE, true);
|
||||
if (this.getAccountManager().getUserData(getAccount(),
|
||||
AccountAuthenticator.KEY_OC_URL) == null) {
|
||||
throw new UnknownHostException();
|
||||
}
|
||||
Uri uri = getUri();
|
||||
|
||||
mClient = new WebdavClient(uri);
|
||||
mClient.setCredentials(username, password);
|
||||
mClient.allowSelfsignedCertificates();
|
||||
mClient = new WebdavClient(account, getContext());
|
||||
// mHost = mClient.getTargetHost();
|
||||
}
|
||||
|
||||
|
|
|
@ -560,8 +560,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
WebdavClient wdc = new WebdavClient(Uri.parse(mAm.getUserData(
|
||||
mAccount, AccountAuthenticator.KEY_OC_URL)));
|
||||
WebdavClient wdc = new WebdavClient(mAccount, getApplicationContext());
|
||||
|
||||
String username = mAccount.name.substring(0,
|
||||
mAccount.name.lastIndexOf('@'));
|
||||
|
|
|
@ -59,31 +59,26 @@ public class WebdavClient extends HttpClient {
|
|||
private static HashMap<String, WebdavClient> clients = new HashMap<String, WebdavClient>();
|
||||
|
||||
/**
|
||||
* Gets a WebdavClient setup for the current account
|
||||
* Creates a WebdavClient setup for the current account
|
||||
* @param account The client accout
|
||||
* @param context The application context
|
||||
* @return
|
||||
*/
|
||||
public static synchronized WebdavClient getInstance(Account account, Context context){
|
||||
WebdavClient instance = clients.get(account.name);
|
||||
if(instance == null ){
|
||||
OwnCloudVersion ownCloudVersion = new OwnCloudVersion(AccountManager.get(context).getUserData(account,
|
||||
AccountAuthenticator.KEY_OC_VERSION));
|
||||
String baseUrl = AccountManager.get(context).getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL);
|
||||
String webDavPath = AccountUtils.getWebdavPath(ownCloudVersion);
|
||||
WebdavClient client = new WebdavClient();
|
||||
|
||||
String username = account.name.substring(0, account.name.indexOf('@'));
|
||||
String password = AccountManager.get(context).getPassword(account);
|
||||
|
||||
client.mUri = Uri.parse(baseUrl + webDavPath);
|
||||
client.getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);
|
||||
client.setCredentials(username, password);
|
||||
client.allowSelfsignedCertificates();
|
||||
clients.put(account.name, client);
|
||||
}
|
||||
return instance;
|
||||
public WebdavClient (Account account, Context context){
|
||||
OwnCloudVersion ownCloudVersion = new OwnCloudVersion(AccountManager.get(context).getUserData(account,
|
||||
AccountAuthenticator.KEY_OC_VERSION));
|
||||
String baseUrl = AccountManager.get(context).getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL);
|
||||
String webDavPath = AccountUtils.getWebdavPath(ownCloudVersion);
|
||||
String username = account.name.substring(0, account.name.indexOf('@'));
|
||||
String password = AccountManager.get(context).getPassword(account);
|
||||
|
||||
mUri = Uri.parse(baseUrl + webDavPath);
|
||||
getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);
|
||||
setCredentials(username, password);
|
||||
allowSelfsignedCertificates();
|
||||
}
|
||||
|
||||
public WebdavClient(){}
|
||||
|
||||
public void setCredentials(String username, String password) {
|
||||
getParams().setAuthenticationPreemptive(true);
|
||||
|
@ -200,12 +195,13 @@ public class WebdavClient extends HttpClient {
|
|||
* @param password Password to verify
|
||||
* @return A {@link HttpStatus}-Code of the result. SC_OK is good.
|
||||
*/
|
||||
public int tryToLogin(Uri uri, String username, String password) {
|
||||
public static int tryToLogin(Uri uri, String username, String password) {
|
||||
int returnCode = 0;
|
||||
setCredentials(username, password);
|
||||
WebdavClient client = new WebdavClient();
|
||||
client.setCredentials(username, password);
|
||||
HeadMethod head = new HeadMethod(uri.toString());
|
||||
try {
|
||||
returnCode = executeMethod(head);
|
||||
returnCode = client.executeMethod(head);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error: " + e.getMessage());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue