OCFile removedFile = operation.getFile();
FileFragment second = getSecondFragment();
if (second != null && removedFile.equals(second.getFile())) {
+ if (second instanceof PreviewMediaFragment) {
+ ((PreviewMediaFragment)second).stopPreview(true);
+ }
cleanSecondFragment();
}
if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())) {
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012 Bartek Przybylski
+ * Copyright (C) 2012-2013 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.dialog;
+
+/**
+ * Dialog requiring confirmation before removing a given OCFile.
+ *
+ * Triggers the removal according to the user response.
+ */
+import com.owncloud.android.R;
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.ui.activity.ComponentsGetter;
+import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
+
+import android.app.Dialog;
+import android.os.Bundle;
+
+public class RemoveFileDialogFragment extends ConfirmationDialogFragment
+implements ConfirmationDialogFragmentListener {
+
+ private static final String ARG_TARGET_FILE = "TARGET_FILE";
+
+ /**
+ * Public factory method to create new RemoveFIleDialogFragment instances.
+ *
+ * @param string_id Resource id for a message to show in the dialog.
+ * @param arguments Arguments to complete the message, if it's a format string.
+ * @param posBtn Resource id for the text of the positive button.
+ * @param neuBtn Resource id for the text of the neutral button.
+ * @param negBtn Resource id for the text of the negative button.
+ * @return Dialog ready to show.
+ */
+ public static RemoveFileDialogFragment newInstance(OCFile file) {
+ RemoveFileDialogFragment frag = new RemoveFileDialogFragment();
+ Bundle args = new Bundle();
+
+ int messageStringId = R.string.confirmation_remove_alert;
+
+ int posBtn = R.string.confirmation_remove_remote;
+ int neuBtn = -1;
+ if (file.isFolder()) {
+ messageStringId = R.string.confirmation_remove_folder_alert;
+ posBtn = R.string.confirmation_remove_remote_and_local;
+ neuBtn = R.string.confirmation_remove_folder_local;
+ } else if (file.isDown()) {
+ posBtn = R.string.confirmation_remove_remote_and_local;
+ neuBtn = R.string.confirmation_remove_local;
+ }
+
+
+ args.putInt(ARG_CONF_RESOURCE_ID, messageStringId);
+ args.putStringArray(ARG_CONF_ARGUMENTS, new String[]{file.getFileName()});
+ args.putInt(ARG_POSITIVE_BTN_RES, posBtn);
+ args.putInt(ARG_NEUTRAL_BTN_RES, neuBtn);
+ args.putInt(ARG_NEGATIVE_BTN_RES, R.string.common_cancel);
+ args.putParcelable(ARG_TARGET_FILE, file);
+ frag.setArguments(args);
+
+ frag.setOnConfirmationListener(frag);
+
+ return frag;
+ }
+
+ private OCFile mTargetFile;
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ Dialog dialog = super.onCreateDialog(savedInstanceState);
+ mTargetFile = getArguments().getParcelable(ARG_TARGET_FILE);
+ return dialog;
+ }
+
+ /**
+ * Performs the removal of the target file, both locally and in the server.
+ */
+ @Override
+ public void onConfirmation(String callerTag) {
+ ComponentsGetter cg = (ComponentsGetter)getSherlockActivity();
+ FileDataStorageManager storageManager = cg.getStorageManager();
+ if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
+ cg.getFileOperationsHelper().removeFile(mTargetFile, false);
+ }
+ }
+
+ /**
+ * Performs the removal of the local copy of the taget file
+ */
+ @Override
+ public void onNeutral(String callerTag) {
+ ((ComponentsGetter)getSherlockActivity()).getFileOperationsHelper()
+ .removeFile(mTargetFile, true);
+ }
+
+ @Override
+ public void onCancel(String callerTag) {
+ // nothing to do here
+ }
+
+}
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
-import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
import com.owncloud.android.ui.dialog.EditNameDialog;
+import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.Log_OC;
* @author David A. Velasco
*/
public class FileDetailFragment extends FileFragment implements
- OnClickListener,
- ConfirmationDialogFragment.ConfirmationDialogFragmentListener, EditNameDialogListener {
+ OnClickListener, EditNameDialogListener {
private int mLayout;
private View mView;
@Override
- public void onCreate(Bundle savedInstanceState) {
+ public void onActivityCreated(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
public void onPrepareOptionsMenu (Menu menu) {
super.onPrepareOptionsMenu(menu);
- FileMenuFilter mf = new FileMenuFilter(
- getFile(),
- mContainerActivity.getStorageManager().getAccount(),
- mContainerActivity,
- getSherlockActivity()
- );
- mf.filter(menu);
+ if (mContainerActivity.getStorageManager() != null) {
+ FileMenuFilter mf = new FileMenuFilter(
+ getFile(),
+ mContainerActivity.getStorageManager().getAccount(),
+ mContainerActivity,
+ getSherlockActivity()
+ );
+ mf.filter(menu);
+ }
// additional restriction for this fragment
MenuItem item = menu.findItem(R.id.action_see_details);
return true;
}
case R.id.action_remove_file: {
- showDialogToRemoveFile();
+ RemoveFileDialogFragment dialog = RemoveFileDialogFragment.newInstance(getFile());
+ dialog.show(getFragmentManager(), FTAG_CONFIRMATION);
return true;
}
case R.id.action_rename_file: {
}
}
- private void showDialogToRemoveFile() {
- OCFile file = getFile();
- ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
- R.string.confirmation_remove_alert,
- new String[]{file.getFileName()},
- file.isDown() ? R.string.confirmation_remove_remote_and_local : R.string.confirmation_remove_remote,
- file.isDown() ? R.string.confirmation_remove_local : -1,
- R.string.common_cancel);
- confDialog.setOnConfirmationListener(this);
- confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
- }
-
-
private void showDialogToRenameFile() {
OCFile file = getFile();
String fileName = file.getFileName();
EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), fileName, 0, selectionEnd, this);
dialog.show(getFragmentManager(), FTAG_RENAME_FILE);
}
-
-
- @Override
- public void onConfirmation(String callerTag) {
- OCFile file = getFile();
- if (callerTag.equals(FTAG_CONFIRMATION)) {
- if (mContainerActivity.getStorageManager().getFileById(file.getFileId()) != null) {
- mContainerActivity.getFileOperationsHelper().removeFile(file, false);
- }
- }
- }
-
- @Override
- public void onNeutral(String callerTag) {
- OCFile file = getFile();
- mContainerActivity.getFileOperationsHelper().removeFile(file, true);
- //if (file.getStoragePath() != null) {
- // file.setStoragePath(null);
- // updateFileDetails(file, mAccount);
- //}
- }
-
- @Override
- public void onCancel(String callerTag) {
- Log_OC.d(TAG, "REMOVAL CANCELED");
- }
-
/**
* Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
import com.owncloud.android.ui.dialog.EditNameDialog;
-import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
+import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
import com.owncloud.android.ui.preview.PreviewImageFragment;
import com.owncloud.android.ui.preview.PreviewMediaFragment;
* @author David A. Velasco
*/
public class OCFileListFragment extends ExtendedListFragment
-implements EditNameDialogListener, ConfirmationDialogFragmentListener {
+implements EditNameDialogListener {
private static final String TAG = OCFileListFragment.class.getSimpleName();
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
OCFile targetFile = (OCFile) mAdapter.getItem(info.position);
- FileMenuFilter mf = new FileMenuFilter(
- targetFile,
- mContainerActivity.getStorageManager().getAccount(),
- mContainerActivity,
- getSherlockActivity()
- );
- mf.filter(menu);
+ if (mContainerActivity.getStorageManager() != null) {
+ FileMenuFilter mf = new FileMenuFilter(
+ targetFile,
+ mContainerActivity.getStorageManager().getAccount(),
+ mContainerActivity,
+ getSherlockActivity()
+ );
+ mf.filter(menu);
+ }
/// additional restrictions for this fragment
// TODO allow in the future 'open with' for previewable files
return true;
}
case R.id.action_remove_file: {
- int messageStringId = R.string.confirmation_remove_alert;
- int posBtnStringId = R.string.confirmation_remove_remote;
- int neuBtnStringId = -1;
- if (mTargetFile.isFolder()) {
- messageStringId = R.string.confirmation_remove_folder_alert;
- posBtnStringId = R.string.confirmation_remove_remote_and_local;
- neuBtnStringId = R.string.confirmation_remove_folder_local;
- } else if (mTargetFile.isDown()) {
- posBtnStringId = R.string.confirmation_remove_remote_and_local;
- neuBtnStringId = R.string.confirmation_remove_local;
- }
- ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
- messageStringId,
- new String[]{mTargetFile.getFileName()},
- posBtnStringId,
- neuBtnStringId,
- R.string.common_cancel);
- confDialog.setOnConfirmationListener(this);
- confDialog.show(getFragmentManager(), FileDetailFragment.FTAG_CONFIRMATION);
+ RemoveFileDialogFragment dialog = RemoveFileDialogFragment.newInstance(mTargetFile);
+ dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION);
return true;
}
case R.id.action_download_file:
mContainerActivity.getFileOperationsHelper().renameFile(mTargetFile, newFilename);
}
}
-
- @Override
- public void onConfirmation(String callerTag) {
- if (callerTag.equals(FileDetailFragment.FTAG_CONFIRMATION)) {
- FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
- if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
- mContainerActivity.getFileOperationsHelper().removeFile(mTargetFile, false);
- }
- }
- }
-
- @Override
- public void onNeutral(String callerTag) {
- mContainerActivity.getFileOperationsHelper().removeFile(mTargetFile, true);
- //listDirectory();
- //mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
- }
-
- @Override
- public void onCancel(String callerTag) {
- Log_OC.d(TAG, "REMOVAL CANCELED");
- }
-
}
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.owncloud.android.R;
-import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.FileMenuFilter;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
+import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.utils.Log_OC;
*
* @author David A. Velasco
*/
-public class PreviewImageFragment extends FileFragment implements
-ConfirmationDialogFragment.ConfirmationDialogFragmentListener {
+public class PreviewImageFragment extends FileFragment {
public static final String EXTRA_FILE = "FILE";
public static final String EXTRA_ACCOUNT = "ACCOUNT";
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
- FileMenuFilter mf = new FileMenuFilter(
- getFile(),
- mContainerActivity.getStorageManager().getAccount(),
- mContainerActivity,
- getSherlockActivity()
- );
- mf.filter(menu);
+ if (mContainerActivity.getStorageManager() != null) {
+ FileMenuFilter mf = new FileMenuFilter(
+ getFile(),
+ mContainerActivity.getStorageManager().getAccount(),
+ mContainerActivity,
+ getSherlockActivity()
+ );
+ mf.filter(menu);
+ }
// additional restriction for this fragment
// TODO allow renaming in PreviewImageFragment
return true;
}
case R.id.action_remove_file: {
- removeFile();
+ RemoveFileDialogFragment dialog = RemoveFileDialogFragment.newInstance(getFile());
+ dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION);
return true;
}
case R.id.action_see_details: {
}
- /**
- * Starts a the removal of the previewed file.
- *
- * Shows a confirmation dialog. The action continues in {@link #onConfirmation(String)} , {@link #onNeutral(String)} or {@link #onCancel(String)},
- * depending upon the user selection in the dialog.
- */
- private void removeFile() {
- ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
- R.string.confirmation_remove_alert,
- new String[]{getFile().getFileName()},
- R.string.confirmation_remove_remote_and_local,
- R.string.confirmation_remove_local,
- R.string.common_cancel);
- confDialog.setOnConfirmationListener(this);
- confDialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION);
- }
-
-
- /**
- * Performs the removal of the previewed file, both locally and in the server.
- */
- @Override
- public void onConfirmation(String callerTag) {
- FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
- if (storageManager.getFileById(getFile().getFileId()) != null) { // check that the file is still there;
- mContainerActivity.getFileOperationsHelper().removeFile(getFile(), false);
- }
- }
-
-
- /**
- * Removes the file from local storage
- */
- @Override
- public void onNeutral(String callerTag) {
- OCFile file = getFile();
- mContainerActivity.getFileOperationsHelper().removeFile(file, true);
- //mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
- //finish();
- }
-
- /**
- * User cancelled the removal action.
- */
- @Override
- public void onCancel(String callerTag) {
- // nothing to do here
- }
-
-
private class BitmapLoader extends AsyncTask<String, Void, Bitmap> {
/**
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.owncloud.android.R;
-import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.FileMenuFilter;
import com.owncloud.android.media.MediaControlView;
import com.owncloud.android.media.MediaServiceBinder;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
+import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.utils.Log_OC;
* @author David A. Velasco
*/
public class PreviewMediaFragment extends FileFragment implements
- OnTouchListener,
- ConfirmationDialogFragment.ConfirmationDialogFragmentListener {
+ OnTouchListener {
public static final String EXTRA_FILE = "FILE";
public static final String EXTRA_ACCOUNT = "ACCOUNT";
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
- FileMenuFilter mf = new FileMenuFilter(
- getFile(),
- mContainerActivity.getStorageManager().getAccount(),
- mContainerActivity,
- getSherlockActivity()
- );
- mf.filter(menu);
+ if (mContainerActivity.getStorageManager() != null) {
+ FileMenuFilter mf = new FileMenuFilter(
+ getFile(),
+ mContainerActivity.getStorageManager().getAccount(),
+ mContainerActivity,
+ getSherlockActivity()
+ );
+ mf.filter(menu);
+ }
// additional restriction for this fragment
// TODO allow renaming in PreviewImageFragment
return true;
}
case R.id.action_remove_file: {
- removeFile();
+ RemoveFileDialogFragment dialog = RemoveFileDialogFragment.newInstance(getFile());
+ dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION);
return true;
}
case R.id.action_see_details: {
}
/**
- * Starts a the removal of the previewed file.
- *
- * Shows a confirmation dialog. The action continues in {@link #onConfirmation(String)} , {@link #onNeutral(String)} or {@link #onCancel(String)},
- * depending upon the user selection in the dialog.
- */
- private void removeFile() {
- ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
- R.string.confirmation_remove_alert,
- new String[]{getFile().getFileName()},
- R.string.confirmation_remove_remote_and_local,
- R.string.confirmation_remove_local,
- R.string.common_cancel);
- confDialog.setOnConfirmationListener(this);
- confDialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION);
- }
-
-
- /**
- * Performs the removal of the previewed file, both locally and in the server.
- */
- @Override
- public void onConfirmation(String callerTag) {
- OCFile file = getFile();
- FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
- if (storageManager.getFileById(file.getFileId()) != null) { // check that the file is still there;
- stopPreview(true);
- mContainerActivity.getFileOperationsHelper().removeFile(file, false);
- }
- }
-
-
- /**
- * Removes the file from local storage
- */
- @Override
- public void onNeutral(String callerTag) {
- OCFile file = getFile();
- stopPreview(true);
- //mContainerActivity.getStorageManager().removeFile(file, false, true); // TODO perform in background task / new thread
- mContainerActivity.getFileOperationsHelper().removeFile(file, true);
- //finish();
- }
-
- /**
- * User cancelled the removal action.
- */
- @Override
- public void onCancel(String callerTag) {
- // nothing to do here
- }
-
-
- /**
* Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} to be previewed.
*
* @param file File to test if can be previewed.
}
- private void stopPreview(boolean stopAudio) {
+ public void stopPreview(boolean stopAudio) {
OCFile file = getFile();
if (file.isAudio() && stopAudio) {
mMediaServiceBinder.pause();