From 500cbf9cea65663d7cc6e4a1ca39bec5af5bdd57 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Tue, 6 Nov 2012 15:13:27 +0100 Subject: [PATCH] New items in the context menu for files (not folders), depending upon its state --- res/menu/file_context_menu.xml | 19 +++++++++++++ res/values/strings.xml | 4 ++- .../android/ui/fragment/OCFileListFragment.java | 33 +++++++++++++++++++++- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/res/menu/file_context_menu.xml b/res/menu/file_context_menu.xml index 8014c149..622c483d 100644 --- a/res/menu/file_context_menu.xml +++ b/res/menu/file_context_menu.xml @@ -1,6 +1,25 @@ + + + + + + + + Yes No OK - Cancel + Cancel download + Cancel upload + Cancel Save & Exit Leave ownCloud Error diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 5187a84f..a5e59d46 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -154,7 +154,38 @@ public class OCFileListFragment extends FragmentListView implements EditNameDial super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.file_context_menu, menu); - AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; + AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; + OCFile targetFile = (OCFile) mAdapter.getItem(info.position); + MenuItem item = null; + int[] ids = null; + if (targetFile.isDirectory()) { + int[] theIds = {R.id.open_file_item, R.id.download_file_item, R.id.cancel_download_item, R.id.cancel_upload_item}; + ids = theIds; + + } else if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) { + int[] theIds = {R.id.open_file_item, R.id.download_file_item, R.id.cancel_upload_item}; + ids = theIds; + + } else if ( mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) { + int[] theIds = {R.id.open_file_item, R.id.download_file_item, R.id.cancel_download_item}; + ids = theIds; + + } else if ( targetFile.isDown()) { + int[] theIds = {R.id.cancel_download_item, R.id.cancel_upload_item}; + ids = theIds; + + } else { + int[] theIds = {R.id.open_file_item, R.id.cancel_download_item, R.id.cancel_upload_item}; + ids = theIds; + } + + for (int i=0; i < ids.length; i++) { + item = menu.findItem(ids[i]); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); + } + } } -- 2.11.0