Fixed CRASH due to NullPointerException when a details actitivity is brough to foreground and the OC icon is pressed, after removing accounts in system settings

This commit is contained in:
David A. Velasco 2013-03-07 12:38:47 +01:00
parent 4b46b17fcb
commit d19d985c0a
2 changed files with 27 additions and 10 deletions

View file

@ -61,7 +61,9 @@ public class AccountUtils {
break;
}
}
} else if (ocAccounts.length != 0) {
}
if (defaultAccount == null && ocAccounts.length != 0) {
// we at least need to take first account as fallback
defaultAccount = ocAccounts[0];
}
@ -84,11 +86,26 @@ public class AccountUtils {
}
public static void setCurrentOwnCloudAccount(Context context, String name) {
public static boolean setCurrentOwnCloudAccount(Context context, String accountName) {
boolean result = false;
if (accountName != null) {
Account[] ocAccounts = AccountManager.get(context).getAccountsByType(
AccountAuthenticator.ACCOUNT_TYPE);
boolean found = false;
for (Account account : ocAccounts) {
found = (account.name.equals(accountName));
if (found) {
SharedPreferences.Editor appPrefs = PreferenceManager
.getDefaultSharedPreferences(context).edit();
appPrefs.putString("select_oc_account", name);
appPrefs.putString("select_oc_account", accountName);
appPrefs.commit();
result = true;
break;
}
}
}
return result;
}
/**

View file

@ -143,10 +143,10 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
super.onCreate(savedInstanceState);
/// Load of parameters from received intent
mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); // no check necessary, mCurrenDir == null if the parameter is not in the intent
Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT);
if (account != null)
AccountUtils.setCurrentOwnCloudAccount(this, account.name);
if (account != null && AccountUtils.setCurrentOwnCloudAccount(this, account.name)) {
mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE);
}
/// Load of saved instance state: keep this always before initDataFromCurrentAccount()
if(savedInstanceState != null) {
@ -187,7 +187,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
// Drop-down navigation
mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
OCFile currFile = mCurrentDir;
while(currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {
while(mStorageManager != null && currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {
mDirectories.add(currFile.getFileName());
currFile = mStorageManager.getFileById(currFile.getParentId());
}