/* ownCloud Android client application\r
* Copyright (C) 2011 Bartek Przybylski\r
+ * Copyright (C) 2012-2013 ownCloud Inc.\r
*\r
* This program is free software: you can redistribute it and/or modify\r
* it under the terms of the GNU General Public License as published by\r
import com.owncloud.android.operations.RemoteOperationResult.ResultCode;\r
import com.owncloud.android.syncadapter.FileSyncService;\r
import com.owncloud.android.ui.dialog.ChangelogDialog;\r
+import com.owncloud.android.ui.dialog.EditNameDialog;\r
import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
+import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;\r
import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
import com.owncloud.android.ui.fragment.FileDetailFragment;\r
import com.owncloud.android.ui.fragment.FileFragment;\r
*/\r
\r
public class FileDisplayActivity extends SherlockFragmentActivity implements\r
- OCFileListFragment.ContainerActivity, FileFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener {\r
+ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener, EditNameDialogListener {\r
\r
private ArrayAdapter<String> mDirectories;\r
private OCFile mCurrentDir = null;\r
private OCFileListFragment mFileList;\r
\r
private boolean mDualPane;\r
+ private boolean mBackFromCreatingFirstAccount;\r
\r
private static final int DIALOG_SETUP_ACCOUNT = 0;\r
private static final int DIALOG_CREATE_DIR = 1;\r
super.onCreate(savedInstanceState);\r
\r
/// Load of parameters from received intent\r
- mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); // no check necessary, mCurrenDir == null if the parameter is not in the intent\r
Account account = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_ACCOUNT);\r
- if (account != null)\r
- AccountUtils.setCurrentOwnCloudAccount(this, account.name);\r
+ if (account != null && AccountUtils.setCurrentOwnCloudAccount(this, account.name)) {\r
+ mCurrentDir = getIntent().getParcelableExtra(FileDetailFragment.EXTRA_FILE); \r
+ }\r
\r
/// Load of saved instance state: keep this always before initDataFromCurrentAccount()\r
if(savedInstanceState != null) {\r
// Drop-down navigation \r
mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);\r
OCFile currFile = mCurrentDir;\r
- while(currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {\r
+ while(mStorageManager != null && currFile != null && currFile.getFileName() != OCFile.PATH_SEPARATOR) {\r
mDirectories.add(currFile.getFileName());\r
currFile = mStorageManager.getFileById(currFile.getParentId());\r
}\r
\r
\r
// show changelog, if needed\r
- showChangeLog();\r
+ //showChangeLog();\r
+ mBackFromCreatingFirstAccount = false;\r
\r
Log.d(getClass().toString(), "onCreate() end");\r
}\r
boolean retval = true;\r
switch (item.getItemId()) {\r
case R.id.action_create_dir: {\r
- showDialog(DIALOG_CREATE_DIR);\r
+ EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.uploader_info_dirname), "", this);\r
+ dialog.show(getSupportFragmentManager(), "createdirdialog");\r
break;\r
}\r
case R.id.action_sync_account: {\r
if (mDualPane) {\r
initFileDetailsInDualPane();\r
}\r
+ mBackFromCreatingFirstAccount = true;\r
}\r
\r
// Listen for sync messages\r
break;\r
}\r
case DIALOG_CHOOSE_UPLOAD_SOURCE: {\r
- final String [] items = { getString(R.string.actionbar_upload_files), \r
- getString(R.string.actionbar_upload_from_apps) }; \r
+ \r
+ String[] items = null;\r
+ \r
+ String[] allTheItems = { getString(R.string.actionbar_upload_files),\r
+ getString(R.string.actionbar_upload_from_apps),\r
+ getString(R.string.actionbar_failed_instant_upload) };\r
+ \r
+ String[] commonItems = { getString(R.string.actionbar_upload_files),\r
+ getString(R.string.actionbar_upload_from_apps) };\r
+ \r
+ if (InstantUploadActivity.IS_ENABLED)\r
+ items = allTheItems;\r
+ else \r
+ items = commonItems;\r
+ \r
builder = new AlertDialog.Builder(this);\r
builder.setTitle(R.string.actionbar_upload);\r
builder.setItems(items, new DialogInterface.OnClickListener() {\r
public void onClick(DialogInterface dialog, int item) {\r
if (item == 0) {\r
- //if (!mDualPane) { \r
- Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);\r
- action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this));\r
- startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);\r
- //} else {\r
- // TODO create and handle new fragment LocalFileListFragment\r
- //}\r
+ // if (!mDualPane) {\r
+ Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);\r
+ action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT,\r
+ AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this));\r
+ startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);\r
+ // } else {\r
+ // TODO create and handle new fragment\r
+ // LocalFileListFragment\r
+ // }\r
} else if (item == 1) {\r
Intent action = new Intent(Intent.ACTION_GET_CONTENT);\r
- action = action.setType("*/*")\r
- .addCategory(Intent.CATEGORY_OPENABLE);\r
- startActivityForResult(\r
- Intent.createChooser(action, getString(R.string.upload_chooser_title)),\r
+ action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);\r
+ startActivityForResult(Intent.createChooser(action, getString(R.string.upload_chooser_title)),\r
ACTION_SELECT_CONTENT_FROM_APPS);\r
+ } else if (item == 2 && InstantUploadActivity.IS_ENABLED) {\r
+ Account account = AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this);\r
+ Intent action = new Intent(FileDisplayActivity.this, InstantUploadActivity.class);\r
+ action.putExtra(FileUploader.KEY_ACCOUNT, account);\r
+ startActivity(action);\r
}\r
}\r
});\r
}\r
\r
setSupportProgressBarIndeterminateVisibility(inProgress);\r
+ if (mBackFromCreatingFirstAccount) {\r
+ // awful patch to fix problem with visibility of progress circle with the first refresh of the first account\r
+ // TODO - kill this Activity when the first account has to be created instead of stack the account creation on it\r
+ getSupportActionBar().hide();\r
+ getSupportActionBar().show();\r
+ mBackFromCreatingFirstAccount = false;\r
+ }\r
removeStickyBroadcast(intent);\r
\r
}\r
}\r
}\r
\r
+ public void onDismiss(EditNameDialog dialog) {\r
+ //dialog.dismiss();\r
+ if (dialog.getResult()) {\r
+ String newDirectoryName = dialog.getNewFilename().trim();\r
+ Log.d(TAG, "'create directory' dialog dismissed with new name " + newDirectoryName);\r
+ if (newDirectoryName.length() > 0) {\r
+ String path;\r
+ if (mCurrentDir == null) {\r
+ // this is just a patch; we should ensure that mCurrentDir never is null\r
+ if (!mStorageManager.fileExists(OCFile.PATH_SEPARATOR)) {\r
+ OCFile file = new OCFile(OCFile.PATH_SEPARATOR);\r
+ mStorageManager.saveFile(file);\r
+ }\r
+ mCurrentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);\r
+ }\r
+ path = FileDisplayActivity.this.mCurrentDir.getRemotePath();\r
+ \r
+ // Create directory\r
+ path += newDirectoryName + OCFile.PATH_SEPARATOR;\r
+ Thread thread = new Thread(new DirectoryCreator(path, AccountUtils.getCurrentOwnCloudAccount(FileDisplayActivity.this), new Handler()));\r
+ thread.start();\r
+ \r
+ showDialog(DIALOG_SHORT_WAIT);\r
+ }\r
+ }\r
+ }\r
\r
private void requestForDownload() {\r
Account account = AccountUtils.getCurrentOwnCloudAccount(this);\r
\r
\r
}\r
+