break;\r
}\r
}\r
- } else if (ocAccounts.length != 0) {\r
+ }\r
+ \r
+ if (defaultAccount == null && ocAccounts.length != 0) {\r
// we at least need to take first account as fallback\r
defaultAccount = ocAccounts[0];\r
}\r
}\r
\r
\r
- public static void setCurrentOwnCloudAccount(Context context, String name) {\r
- SharedPreferences.Editor appPrefs = PreferenceManager\r
- .getDefaultSharedPreferences(context).edit();\r
- appPrefs.putString("select_oc_account", name);\r
- appPrefs.commit();\r
+ public static boolean setCurrentOwnCloudAccount(Context context, String accountName) {\r
+ boolean result = false;\r
+ if (accountName != null) {\r
+ Account[] ocAccounts = AccountManager.get(context).getAccountsByType(\r
+ AccountAuthenticator.ACCOUNT_TYPE);\r
+ boolean found = false;\r
+ for (Account account : ocAccounts) {\r
+ found = (account.name.equals(accountName));\r
+ if (found) {\r
+ SharedPreferences.Editor appPrefs = PreferenceManager\r
+ .getDefaultSharedPreferences(context).edit();\r
+ appPrefs.putString("select_oc_account", accountName);\r
+ \r
+ appPrefs.commit();\r
+ result = true;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ return result;\r
}\r
\r
/**\r
super.onCreate(savedInstanceState);\r
\r
/// Load of parameters from received intent\r
- mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); // no check necessary, mCurrenDir == null if the parameter is not in the intent\r
Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT);\r
- if (account != null)\r
- AccountUtils.setCurrentOwnCloudAccount(this, account.name);\r
+ if (account != null && AccountUtils.setCurrentOwnCloudAccount(this, account.name)) {\r
+ mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); \r
+ }\r
\r
/// Load of saved instance state: keep this always before initDataFromCurrentAccount()\r
if(savedInstanceState != null) {\r
// Drop-down navigation \r
mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);\r
OCFile currFile = mCurrentDir;\r
- while(currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {\r
+ while(mStorageManager != null && currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {\r
mDirectories.add(currFile.getFileName());\r
currFile = mStorageManager.getFileById(currFile.getParentId());\r
}\r