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=-c Merge remote-tracking branch 'upstream/develop' into uploadNewFolder Conflicts: src/com/owncloud/android/ui/activity/Uploader.java --- d54345d0403a4ea2214b793b24ba0e821ea1339c diff --combined res/values/strings.xml index 849ce5f4,27751d14..9772edff --- a/res/values/strings.xml +++ b/res/values/strings.xml @@@ -39,7 -39,9 +39,9 @@@ Recommend to a friend Feedback Imprint - + Remember share location + Remember last share upload location + "Try %1$s on your smartphone!" "I want to invite you to use %1$s on your smartphone!\nDownload here: %2$s" @@@ -51,7 -53,6 +53,7 @@@ Files Connect Upload + New folder Choose upload folder: No account found There are no %1$s accounts on your device. Please setup an account first. @@@ -61,9 -62,14 +63,14 @@@ No content was received. Nothing to upload. %1$s is not allowed to access the shared content Uploading + seconds ago Nothing in here. Upload something! Loading... There are no files in this folder. + folder + folders + file + files Tap on a file to display additional information. Size: Type: @@@ -280,6 -286,7 +287,7 @@@ An error occurred while waiting for the server, the operation couldn\'t have been done An error occurred while waiting for the server, the operation couldn\'t have been done The operation couldn\'t be completed, server is unavailable + You do not have permission %s @@@ -297,14 -304,15 +305,15 @@@ Logs Send History - ownCloud Android app logs - Loading data... + No app for sending logs found. Install mail app! + %1$s Android app logs + Loading data… Authentication required Wrong password Move Nothing in here. You can add a folder! - Choose + Choose Unable to move. Please check whether the file exists It is not possible to move a folder into a descendant @@@ -315,4 -323,10 +324,10 @@@ Instant Uploads Security + Upload Video Path + + shared + with you + %1$s %2$s >>%3$s<< %4$s + diff --combined 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 @@@ -26,6 -26,14 +26,6 @@@ import java.util.List import java.util.Stack; import java.util.Vector; -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.utils.Log_OC; - import android.accounts.Account; import android.accounts.AccountManager; import android.app.AlertDialog; @@@ -37,37 -45,27 +37,41 @@@ 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; import android.os.Parcelable; + import android.preference.PreferenceManager; import android.provider.MediaStore.Audio; import android.provider.MediaStore.Images; import android.provider.MediaStore.Video; import android.view.View; - import android.view.Window; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Button; import android.widget.EditText; +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. @@@ -75,7 -73,7 +79,7 @@@ * @author Bartek Przybylski * */ -public class Uploader extends SherlockListActivity implements OnItemClickListener, android.view.View.OnClickListener { +public class Uploader extends FileActivity implements OnItemClickListener, android.view.View.OnClickListener { private static final String TAG = "ownCloudUploader"; private Account mAccount; @@@ -86,7 -84,7 +90,7 @@@ private String mUploadPath; private FileDataStorageManager mStorageManager; private OCFile mFile; - + private final static int DIALOG_NO_ACCOUNT = 0; private final static int DIALOG_WAITING = 1; private final static int DIALOG_NO_STREAM = 2; @@@ -97,9 -95,11 +101,11 @@@ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - getWindow().requestFeature(Window.FEATURE_NO_TITLE); mParents = new Stack(); - mParents.add(""); + + ActionBar actionBar = getSupportActionBar(); + actionBar.setIcon(DisplayUtils.getSeasonalIconId()); + if (prepareStreamsToUpload()) { mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType()); @@@ -112,8 -112,11 +118,11 @@@ } else { mAccount = accounts[0]; mStorageManager = new FileDataStorageManager(mAccount, getContentResolver()); + initTargetFolder(); populateDirectoryList(); + } + } else { showDialog(DIALOG_NO_STREAM); } @@@ -167,7 -170,7 +176,7 @@@ 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() { @@@ -175,6 -178,7 +184,7 @@@ public void onClick(DialogInterface dialog, int which) { mAccount = mAccountManager.getAccountsByType(MainApp.getAccountType())[which]; mStorageManager = new FileDataStorageManager(mAccount, getContentResolver()); + initTargetFolder(); populateDirectoryList(); } }); @@@ -264,13 -268,6 +274,13 @@@ uploadFiles(); break; + + case R.id.uploader_new_folder: + CreateFolderDialogFragment dialog = CreateFolderDialogFragment.newInstance(mFile); + dialog.show(getSupportFragmentManager(), "createdirdialog"); + break; + + default: throw new IllegalArgumentException("Wrong element clicked"); } @@@ -300,15 -297,23 +310,25 @@@ 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); @@@ -325,18 -330,21 +345,26 @@@ R.layout.uploader_list_item_layout, new String[] {"dirname"}, new int[] {R.id.textView1}); - setListAdapter(sa); - Button btn = (Button) findViewById(R.id.uploader_choose_folder); - btn.setOnClickListener(this); - getListView().setOnItemClickListener(this); + + mListView.setAdapter(sa); + Button btnChooseFolder = (Button) findViewById(R.id.uploader_choose_folder); + btnChooseFolder.setOnClickListener(this); + + Button btnNewFolder = (Button) findViewById(R.id.uploader_new_folder); + btnNewFolder.setOnClickListener(this); + + mListView.setOnItemClickListener(this); } } + 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(); @@@ -428,6 -436,13 +456,13 @@@ intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote.toArray(new String[remote.size()])); intent.putExtra(FileUploader.KEY_ACCOUNT, mAccount); startService(intent); + + //Save the path to shared preferences + SharedPreferences.Editor appPrefs = PreferenceManager + .getDefaultSharedPreferences(getApplicationContext()).edit(); + appPrefs.putString("last_upload_path", mUploadPath); + appPrefs.apply(); + finish(); } @@@ -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; + } + + }