+++ /dev/null
-/* ownCloud Android client application
- * Copyright (C) 2012-2014 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,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.ui.activity;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.accounts.AuthenticatorException;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.res.Resources.NotFoundException;
-import android.os.Bundle;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentTransaction;
-import android.support.v4.widget.SwipeRefreshLayout;
-import android.support.v7.app.ActionBar;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.Toast;
-
-import com.owncloud.android.R;
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.lib.common.OwnCloudAccount;
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
-import com.owncloud.android.lib.common.OwnCloudCredentials;
-import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
-import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.operations.CreateFolderOperation;
-import com.owncloud.android.operations.RefreshFolderOperation;
-import com.owncloud.android.syncadapter.FileSyncAdapter;
-import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
-import com.owncloud.android.ui.fragment.FileFragment;
-import com.owncloud.android.ui.fragment.OCFileListFragment;
-import com.owncloud.android.utils.DisplayUtils;
-import com.owncloud.android.utils.ErrorMessageAdapter;
-
-
-public class CopyActivity extends HookActivity implements FileFragment.ContainerActivity,
- OnClickListener, SwipeRefreshLayout.OnRefreshListener {
-
- public static final String EXTRA_CURRENT_FOLDER = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CURRENT_FOLDER";
- public static final String EXTRA_TARGET_FILE = UploadFilesActivity.class.getCanonicalName() + "EXTRA_TARGET_FILE";
-
- public static final int RESULT_OK_AND_COPY = 1;
-
- private SyncBroadcastReceiver mSyncBroadcastReceiver;
-
- private static final String TAG = CopyActivity.class.getSimpleName();
-
- private static final String TAG_LIST_OF_FOLDERS = "LIST_OF_FOLDERS";
-
- private boolean mSyncInProgress = false;
-
- private Button mCancelBtn;
- private Button mChooseBtn;
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- Log_OC.d(TAG, "onCreate() start");
- requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
-
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.files_folder_picker);
-
- if (savedInstanceState == null) {
- createFragments();
- }
-
- // sets callback listeners for UI elements
- initControls();
-
- // Action bar setup
- ActionBar actionBar = getSupportActionBar();
- actionBar.setDisplayShowTitleEnabled(true);
- actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
- setSupportProgressBarIndeterminateVisibility(mSyncInProgress);
- // always AFTER setContentView(...) ; to work around bug in its implementation
-
- // sets message for empty list of folders
- setBackgroundText();
-
- Log_OC.d(TAG, "onCreate() end");
-
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId());
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- }
-
- /**
- * Called when the ownCloud {@link Account} associated to the Activity was just updated.
- */
- @Override
- protected void onAccountSet(boolean stateWasRecovered) {
- super.onAccountSet(stateWasRecovered);
- if (getAccount() != null) {
-
- updateFileFromDB();
-
- OCFile folder = getFile();
- if (folder == null || !folder.isFolder()) {
- // fall back to root folder
- setFile(getStorageManager().getFileByPath(OCFile.ROOT_PATH));
- folder = getFile();
- }
-
- if (!stateWasRecovered) {
- OCFileListFragment listOfFolders = getListOfFilesFragment();
- listOfFolders.listDirectory(folder);
-
- startSyncFolderOperation(folder, false);
- }
-
- updateNavigationElementsInActionBar();
- }
- }
-
- private void createFragments() {
- OCFileListFragment listOfFiles = new OCFileListFragment();
- Bundle args = new Bundle();
- args.putBoolean(OCFileListFragment.ARG_JUST_FOLDERS, true);
- args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, false);
- listOfFiles.setArguments(args);
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.add(R.id.fragment_container, listOfFiles, TAG_LIST_OF_FOLDERS);
- transaction.commit();
- }
-
- /**
- * Show a text message on screen view for notifying user if content is
- * loading or folder is empty
- */
- private void setBackgroundText() {
- OCFileListFragment listFragment = getListOfFilesFragment();
- if (listFragment != null) {
- int message = R.string.file_list_loading;
- if (!mSyncInProgress) {
- // In case folder list is empty
- message = R.string.file_list_empty_moving;
- }
- listFragment.setMessageForEmptyList(getString(message));
- } else {
- Log.e(TAG, "OCFileListFragment is null");
- }
- }
-
- private OCFileListFragment getListOfFilesFragment() {
- Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(CopyActivity.TAG_LIST_OF_FOLDERS);
- if (listOfFiles != null) {
- return (OCFileListFragment) listOfFiles;
- }
- Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!");
- return null;
- }
-
-
- /**
- * {@inheritDoc}
- * <p/>
- * Updates action bar and second fragment, if in dual pane mode.
- */
- @Override
- public void onBrowsedDownTo(OCFile directory) {
- setFile(directory);
- updateNavigationElementsInActionBar();
- // Sync Folder
- startSyncFolderOperation(directory, false);
-
- }
-
-
- public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) {
- long currentSyncTime = System.currentTimeMillis();
-
- mSyncInProgress = true;
-
- // perform folder synchronization
- RemoteOperation synchFolderOp = new RefreshFolderOperation(folder,
- currentSyncTime,
- false,
- getFileOperationsHelper().isSharedSupported(),
- ignoreETag,
- getStorageManager(),
- getAccount(),
- getApplicationContext()
- );
- synchFolderOp.execute(getAccount(), this, null, null);
-
- setSupportProgressBarIndeterminateVisibility(true);
-
- setBackgroundText();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- Log_OC.e(TAG, "onResume() start");
-
- // refresh list of files
- refreshListOfFilesFragment();
-
- // Listen for sync messages
- IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START);
- syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END);
- syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED);
- syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
- syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
- mSyncBroadcastReceiver = new SyncBroadcastReceiver();
- registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
-
- Log_OC.d(TAG, "onResume() end");
- }
-
- @Override
- protected void onPause() {
- Log_OC.e(TAG, "onPause() start");
- if (mSyncBroadcastReceiver != null) {
- unregisterReceiver(mSyncBroadcastReceiver);
- //LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
- mSyncBroadcastReceiver = null;
- }
-
- Log_OC.d(TAG, "onPause() end");
- super.onPause();
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.main_menu, menu);
- menu.findItem(R.id.action_upload).setVisible(false);
- menu.findItem(R.id.action_sync_account).setVisible(false);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- boolean retval = true;
- switch (item.getItemId()) {
- case R.id.action_create_dir: {
- CreateFolderDialogFragment dialog =
- CreateFolderDialogFragment.newInstance(getCurrentFolder());
- dialog.show(
- getSupportFragmentManager(),
- CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT
- );
- break;
- }
- case android.R.id.home: {
- OCFile currentDir = getCurrentFolder();
- if (currentDir != null && currentDir.getParentId() != 0) {
- onBackPressed();
- }
- break;
- }
- default:
- retval = super.onOptionsItemSelected(item);
- }
- return retval;
- }
-
- private OCFile getCurrentFolder() {
- OCFile file = getFile();
- if (file != null) {
- if (file.isFolder()) {
- return file;
- } else if (getStorageManager() != null) {
- String parentPath = file.getRemotePath().substring(0, file.getRemotePath().lastIndexOf(file.getFileName()));
- return getStorageManager().getFileByPath(parentPath);
- }
- }
- return null;
- }
-
- protected void refreshListOfFilesFragment() {
- OCFileListFragment fileListFragment = getListOfFilesFragment();
- if (fileListFragment != null) {
- fileListFragment.listDirectory();
- }
- }
-
- public void browseToRoot() {
- OCFileListFragment listOfFiles = getListOfFilesFragment();
- if (listOfFiles != null) { // should never be null, indeed
- OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
- listOfFiles.listDirectory(root);
- setFile(listOfFiles.getCurrentFile());
- updateNavigationElementsInActionBar();
- startSyncFolderOperation(root, false);
- }
- }
-
- @Override
- public void onBackPressed() {
- OCFileListFragment listOfFiles = getListOfFilesFragment();
- if (listOfFiles != null) { // should never be null, indeed
- int levelsUp = listOfFiles.onBrowseUp();
- if (levelsUp == 0) {
- finish();
- return;
- }
- setFile(listOfFiles.getCurrentFile());
- updateNavigationElementsInActionBar();
- }
- }
-
- private void updateNavigationElementsInActionBar() {
- ActionBar actionBar = getSupportActionBar();
- OCFile currentDir = getCurrentFolder();
- boolean atRoot = (currentDir == null || currentDir.getParentId() == 0);
- actionBar.setDisplayHomeAsUpEnabled(!atRoot);
- actionBar.setHomeButtonEnabled(!atRoot);
- actionBar.setTitle(
- atRoot
- ? getString(R.string.default_display_name_for_root_folder)
- : currentDir.getFileName()
- );
- }
-
- /**
- * Set per-view controllers
- */
- private void initControls() {
- mCancelBtn = (Button) findViewById(R.id.folder_picker_btn_cancel);
- mCancelBtn.setOnClickListener(this);
- mChooseBtn = (Button) findViewById(R.id.folder_picker_btn_choose);
- mChooseBtn.setOnClickListener(this);
- }
-
- @Override
- public void onClick(View v) {
- if (v == mCancelBtn) {
- finish();
- } else if (v == mChooseBtn) {
- Intent i = getIntent();
- OCFile targetFile = i.getParcelableExtra(CopyActivity.EXTRA_TARGET_FILE);
-
- Intent data = new Intent();
- data.putExtra(EXTRA_CURRENT_FOLDER, getCurrentFolder());
- data.putExtra(EXTRA_TARGET_FILE, targetFile);
- setResult(RESULT_OK_AND_COPY, data);
- finish();
- }
- }
-
-
- @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
- * to 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();
- refreshListOfFilesFragment();
- } else {
- dismissLoadingDialog();
- try {
- Toast msg = Toast.makeText(CopyActivity.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);
- }
- }
- }
-
-
- private class SyncBroadcastReceiver extends BroadcastReceiver {
-
- /**
- * {@link BroadcastReceiver} to enable syncing feedback in UI
- */
- @Override
- public void onReceive(Context context, Intent intent) {
- try {
- String event = intent.getAction();
- Log_OC.d(TAG, "Received broadcast " + event);
- String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME);
- String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);
- RemoteOperationResult synchResult = (RemoteOperationResult) intent.getSerializableExtra(FileSyncAdapter.EXTRA_RESULT);
- boolean sameAccount = (getAccount() != null && accountName.equals(getAccount().name) && getStorageManager() != null);
-
- if (sameAccount) {
-
- if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
- mSyncInProgress = true;
-
- } else {
- OCFile currentFile = (getFile() == null) ? null : getStorageManager().getFileByPath(getFile().getRemotePath());
- OCFile currentDir = (getCurrentFolder() == null) ? null : getStorageManager().getFileByPath(getCurrentFolder().getRemotePath());
-
- if (currentDir == null) {
- // current folder was removed from the server
- Toast.makeText(CopyActivity.this,
- String.format(getString(R.string.sync_current_folder_was_removed), getCurrentFolder().getFileName()),
- Toast.LENGTH_LONG)
- .show();
- browseToRoot();
-
- } else {
- if (currentFile == null && !getFile().isFolder()) {
- // currently selected file was removed in the server, and now we know it
- currentFile = currentDir;
- }
-
- if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) {
- OCFileListFragment fileListFragment = getListOfFilesFragment();
- if (fileListFragment != null) {
- fileListFragment.listDirectory(currentDir);
- }
- }
- setFile(currentFile);
- }
-
- mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
-
- if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
- equals(event) &&
- /// TODO refactor and make common
- synchResult != null && !synchResult.isSuccess() &&
- (synchResult.getCode() == ResultCode.UNAUTHORIZED ||
- synchResult.isIdPRedirection() ||
- (synchResult.isException() && synchResult.getException()
- instanceof AuthenticatorException))) {
-
- try {
- OwnCloudClient client;
- OwnCloudAccount ocAccount =
- new OwnCloudAccount(getAccount(), context);
- client = (OwnCloudClientManagerFactory.getDefaultSingleton().
- removeClientFor(ocAccount));
-
- if (client != null) {
- OwnCloudCredentials cred = client.getCredentials();
- if (cred != null) {
- AccountManager am = AccountManager.get(context);
- if (cred.authTokenExpires()) {
- am.invalidateAuthToken(
- getAccount().type,
- cred.getAuthToken()
- );
- } else {
- am.clearPassword(getAccount());
- }
- }
- }
- requestCredentialsUpdate();
-
- } catch (AccountNotFoundException e) {
- Log_OC.e(TAG, "Account " + getAccount() + " was removed!", e);
- }
-
- }
- }
- removeStickyBroadcast(intent);
- Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
- setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/);
-
- setBackgroundText();
-
- }
-
- } catch (RuntimeException e) {
- // avoid app crashes after changing the serial id of RemoteOperationResult
- // in owncloud library with broadcast notifications pending to process
- removeStickyBroadcast(intent);
- }
- }
- }
-
-
- /**
- * Shows the information of the {@link OCFile} received as a
- * parameter in the second fragment.
- *
- * @param file {@link OCFile} whose details will be shown
- */
- @Override
- public void showDetails(OCFile file) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
-
- }
-
-
- @Override
- public void onRefresh() {
- OCFileListFragment listOfFiles = getListOfFilesFragment();
- if (listOfFiles != null) {
- OCFile folder = listOfFiles.getCurrentFile();
- if (folder != null) {
- startSyncFolderOperation(folder, true);
- }
- }
- }
-
-}
*/
package com.owncloud.android.ui.fragment;
-import java.io.File;
-
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.CopyActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.FolderPickerActivity;
import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
import com.owncloud.android.ui.preview.PreviewMediaFragment;
import com.owncloud.android.utils.FileStorageUtils;
+import java.io.File;
+import java.util.Vector;
+
/**
* A Fragment that lists all files and folders in a given path.
- *
+ *
* TODO refactor to get rid of direct dependency on FileDisplayActivity
*/
public class OCFileListFragment extends ExtendedListFragment {
-
+
private static final String TAG = OCFileListFragment.class.getSimpleName();
private static final String MY_PACKAGE = OCFileListFragment.class.getPackage() != null ?
OCFileListFragment.class.getPackage().getName() : "com.owncloud.android.ui.fragment";
-
+
public final static String ARG_JUST_FOLDERS = MY_PACKAGE + ".JUST_FOLDERS";
public final static String ARG_ALLOW_CONTEXTUAL_ACTIONS = MY_PACKAGE + ".ALLOW_CONTEXTUAL";
-
+
private static final String KEY_FILE = MY_PACKAGE + ".extra.FILE";
private FileFragment.ContainerActivity mContainerActivity;
-
+
private OCFile mFile = null;
private FileListListAdapter mAdapter;
private boolean mJustFolders;
Log_OC.e(TAG, "onAttach");
try {
mContainerActivity = (FileFragment.ContainerActivity) activity;
-
+
} catch (ClassCastException e) {
- throw new ClassCastException(activity.toString() + " must implement " +
+ throw new ClassCastException(activity.toString() + " must implement " +
FileFragment.ContainerActivity.class.getSimpleName());
}
try {
setOnRefreshListener((OnEnforceableRefreshListener) activity);
} catch (ClassCastException e) {
- throw new ClassCastException(activity.toString() + " must implement " +
+ throw new ClassCastException(activity.toString() + " must implement " +
SwipeRefreshLayout.OnRefreshListener.class.getSimpleName());
}
}
-
+
@Override
public void onDetach() {
setOnRefreshListener(null);
mJustFolders,
getActivity(),
mContainerActivity
- );
+ );
setListAdapter(mAdapter);
registerForContextMenu();
* Saves the current listed folder.
*/
@Override
- public void onSaveInstanceState (Bundle outState) {
+ public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(KEY_FILE, mFile);
}
-
+
/**
* Call this, when the user presses the up button.
- *
- * Tries to move up the current folder one level. If the parent folder was removed from the
+ * <p/>
+ * Tries to move up the current folder one level. If the parent folder was removed from the
* database, it continues browsing up until finding an existing folders.
- *
+ * <p/>
* return Count of folder levels browsed up.
*/
public int onBrowseUp() {
OCFile parentDir = null;
int moveCount = 0;
-
- if(mFile != null){
+
+ if (mFile != null) {
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
-
+
String parentPath = null;
if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
parentPath = new File(mFile.getRemotePath()).getParent();
- parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :
- parentPath + OCFile.PATH_SEPARATOR;
+ parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :
+ parentPath + OCFile.PATH_SEPARATOR;
parentDir = storageManager.getFileByPath(parentPath);
moveCount++;
} else {
}
while (parentDir == null) {
parentPath = new File(parentPath).getParent();
- parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :
- parentPath + OCFile.PATH_SEPARATOR;
+ parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :
+ parentPath + OCFile.PATH_SEPARATOR;
parentDir = storageManager.getFileByPath(parentPath);
moveCount++;
} // exit is granted because storageManager.getFileByPath("/") never returns null
listDirectory(mFile /*, MainApp.getOnlyOnDevice()*/);
onRefresh(false);
-
+
// restore index and top position
restoreIndexAndTopPosition();
-
+
} // else - should never happen now
-
+
return moveCount;
}
-
+
@Override
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
OCFile file = (OCFile) mAdapter.getItem(position);
if (file != null) {
- if (file.isFolder()) {
+ if (file.isFolder()) {
// update state and view of this fragment
// TODO Enable when "On Device" is recovered ?
listDirectory(file/*, MainApp.getOnlyOnDevice()*/);
mContainerActivity.onBrowsedDownTo(file);
// save index and top position
saveIndexAndTopPosition(position);
-
+
} else { /// Click on a file
if (PreviewImageFragment.canBePreviewed(file)) {
// preview image - it handles the download, if needed
- ((FileDisplayActivity)mContainerActivity).startImagePreview(file);
-
+ ((FileDisplayActivity) mContainerActivity).startImagePreview(file);
+
} else if (file.isDown()) {
if (PreviewMediaFragment.canBePreviewed(file)) {
// media preview
- ((FileDisplayActivity)mContainerActivity).startMediaPreview(file, 0, true);
+ ((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true);
} else {
mContainerActivity.getFileOperationsHelper().openFile(file);
}
-
+
} else {
// automatic download, preview on finish
- ((FileDisplayActivity)mContainerActivity).startDownloadForPreview(file);
+ ((FileDisplayActivity) mContainerActivity).startDownloadForPreview(file);
}
-
+
}
-
+
} else {
Log_OC.d(TAG, "Null object in ListAdapter!!");
}
-
+
}
-
+
/**
* {@inheritDoc}
*/
@Override
- public void onCreateContextMenu (
+ public void onCreateContextMenu(
ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
Bundle args = getArguments();
- boolean allowContextualActions =
- (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
+ boolean allowContextualActions =
+ (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
if (allowContextualActions) {
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.file_actions_menu, menu);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
OCFile targetFile = (OCFile) mAdapter.getItem(info.position);
-
+
if (mContainerActivity.getStorageManager() != null) {
FileMenuFilter mf = new FileMenuFilter(
targetFile,
}
}
}
-
-
+
+
/**
* {@inhericDoc}
*/
@Override
- public boolean onContextItemSelected (MenuItem item) {
- AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
+ public boolean onContextItemSelected(MenuItem item) {
+ AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
mTargetFile = (OCFile) mAdapter.getItem(info.position);
- switch (item.getItemId()) {
+ switch (item.getItemId()) {
case R.id.action_share_file: {
mContainerActivity.getFileOperationsHelper().shareFileWithLink(mTargetFile);
return true;
dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION);
return true;
}
- case R.id.action_download_file:
+ case R.id.action_download_file:
case R.id.action_sync_file: {
mContainerActivity.getFileOperationsHelper().syncFile(mTargetFile);
return true;
}
case R.id.action_cancel_download:
case R.id.action_cancel_upload: {
- ((FileDisplayActivity)mContainerActivity).cancelTransference(mTargetFile);
+ ((FileDisplayActivity) mContainerActivity).cancelTransference(mTargetFile);
return true;
}
case R.id.action_see_details: {
// Obtain the file
if (!mTargetFile.isDown()) { // Download the file
Log_OC.d(TAG, mTargetFile.getRemotePath() + " : File must be downloaded");
- ((FileDisplayActivity)mContainerActivity).startDownloadForSending(mTargetFile);
-
+ ((FileDisplayActivity) mContainerActivity).startDownloadForSending(mTargetFile);
+
} else {
mContainerActivity.getFileOperationsHelper().sendDownloadedFile(mTargetFile);
}
return true;
}
case R.id.action_copy:
- Intent action = new Intent(getActivity(), CopyActivity.class);
+ Intent action = new Intent(getActivity(), FolderPickerActivity.class);
// Pass mTargetFile that contains info of selected file/folder
- action.putExtra(CopyActivity.EXTRA_TARGET_FILE, mTargetFile);
+ action.putExtra(FolderPickerActivity.EXTRA_FILE, mTargetFile);
getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_COPY_FILES);
return true;
default:
- return super.onContextItemSelected(item);
+ return super.onContextItemSelected(item);
}
}
/**
* Use this to query the {@link OCFile} that is currently
* being displayed by this fragment
+ *
* @return The currently viewed OCFile
*/
- public OCFile getCurrentFile(){
+ public OCFile getCurrentFile() {
return mFile;
}
-
+
/**
* Calls {@link OCFileListFragment#listDirectory(OCFile)} with a null parameter
*/
// TODO Enable when "On Device" is recovered ?
listDirectory(getCurrentFile()/*, MainApp.getOnlyOnDevice()*/);
}
-
+
/**
* Lists the given directory on the view. When the input parameter is null,
* it will either refresh the last known directory. list the root
* if there never was a directory.
- *
+ *
* @param directory File to be listed
*/
public void listDirectory(OCFile directory/*, boolean onlyOnDevice*/) {
if (storageManager != null) {
// Check input parameters for null
- if(directory == null){
- if(mFile != null){
+ if (directory == null) {
+ if (mFile != null) {
directory = mFile;
} else {
directory = storageManager.getFileByPath("/");
if (directory == null) return; // no files, wait for sync
}
}
-
-
+
+
// If that's not a directory -> List its parent
- if(!directory.isFolder()){
+ if (!directory.isFolder()) {
Log_OC.w(TAG, "You see, that is not a directory -> " + directory.toString());
directory = storageManager.getFileById(directory.getParentId());
}