Added check for that the last upload folder still exists

This commit is contained in:
Magnus Sjoqvist 2014-10-14 11:21:50 +02:00
parent 4275f02cab
commit 89627024b1

View file

@ -116,10 +116,25 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene
ActionBar actionBar = getSherlock().getActionBar();
actionBar.setIcon(DisplayUtils.getSeasonalIconId());
if (prepareStreamsToUpload()) {
mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType());
if (accounts.length == 0) {
Log_OC.i(TAG, "No ownCloud account is available");
showDialog(DIALOG_NO_ACCOUNT);
} else if (accounts.length > 1) {
Log_OC.i(TAG, "More then one ownCloud is available");
showDialog(DIALOG_MULTIPLE_ACCOUNT);
} else {
mAccount = accounts[0];
mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
SharedPreferences appPreferences = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
mSaveUploadLocation = appPreferences.getBoolean("save_last_upload_location", false);
//If the users has enabled last upload path saving then populate mParents with the previous path
if(mSaveUploadLocation)
{
@ -133,23 +148,15 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene
for (String dir : dir_names)
mParents.add(dir);
}
//Make sure that path still exists, if it doesn't pop the stack and try the previous path
while(!mStorageManager.fileExists(generatePath(mParents))){
mParents.pop();
}
}
else {
mParents.add("");
}
if (prepareStreamsToUpload()) {
mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType());
if (accounts.length == 0) {
Log_OC.i(TAG, "No ownCloud account is available");
showDialog(DIALOG_NO_ACCOUNT);
} else if (accounts.length > 1) {
Log_OC.i(TAG, "More then one ownCloud is available");
showDialog(DIALOG_MULTIPLE_ACCOUNT);
} else {
mAccount = accounts[0];
mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
populateDirectoryList();
}
} else {
@ -340,10 +347,7 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene
getActionBar().setTitle(current_dir);
}
String full_path = "";
for (String a : mParents)
full_path += a + "/";
String full_path = generatePath(mParents);
Log_OC.d(TAG, "Populating view with content of : " + full_path);
@ -370,6 +374,14 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene
}
}
private String generatePath(Stack<String> dirs) {
String full_path = "";
for (String a : dirs)
full_path += a + "/";
return full_path;
}
private boolean prepareStreamsToUpload() {
if (getIntent().getAction().equals(Intent.ACTION_SEND)) {
mStreamsToUpload = new ArrayList<Parcelable>();