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";
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
-
inflater.inflate(R.menu.file_actions_menu, menu);
- /*
- List<Integer> toHide = new ArrayList<Integer>();
-
- MenuItem item = null;
- toHide.add(R.id.action_cancel_download);
- toHide.add(R.id.action_cancel_upload);
- toHide.add(R.id.action_download_file);
- toHide.add(R.id.action_sync_file);
- toHide.add(R.id.action_rename_file); // by now
-
- // Options shareLink
- if (!getFile().isShareByLink()) {
- toHide.add(R.id.action_unshare_file);
- }
-
- // Send file
- boolean sendEnabled = getString(R.string.send_files_to_other_apps).equalsIgnoreCase("on");
- if (!sendEnabled) {
- toHide.add(R.id.action_send_file);
- }
-
- for (int i : toHide) {
- item = menu.findItem(i);
- if (item != null) {
- item.setVisible(false);
- item.setEnabled(false);
- }
- }
- */
-
}
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
- FileMenuFilter mf = new FileMenuFilter();
- mf.setFile(getFile());
- mf.setComponentGetter(mContainerActivity);
- mf.setAccount(mContainerActivity.getStorageManager().getAccount());
- mf.setContext(getSherlockActivity());
- mf.setFragment(this);
- mf.filter(menu);
-
- /*
- MenuItem item = menu.findItem(R.id.action_unshare_file);
- // Options shareLink
- if (!getFile().isShareByLink()) {
+ 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
+ MenuItem item = menu.findItem(R.id.action_rename_file);
+ if (item != null) {
item.setVisible(false);
item.setEnabled(false);
- } else {
- item.setVisible(true);
- item.setEnabled(true);
}
- */
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_share_file: {
- shareFileWithLink();
+ stopPreview(false);
+ mContainerActivity.getFileOperationsHelper().shareFileWithLink(getFile());
return true;
}
case R.id.action_unshare_file: {
- unshareFileWithLink();
+ stopPreview(false);
+ mContainerActivity.getFileOperationsHelper().unshareFileWithLink(getFile());
return true;
}
case R.id.action_open_file_with: {
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: {
case R.id.action_send_file: {
sendFile();
}
-
+ case R.id.action_sync_file: {
+ mContainerActivity.getFileOperationsHelper().syncFile(getFile());
+ return true;
+ }
+
default:
return false;
}
setFile(file);
}
- private void unshareFileWithLink() {
- stopPreview(false);
- mContainerActivity.getFileOperationsHelper().unshareFileWithLink(getFile());
- }
-
- private void shareFileWithLink() {
- stopPreview(false);
- mContainerActivity.getFileOperationsHelper().shareFileWithLink(getFile());
-
- }
-
private void sendFile() {
stopPreview(false);
mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile());
}
/**
- * 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, true);
- }
- }
-
-
- /**
- * 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
- 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();