From: tobiasKaminsky Date: Thu, 8 Jan 2015 21:41:41 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/develop' into uploadNewFolder X-Git-Tag: oc-android-1.7.1_signed^2~9^2~10^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/d54345d0403a4ea2214b793b24ba0e821ea1339c?hp=--cc Merge remote-tracking branch 'upstream/develop' into uploadNewFolder Conflicts: src/com/owncloud/android/ui/activity/Uploader.java --- d54345d0403a4ea2214b793b24ba0e821ea1339c diff --cc src/com/owncloud/android/ui/activity/Uploader.java index 9ccdc63b,6c8a1320..6efd6b4c --- a/src/com/owncloud/android/ui/activity/Uploader.java +++ b/src/com/owncloud/android/ui/activity/Uploader.java @@@ -37,7 -45,7 +37,8 @@@ import android.content.DialogInterface import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnClickListener; import android.content.Intent; + import android.content.SharedPreferences; +import android.content.res.Resources.NotFoundException; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; @@@ -55,19 -62,10 +56,22 @@@ import android.widget.ListView import android.widget.SimpleAdapter; import android.widget.Toast; + import com.actionbarsherlock.app.ActionBar; -import com.actionbarsherlock.app.SherlockListActivity; + import com.actionbarsherlock.view.MenuItem; +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.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.operations.CreateFolderOperation; +import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; + import com.owncloud.android.utils.DisplayUtils; +import com.owncloud.android.utils.ErrorMessageAdapter; + /** * This can be used to upload things to an ownCloud instance. @@@ -300,15 -297,23 +310,25 @@@ public class Uploader extends FileActiv private void populateDirectoryList() { setContentView(R.layout.uploader_layout); + + ListView mListView = (ListView) findViewById(android.R.id.list); - String full_path = ""; - for (String a : mParents) - full_path += a + "/"; + String current_dir = mParents.peek(); + if(current_dir.equals("")){ + getSupportActionBar().setTitle(getString(R.string.default_display_name_for_root_folder)); + } + else{ + getSupportActionBar().setTitle(current_dir); + } + boolean notRoot = (mParents.size() > 1); + ActionBar actionBar = getSupportActionBar(); + actionBar.setDisplayHomeAsUpEnabled(notRoot); + actionBar.setHomeButtonEnabled(notRoot); + + 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); @@@ -437,38 -452,51 +472,87 @@@ } } + @Override + public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { + super.onRemoteOperationFinish(operation, result); + + + if (operation instanceof CreateFolderOperation) { + onCreateFolderOperationFinish((CreateFolderOperation)operation, result); + } + + } + + /** + * Updates the view associated to the activity after the finish of an operation trying create a new folder + * + * @param operation Creation operation performed. + * @param result Result of the creation. + */ + private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) { + if (result.isSuccess()) { + dismissLoadingDialog(); + populateDirectoryList(); + } else { + dismissLoadingDialog(); + try { + Toast msg = Toast.makeText(this, + ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); + msg.show(); + + } catch (NotFoundException e) { + Log_OC.e(TAG, "Error while trying to show fail message " , e); + } + } + } ++ ++ + /** + * 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; + } + + }