X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/ccdf0f1b96033524e1dc71876ced8c8172d6315a..876204faf03075e286cf550b3bfba86d3f5a1419:/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 35f769a1..8a01972a 100644 --- a/src/com/owncloud/android/ui/activity/Uploader.java +++ b/src/com/owncloud/android/ui/activity/Uploader.java @@ -1,6 +1,9 @@ -/* ownCloud Android client application +/** + * ownCloud Android client application + * + * @author Bartek Przybylski * Copyright (C) 2012 Bartek Przybylski - * Copyright (C) 2012-2013 ownCloud Inc. + * Copyright (C) 2015 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -36,17 +39,18 @@ import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnClickListener; -import android.content.res.Resources.NotFoundException; 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; @@ -55,6 +59,8 @@ import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.view.MenuItem; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountAuthenticator; @@ -65,21 +71,13 @@ 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.operations.CreateShareOperation; -import com.owncloud.android.operations.MoveFileOperation; -import com.owncloud.android.operations.RemoveFileOperation; -import com.owncloud.android.operations.RenameFileOperation; -import com.owncloud.android.operations.SynchronizeFileOperation; -import com.owncloud.android.operations.UnshareLinkOperation; 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. - * - * @author Bartek Przybylski - * */ public class Uploader extends FileActivity implements OnItemClickListener, android.view.View.OnClickListener { private static final String TAG = "ownCloudUploader"; @@ -103,9 +101,11 @@ public class Uploader extends FileActivity implements OnItemClickListener, andro @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()); @@ -118,8 +118,11 @@ public class Uploader extends FileActivity implements OnItemClickListener, andro } else { mAccount = accounts[0]; mStorageManager = new FileDataStorageManager(mAccount, getContentResolver()); + initTargetFolder(); populateDirectoryList(); + } + } else { showDialog(DIALOG_NO_STREAM); } @@ -173,7 +176,7 @@ public class Uploader extends FileActivity implements OnItemClickListener, andro 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() { @@ -181,6 +184,7 @@ public class Uploader extends FileActivity implements OnItemClickListener, andro public void onClick(DialogInterface dialog, int which) { mAccount = mAccountManager.getAccountsByType(MainApp.getAccountType())[which]; mStorageManager = new FileDataStorageManager(mAccount, getContentResolver()); + initTargetFolder(); populateDirectoryList(); } }); @@ -309,12 +313,22 @@ public class Uploader extends FileActivity implements OnItemClickListener, andro 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); @@ -343,6 +357,14 @@ public class Uploader extends FileActivity implements OnItemClickListener, andro } } + 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(); @@ -434,6 +456,13 @@ public class Uploader extends FileActivity implements OnItemClickListener, andro 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(); } @@ -477,4 +506,53 @@ public class Uploader extends FileActivity implements OnItemClickListener, andro } } } + + + /** + * 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; + } + + }