From 385211893f707701c2c93014f5ae64d5a677e385 Mon Sep 17 00:00:00 2001 From: Lennart Rosam Date: Tue, 10 Apr 2012 01:16:55 +0200 Subject: [PATCH] Make these classes use the account selection from the preferences screen --- .../owncloud/ui/activity/FileDisplayActivity.java | 14 ++++++-------- src/eu/alefzero/owncloud/ui/fragment/FileList.java | 8 ++------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index a7546283bd..f726fd9bd0 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -38,6 +38,7 @@ import android.widget.ArrayAdapter; import android.widget.EditText; 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.ui.fragment.FileList; 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) { final AlertDialog.Builder builder = new Builder(this); final EditText dirName = new EditText(getBaseContext()); + final Account a = AuthUtils.getCurrentOwnCloudAccount(this); builder.setView(dirName); builder.setTitle(R.string.uploader_info_dirname); @@ -76,18 +78,14 @@ public class FileDisplayActivity extends android.support.v4.app.FragmentActivity dialog.cancel(); 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 = ""; for (int i = mDirectories.getCount()-2; i >= 0; --i) { path += "/" + mDirectories.getItem(i); } OCFile parent = new OCFile(getContentResolver(), a, path+"/"); path += "/" + s + "/"; - Thread thread = new Thread(new DirectoryCreator(path, a, am)); + Thread thread = new Thread(new DirectoryCreator(path, a)); thread.start(); 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 AccountManager mAm; - public DirectoryCreator(String targetPath, Account account, AccountManager am) { + public DirectoryCreator(String targetPath, Account account) { mTargetPath = targetPath; mAccount = account; - mAm = am; + mAm = (AccountManager) getSystemService(ACCOUNT_SERVICE); } @Override diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileList.java b/src/eu/alefzero/owncloud/ui/fragment/FileList.java index c71d9bf69f..bb600934f5 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileList.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileList.java @@ -22,8 +22,6 @@ import java.util.Stack; import java.util.Vector; import android.accounts.Account; -import android.accounts.AccountManager; -import android.app.Service; import android.content.ContentProviderOperation; import android.content.Intent; import android.os.Bundle; @@ -33,7 +31,7 @@ import android.util.Log; import android.view.View; import android.widget.AdapterView; 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.ui.FragmentListView; import eu.alefzero.owncloud.ui.activity.FileDetailActivity; @@ -47,7 +45,6 @@ import eu.alefzero.owncloud.ui.adapter.FileListListAdapter; */ public class FileList extends FragmentListView { private Account mAccount; - private AccountManager mAccountManager; private Stack mDirNames; private Vector mFiles; @@ -59,8 +56,7 @@ public class FileList extends FragmentListView { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mAccountManager = (AccountManager)getActivity().getSystemService(Service.ACCOUNT_SERVICE); - mAccount = mAccountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[0]; + mAccount = AuthUtils.getCurrentOwnCloudAccount(getActivity()); populateFileList(); //addContact(mAccount, "Bartek Przybylski", "czlowiek"); }