X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/4275f02cab7b82a9b1488dd8324ce1b805c5bf56..e901b609baa4dd5f681e2a5257c9e504997e3377:/src/com/owncloud/android/ui/activity/Uploader.java diff --git a/src/com/owncloud/android/ui/activity/Uploader.java b/src/com/owncloud/android/ui/activity/Uploader.java index 238b85c2..6c8a1320 100644 --- a/src/com/owncloud/android/ui/activity/Uploader.java +++ b/src/com/owncloud/android/ui/activity/Uploader.java @@ -32,7 +32,7 @@ import com.owncloud.android.authentication.AccountAuthenticator; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileUploader; -import com.owncloud.android.utils.Log_OC; +import com.owncloud.android.lib.common.utils.Log_OC; import android.accounts.Account; import android.accounts.AccountManager; @@ -64,23 +64,8 @@ import android.widget.Toast; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockListActivity; -import com.owncloud.android.MainApp; -import com.owncloud.android.R; -import com.owncloud.android.authentication.AccountAuthenticator; -import com.owncloud.android.datamodel.FileDataStorageManager; -import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.files.services.FileUploader; +import com.actionbarsherlock.view.MenuItem; import com.owncloud.android.utils.DisplayUtils; -import com.owncloud.android.utils.Log_OC; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Stack; -import java.util.Vector; - /** * This can be used to upload things to an ownCloud instance. @@ -99,7 +84,6 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene private String mUploadPath; private FileDataStorageManager mStorageManager; private OCFile mFile; - private boolean mSaveUploadLocation; private final static int DIALOG_NO_ACCOUNT = 0; private final static int DIALOG_WAITING = 1; @@ -113,31 +97,9 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene super.onCreate(savedInstanceState); mParents = new Stack(); - ActionBar actionBar = getSherlock().getActionBar(); + ActionBar actionBar = getSupportActionBar(); actionBar.setIcon(DisplayUtils.getSeasonalIconId()); - 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) - { - String last_path = appPreferences.getString("last_upload_path", ""); - // "/" equals root-directory - if(last_path.equals("/")) { - mParents.add(""); - } - else{ - String[] dir_names = last_path.split("/"); - for (String dir : dir_names) - mParents.add(dir); - } - } - else { - mParents.add(""); - } - if (prepareStreamsToUpload()) { mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType()); @@ -150,8 +112,11 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene } else { mAccount = accounts[0]; mStorageManager = new FileDataStorageManager(mAccount, getContentResolver()); + initTargetFolder(); populateDirectoryList(); + } + } else { showDialog(DIALOG_NO_STREAM); } @@ -205,7 +170,7 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene case DIALOG_MULTIPLE_ACCOUNT: CharSequence ac[] = new CharSequence[mAccountManager.getAccountsByType(MainApp.getAccountType()).length]; for (int i = 0; i < ac.length; ++i) { - ac[i] = mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name; + ac[i] = DisplayUtils.convertIdn(mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name, false); } builder.setTitle(R.string.common_choose_account); builder.setItems(ac, new OnClickListener() { @@ -213,6 +178,7 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene public void onClick(DialogInterface dialog, int which) { mAccount = mAccountManager.getAccountsByType(MainApp.getAccountType())[which]; mStorageManager = new FileDataStorageManager(mAccount, getContentResolver()); + initTargetFolder(); populateDirectoryList(); } }); @@ -334,19 +300,20 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene String current_dir = mParents.peek(); if(current_dir.equals("")){ - getActionBar().setTitle(getString(R.string.default_display_name_for_root_folder)); + getSupportActionBar().setTitle(getString(R.string.default_display_name_for_root_folder)); } else{ - getActionBar().setTitle(current_dir); + getSupportActionBar().setTitle(current_dir); } + boolean notRoot = (mParents.size() > 1); + ActionBar actionBar = getSupportActionBar(); + actionBar.setDisplayHomeAsUpEnabled(notRoot); + actionBar.setHomeButtonEnabled(notRoot); - 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); - + mFile = mStorageManager.getFileByPath(full_path); if (mFile != null) { Vector files = mStorageManager.getFolderContent(mFile); @@ -370,6 +337,14 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene } } + private String generatePath(Stack 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(); @@ -462,13 +437,11 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene intent.putExtra(FileUploader.KEY_ACCOUNT, mAccount); startService(intent); - //If the user has enabled last upload path then save the path to shared preferences - if(mSaveUploadLocation){ - SharedPreferences.Editor appPrefs = PreferenceManager - .getDefaultSharedPreferences(getApplicationContext()).edit(); - appPrefs.putString("last_upload_path", mUploadPath); - appPrefs.apply(); - } + //Save the path to shared preferences + SharedPreferences.Editor appPrefs = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()).edit(); + appPrefs.putString("last_upload_path", mUploadPath); + appPrefs.apply(); finish(); } @@ -478,5 +451,52 @@ public class Uploader extends SherlockListActivity implements OnItemClickListene Toast.makeText(this, message, Toast.LENGTH_LONG).show(); } } + + /** + * Loads the target folder initialize shown to the user. + * + * The target account has to be chosen before this method is called. + */ + private void initTargetFolder() { + if (mStorageManager == null) { + throw new IllegalStateException("Do not call this method before initializing mStorageManager"); + } + + SharedPreferences appPreferences = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()); + String last_path = appPreferences.getString("last_upload_path", ""); + // "/" equals root-directory + if(last_path.equals("/")) { + mParents.add(""); + } + else{ + String[] dir_names = last_path.split("/"); + 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.size() > 1){ + mParents.pop(); + } + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + boolean retval = true; + switch (item.getItemId()) { + case android.R.id.home: { + if((mParents.size() > 1)) { + onBackPressed(); + } + break; + } + default: + retval = super.onOptionsItemSelected(item); + } + return retval; + } + + }