X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/c6edcab5a2f81773f05b8f796f2c356c2c2aeb4d..cfbbece869db04ffc071ba7b61257af9a7d57f78:/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java diff --git a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index 8df42c98..a2685b8a 100644 --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -16,9 +16,6 @@ */ package com.owncloud.android.ui.preview; -import java.util.ArrayList; -import java.util.List; - import android.accounts.Account; import android.app.Activity; import android.app.AlertDialog; @@ -48,13 +45,14 @@ import com.actionbarsherlock.view.Menu; 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.MediaService; 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; @@ -69,8 +67,7 @@ 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"; @@ -90,8 +87,6 @@ public class PreviewMediaFragment extends FileFragment implements private boolean mAutoplay; public boolean mPrepared; - private FileFragment.ContainerActivity mContainerActivity; - private static final String TAG = PreviewMediaFragment.class.getSimpleName(); @@ -250,36 +245,7 @@ public class PreviewMediaFragment extends FileFragment implements @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); - inflater.inflate(R.menu.file_actions_menu, menu); - List toHide = new ArrayList(); - - 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); - } - } - } @@ -290,14 +256,22 @@ public class PreviewMediaFragment extends FileFragment implements public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(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); } } @@ -309,11 +283,13 @@ public class PreviewMediaFragment extends FileFragment implements 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: { @@ -321,7 +297,8 @@ public class PreviewMediaFragment extends FileFragment implements 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: { @@ -331,7 +308,11 @@ public class PreviewMediaFragment extends FileFragment implements case R.id.action_send_file: { sendFile(); } - + case R.id.action_sync_file: { + mContainerActivity.getFileOperationsHelper().syncFile(getFile()); + return true; + } + default: return false; } @@ -347,17 +328,6 @@ public class PreviewMediaFragment extends FileFragment implements 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()); @@ -624,58 +594,6 @@ public class PreviewMediaFragment extends FileFragment implements } /** - * 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. @@ -686,7 +604,7 @@ public class PreviewMediaFragment extends FileFragment implements } - private void stopPreview(boolean stopAudio) { + public void stopPreview(boolean stopAudio) { OCFile file = getFile(); if (file.isAudio() && stopAudio) { mMediaServiceBinder.pause();