Make these classes use the account selection from the preferences screen

This commit is contained in:
Lennart Rosam 2012-04-10 01:16:55 +02:00
parent a6e98cc7dc
commit 385211893f
2 changed files with 8 additions and 14 deletions

View file

@ -38,6 +38,7 @@ import android.widget.ArrayAdapter;
import android.widget.EditText; import android.widget.EditText;
import eu.alefzero.owncloud.R; import eu.alefzero.owncloud.R;
import eu.alefzero.owncloud.authenticator.AccountAuthenticator; import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
import eu.alefzero.owncloud.authenticator.AuthUtils;
import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.owncloud.datamodel.OCFile;
import eu.alefzero.owncloud.ui.fragment.FileList; import eu.alefzero.owncloud.ui.fragment.FileList;
import eu.alefzero.webdav.WebdavClient; import eu.alefzero.webdav.WebdavClient;
@ -66,6 +67,7 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
protected Dialog onCreateDialog(int id, Bundle args) { protected Dialog onCreateDialog(int id, Bundle args) {
final AlertDialog.Builder builder = new Builder(this); final AlertDialog.Builder builder = new Builder(this);
final EditText dirName = new EditText(getBaseContext()); final EditText dirName = new EditText(getBaseContext());
final Account a = AuthUtils.getCurrentOwnCloudAccount(this);
builder.setView(dirName); builder.setView(dirName);
builder.setTitle(R.string.uploader_info_dirname); builder.setTitle(R.string.uploader_info_dirname);
@ -76,10 +78,6 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
dialog.cancel(); dialog.cancel();
return; return;
} }
AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
// following account choosing is incorrect and needs to be replaced
// with some sort of session mechanism
Account a = am.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[0];
String path = ""; String path = "";
for (int i = mDirectories.getCount()-2; i >= 0; --i) { for (int i = mDirectories.getCount()-2; i >= 0; --i) {
@ -87,7 +85,7 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
} }
OCFile parent = new OCFile(getContentResolver(), a, path+"/"); OCFile parent = new OCFile(getContentResolver(), a, path+"/");
path += "/" + s + "/"; path += "/" + s + "/";
Thread thread = new Thread(new DirectoryCreator(path, a, am)); Thread thread = new Thread(new DirectoryCreator(path, a));
thread.start(); thread.start();
OCFile.createNewFile(getContentResolver(), a, path, 0, 0, 0, "DIR", parent.getFileId()).save(); OCFile.createNewFile(getContentResolver(), a, path, 0, 0, 0, "DIR", parent.getFileId()).save();
@ -200,10 +198,10 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity
private Account mAccount; private Account mAccount;
private AccountManager mAm; private AccountManager mAm;
public DirectoryCreator(String targetPath, Account account, AccountManager am) { public DirectoryCreator(String targetPath, Account account) {
mTargetPath = targetPath; mTargetPath = targetPath;
mAccount = account; mAccount = account;
mAm = am; mAm = (AccountManager) getSystemService(ACCOUNT_SERVICE);
} }
@Override @Override

View file

@ -22,8 +22,6 @@ import java.util.Stack;
import java.util.Vector; import java.util.Vector;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Service;
import android.content.ContentProviderOperation; import android.content.ContentProviderOperation;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@ -33,7 +31,7 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import eu.alefzero.owncloud.R; import eu.alefzero.owncloud.R;
import eu.alefzero.owncloud.authenticator.AccountAuthenticator; import eu.alefzero.owncloud.authenticator.AuthUtils;
import eu.alefzero.owncloud.datamodel.OCFile; import eu.alefzero.owncloud.datamodel.OCFile;
import eu.alefzero.owncloud.ui.FragmentListView; import eu.alefzero.owncloud.ui.FragmentListView;
import eu.alefzero.owncloud.ui.activity.FileDetailActivity; import eu.alefzero.owncloud.ui.activity.FileDetailActivity;
@ -47,7 +45,6 @@ import eu.alefzero.owncloud.ui.adapter.FileListListAdapter;
*/ */
public class FileList extends FragmentListView { public class FileList extends FragmentListView {
private Account mAccount; private Account mAccount;
private AccountManager mAccountManager;
private Stack<String> mDirNames; private Stack<String> mDirNames;
private Vector<OCFile> mFiles; private Vector<OCFile> mFiles;
@ -59,8 +56,7 @@ public class FileList extends FragmentListView {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mAccountManager = (AccountManager)getActivity().getSystemService(Service.ACCOUNT_SERVICE); mAccount = AuthUtils.getCurrentOwnCloudAccount(getActivity());
mAccount = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[0];
populateFileList(); populateFileList();
//addContact(mAccount, "Bartek Przybylski", "czlowiek"); //addContact(mAccount, "Bartek Przybylski", "czlowiek");
} }