--- /dev/null
+package com.owncloud.android.files;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.accounts.Account;
+import android.content.Context;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import com.actionbarsherlock.app.SherlockFragment;
+import com.owncloud.android.R;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
+import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
+import com.owncloud.android.ui.activity.ComponentsGetter;
+import com.owncloud.android.ui.fragment.FileDetailFragment;
+import com.owncloud.android.ui.fragment.OCFileListFragment;
+import com.owncloud.android.ui.preview.PreviewImageFragment;
+import com.owncloud.android.ui.preview.PreviewMediaFragment;
+
+public class FileMenuFilter {
+
+ private OCFile mFile;
+ private ComponentsGetter mComponentsGetter;
+ private Account mAccount;
+ private Context mContext;
+ private SherlockFragment mFragment;
+
+ public void setFile(OCFile targetFile) {
+ mFile = targetFile;
+ }
+
+ public void setAccount(Account account) {
+ mAccount = account;
+ }
+
+ public void setComponentGetter(ComponentsGetter cg) {
+ mComponentsGetter = cg;
+ }
+
+ public void setContext(Context context) {
+ mContext = context;
+ }
+
+ public void setFragment(SherlockFragment fragment) {
+ mFragment = fragment;
+ }
+
+ public void filter(Menu menu) {
+ List<Integer> toShow = new ArrayList<Integer>();
+ List<Integer> toDisable = new ArrayList<Integer>();
+ List<Integer> toHide = new ArrayList<Integer>();
+
+ filter(toShow, toDisable, toHide);
+
+ MenuItem item = null;
+ for (int i : toShow) {
+ item = menu.findItem(i);
+ if (item != null) {
+ item.setVisible(true);
+ item.setEnabled(true);
+ }
+ }
+
+ for (int i : toDisable) {
+ item = menu.findItem(i);
+ if (item != null) {
+ item.setVisible(true);
+ item.setEnabled(false);
+ }
+ }
+
+ for (int i : toHide) {
+ item = menu.findItem(i);
+ if (item != null) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ }
+ }
+ }
+
+ /**
+ * ActionBarSherlock...
+ *
+ */
+ public void filter(com.actionbarsherlock.view.Menu menu) {
+
+ List<Integer> toShow = new ArrayList<Integer>();
+ List<Integer> toDisable = new ArrayList<Integer>();
+ List<Integer> toHide = new ArrayList<Integer>();
+
+ filter(toShow, toDisable, toHide);
+
+ com.actionbarsherlock.view.MenuItem item = null;
+ for (int i : toShow) {
+ item = menu.findItem(i);
+ if (item != null) {
+ item.setVisible(true);
+ item.setEnabled(true);
+ }
+ }
+ for (int i : toDisable) {
+ item = menu.findItem(i);
+ if (item != null) {
+ item.setVisible(true);
+ item.setEnabled(false);
+ }
+ }
+ for (int i : toHide) {
+ item = menu.findItem(i);
+ if (item != null) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ }
+ }
+ }
+
+ private void filter(List<Integer> toShow, List<Integer> toDisable, List <Integer> toHide) {
+ boolean downloading = false;
+ boolean uploading = false;
+ if (mComponentsGetter != null && mFile != null && mAccount != null) {
+ FileDownloaderBinder downloaderBinder = mComponentsGetter.getFileDownloaderBinder();
+ downloading = downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile);
+ FileUploaderBinder uploaderBinder = mComponentsGetter.getFileUploaderBinder();
+ uploading = uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile);
+ }
+
+ // R.id.action_download_file
+ if (mFile == null || mFile.isFolder() || mFile.isDown() || downloading || uploading ||
+ (mFragment != null && (
+ mFragment instanceof PreviewImageFragment ||
+ mFragment instanceof PreviewMediaFragment
+ )
+ )
+ ) {
+ toHide.add(R.id.action_download_file);
+
+ } else {
+ toShow.add(R.id.action_download_file);
+ }
+
+ // R.id.action_rename_file
+ if ((downloading || uploading) &&
+ (mFragment != null && mFragment instanceof OCFileListFragment)
+ ) {
+ toDisable.add(R.id.action_rename_file);
+
+ } else if (mFile == null || downloading || uploading ||
+ (mFragment != null && (
+ mFragment instanceof PreviewImageFragment ||
+ mFragment instanceof PreviewMediaFragment
+ )
+ )
+ ) {
+ toHide.add(R.id.action_rename_file);
+
+ } else {
+ toShow.add(R.id.action_rename_file);
+ }
+
+ // R.id.action_remove_file
+ if ((downloading || uploading) &&
+ (mFragment != null && mFragment instanceof OCFileListFragment)
+ ) {
+ toDisable.add(R.id.action_remove_file);
+
+ } else if (mFile == null || downloading || uploading) {
+ toHide.add(R.id.action_remove_file);
+
+ } else {
+ toShow.add(R.id.action_remove_file);
+ }
+
+ // R.id.action_open_file_with
+ if (mFile == null || mFile.isFolder() || !mFile.isDown() || downloading || uploading ||
+ (mFragment != null && mFragment instanceof OCFileListFragment)) {
+ toHide.add(R.id.action_open_file_with);
+
+ } else {
+ toShow.add(R.id.action_open_file_with);
+ }
+
+
+ // R.id.action_cancel_download
+ if (mFile == null || !downloading || mFile.isFolder() ||
+ (mFragment != null && (
+ (mFragment instanceof PreviewImageFragment) ||
+ (mFragment instanceof PreviewMediaFragment)
+ )
+ )
+ ) {
+ toHide.add(R.id.action_cancel_download);
+ } else {
+ toShow.add(R.id.action_cancel_download);
+ }
+
+ // R.id.action_cancel_upload
+ if (mFile == null || !uploading || mFile.isFolder() ||
+ (mFragment != null && (
+ (mFragment instanceof PreviewImageFragment) ||
+ (mFragment instanceof PreviewMediaFragment)
+ )
+ )
+ ) {
+ toHide.add(R.id.action_cancel_upload);
+ } else {
+ toShow.add(R.id.action_cancel_upload);
+ }
+
+ // R.id.action_sync_file
+ if (mFile == null || mFile.isFolder() || !mFile.isDown() || downloading || uploading ||
+ (mFragment != null && mFragment instanceof PreviewMediaFragment)
+ ) {
+ toHide.add(R.id.action_sync_file);
+ } else {
+ toShow.add(R.id.action_sync_file);
+ }
+
+ // R.id.action_share_file // TODO add check on SHARE available on server side?
+ if (mFile == null) {
+ toHide.add(R.id.action_share_file);
+ } else {
+ toShow.add(R.id.action_share_file);
+ }
+
+ // R.id.action_unshare_file // TODO add check on SHARE available on server side?
+ if (mFile == null || !mFile.isShareByLink()) {
+ toHide.add(R.id.action_unshare_file);
+ } else {
+ toShow.add(R.id.action_unshare_file);
+ }
+
+
+ // R.id.action_see_details
+ if (mFile == null || mFile.isFolder() || (mFragment != null && mFragment instanceof FileDetailFragment)) {
+ // TODO check dual pane when FileDetailFragment is shown
+ toHide.add(R.id.action_see_details);
+ } else {
+ toShow.add(R.id.action_see_details);
+ }
+
+ // R.id.action_send_file
+ boolean sendEnabled = (mContext != null &&
+ mContext.getString(R.string.send_files_to_other_apps).equalsIgnoreCase("on"));
+ if (mFile != null && sendEnabled && !mFile.isFolder()) {
+ toShow.add(R.id.action_send_file);
+ } else {
+ toHide.add(R.id.action_send_file);
+ }
+
+ }
+
+}
package com.owncloud.android.ui.fragment;
import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.List;
import android.accounts.Account;
import android.content.Intent;
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.files.services.FileObserverService;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
return view;
}
- /*-*
- * {@inheritDoc}
- *-/
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- if (mAccount != null) {
- OCFile file = ((FileActivity)getActivity()).getStorageManager().
- getFileByPath(getFile().getRemotePath());
- if (file != null) {
- setFile(file);
- }
- }
- }
- */
-
-
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.file_actions_menu, menu);
+
+ /*
+ TODO Maybe should stay here? It's context (fragment) specific
+
MenuItem item = menu.findItem(R.id.action_see_details);
if (item != null) {
item.setVisible(false);
}
}
+ */
}
public void onPrepareOptionsMenu (Menu menu) {
super.onPrepareOptionsMenu(menu);
- List<Integer> toHide = new ArrayList<Integer>();
- List<Integer> toShow = new ArrayList<Integer>();
- OCFile file = getFile();
-
- FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
- boolean downloading = downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file);
- FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
- boolean uploading = uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile());
-
- if (downloading || uploading) {
- toHide.add(R.id.action_download_file);
- toHide.add(R.id.action_rename_file);
- toHide.add(R.id.action_remove_file);
- toHide.add(R.id.action_open_file_with);
- if (!downloading) {
- toHide.add(R.id.action_cancel_download);
- toShow.add(R.id.action_cancel_upload);
- } else {
- toHide.add(R.id.action_cancel_upload);
- toShow.add(R.id.action_cancel_download);
- }
-
- } else if (file != null && file.isDown()) {
- toHide.add(R.id.action_download_file);
- toHide.add(R.id.action_cancel_download);
- toHide.add(R.id.action_cancel_upload);
-
- toShow.add(R.id.action_rename_file);
- toShow.add(R.id.action_remove_file);
- toShow.add(R.id.action_open_file_with);
- toShow.add(R.id.action_sync_file);
-
- } else if (file != null) {
- toHide.add(R.id.action_open_file_with);
- toHide.add(R.id.action_cancel_download);
- toHide.add(R.id.action_cancel_upload);
- toHide.add(R.id.action_sync_file);
-
- toShow.add(R.id.action_rename_file);
- toShow.add(R.id.action_remove_file);
- toShow.add(R.id.action_download_file);
-
- } else {
- toHide.add(R.id.action_open_file_with);
- toHide.add(R.id.action_cancel_download);
- toHide.add(R.id.action_cancel_upload);
- toHide.add(R.id.action_sync_file);
- toHide.add(R.id.action_download_file);
- toHide.add(R.id.action_rename_file);
- toHide.add(R.id.action_remove_file);
-
- }
-
- // Options shareLink
- if (!file.isShareByLink()) {
- toHide.add(R.id.action_unshare_file);
- } else {
- toShow.add(R.id.action_unshare_file);
- }
-
- MenuItem item = null;
- for (int i : toHide) {
- item = menu.findItem(i);
- if (item != null) {
- item.setVisible(false);
- item.setEnabled(false);
- }
- }
- for (int i : toShow) {
- item = menu.findItem(i);
- if (item != null) {
- item.setVisible(true);
- item.setEnabled(true);
- }
- }
+ FileMenuFilter mf = new FileMenuFilter();
+ mf.setFile(getFile());
+ mf.setComponentGetter(mContainerActivity);
+ mf.setAccount(mContainerActivity.getStorageManager().getAccount());
+ mf.setContext(getSherlockActivity());
+ mf.setFragment(this);
+ mf.filter(menu);
}
import java.io.File;
import java.util.ArrayList;
-import java.util.List;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.FileMenuFilter;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.ui.adapter.FileListListAdapter;
* @author masensio
* @author David A. Velasco
*/
-public class OCFileListFragment extends ExtendedListFragment implements EditNameDialogListener, ConfirmationDialogFragmentListener {
+public class OCFileListFragment extends ExtendedListFragment
+implements EditNameDialogListener, ConfirmationDialogFragmentListener {
private static final String TAG = OCFileListFragment.class.getSimpleName();
inflater.inflate(R.menu.file_actions_menu, menu);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
OCFile targetFile = (OCFile) mAdapter.getItem(info.position);
- List<Integer> toHide = new ArrayList<Integer>();
- List<Integer> toDisable = new ArrayList<Integer>();
- MenuItem item = null;
- if (targetFile.isFolder()) {
- // contextual menu for folders
- toHide.add(R.id.action_open_file_with);
- toHide.add(R.id.action_download_file);
- toHide.add(R.id.action_cancel_download);
- toHide.add(R.id.action_cancel_upload);
- toHide.add(R.id.action_sync_file);
- toHide.add(R.id.action_see_details);
- toHide.add(R.id.action_send_file);
- if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile) ||
- mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile) ) {
- toDisable.add(R.id.action_rename_file);
- toDisable.add(R.id.action_remove_file);
-
- }
-
- } else {
- // contextual menu for regular files
-
- // new design: 'download' and 'open with' won't be available anymore in context menu
- toHide.add(R.id.action_download_file);
- toHide.add(R.id.action_open_file_with);
-
- if (targetFile.isDown()) {
- toHide.add(R.id.action_cancel_download);
- toHide.add(R.id.action_cancel_upload);
-
- } else {
- toHide.add(R.id.action_sync_file);
- }
- if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile)) {
- toHide.add(R.id.action_cancel_upload);
- toDisable.add(R.id.action_rename_file);
- toDisable.add(R.id.action_remove_file);
-
- } else if ( mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile)) {
- toHide.add(R.id.action_cancel_download);
- toDisable.add(R.id.action_rename_file);
- toDisable.add(R.id.action_remove_file);
-
- } else {
- toHide.add(R.id.action_cancel_download);
- toHide.add(R.id.action_cancel_upload);
- }
- }
-
- // Options shareLink
- if (!targetFile.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);
- }
- }
-
- for (int i : toDisable) {
- item = menu.findItem(i);
- if (item != null) {
- item.setEnabled(false);
- }
- }
+ FileMenuFilter mf = new FileMenuFilter();
+ mf.setFile(targetFile);
+ mf.setComponentGetter(mContainerActivity);
+ mf.setAccount(mContainerActivity.getStorageManager().getAccount());
+ mf.setContext(getSherlockActivity());
+ mf.setFragment(this);
+ mf.filter(menu);
}
package com.owncloud.android.ui.preview;
import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.List;
import android.accounts.Account;
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.fragment.FileFragment;
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.file_actions_menu, menu);
- List<Integer> toHide = new ArrayList<Integer>();
-
+ /*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_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) {
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()) {
item.setVisible(true);
item.setEnabled(true);
}
-
+ */
}
*/
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;
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;
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.file_actions_menu, menu);
+ /*
List<Integer> toHide = new ArrayList<Integer>();
MenuItem item = null;
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()) {
item.setVisible(true);
item.setEnabled(true);
}
+ */
}