1 package com
.owncloud
.android
.files
;
3 import java
.util
.ArrayList
;
6 import android
.accounts
.Account
;
7 import android
.content
.Context
;
8 import android
.view
.Menu
;
9 import android
.view
.MenuItem
;
11 import com
.actionbarsherlock
.app
.SherlockFragment
;
12 import com
.owncloud
.android
.R
;
13 import com
.owncloud
.android
.datamodel
.OCFile
;
14 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
15 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
16 import com
.owncloud
.android
.ui
.activity
.ComponentsGetter
;
17 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
18 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
19 import com
.owncloud
.android
.ui
.preview
.PreviewImageFragment
;
20 import com
.owncloud
.android
.ui
.preview
.PreviewMediaFragment
;
22 public class FileMenuFilter
{
25 private ComponentsGetter mComponentsGetter
;
26 private Account mAccount
;
27 private Context mContext
;
28 private SherlockFragment mFragment
;
30 public void setFile(OCFile targetFile
) {
34 public void setAccount(Account account
) {
38 public void setComponentGetter(ComponentsGetter cg
) {
39 mComponentsGetter
= cg
;
42 public void setContext(Context context
) {
46 public void setFragment(SherlockFragment fragment
) {
50 public void filter(Menu menu
) {
51 List
<Integer
> toShow
= new ArrayList
<Integer
>();
52 List
<Integer
> toDisable
= new ArrayList
<Integer
>();
53 List
<Integer
> toHide
= new ArrayList
<Integer
>();
55 filter(toShow
, toDisable
, toHide
);
58 for (int i
: toShow
) {
59 item
= menu
.findItem(i
);
61 item
.setVisible(true
);
62 item
.setEnabled(true
);
66 for (int i
: toDisable
) {
67 item
= menu
.findItem(i
);
69 item
.setVisible(true
);
70 item
.setEnabled(false
);
74 for (int i
: toHide
) {
75 item
= menu
.findItem(i
);
77 item
.setVisible(false
);
78 item
.setEnabled(false
);
84 * ActionBarSherlock...
87 public void filter(com
.actionbarsherlock
.view
.Menu menu
) {
89 List
<Integer
> toShow
= new ArrayList
<Integer
>();
90 List
<Integer
> toDisable
= new ArrayList
<Integer
>();
91 List
<Integer
> toHide
= new ArrayList
<Integer
>();
93 filter(toShow
, toDisable
, toHide
);
95 com
.actionbarsherlock
.view
.MenuItem item
= null
;
96 for (int i
: toShow
) {
97 item
= menu
.findItem(i
);
99 item
.setVisible(true
);
100 item
.setEnabled(true
);
103 for (int i
: toDisable
) {
104 item
= menu
.findItem(i
);
106 item
.setVisible(true
);
107 item
.setEnabled(false
);
110 for (int i
: toHide
) {
111 item
= menu
.findItem(i
);
113 item
.setVisible(false
);
114 item
.setEnabled(false
);
119 private void filter(List
<Integer
> toShow
, List
<Integer
> toDisable
, List
<Integer
> toHide
) {
120 boolean downloading
= false
;
121 boolean uploading
= false
;
122 if (mComponentsGetter
!= null
&& mFile
!= null
&& mAccount
!= null
) {
123 FileDownloaderBinder downloaderBinder
= mComponentsGetter
.getFileDownloaderBinder();
124 downloading
= downloaderBinder
!= null
&& downloaderBinder
.isDownloading(mAccount
, mFile
);
125 FileUploaderBinder uploaderBinder
= mComponentsGetter
.getFileUploaderBinder();
126 uploading
= uploaderBinder
!= null
&& uploaderBinder
.isUploading(mAccount
, mFile
);
129 // R.id.action_download_file
130 if (mFile
== null
|| mFile
.isFolder() || mFile
.isDown() || downloading
|| uploading
||
131 (mFragment
!= null
&& (
132 mFragment
instanceof PreviewImageFragment
||
133 mFragment
instanceof PreviewMediaFragment
137 toHide
.add(R
.id
.action_download_file
);
140 toShow
.add(R
.id
.action_download_file
);
143 // R.id.action_rename_file
144 if ((downloading
|| uploading
) &&
145 (mFragment
!= null
&& mFragment
instanceof OCFileListFragment
)
147 toDisable
.add(R
.id
.action_rename_file
);
149 } else if (mFile
== null
|| downloading
|| uploading
||
150 (mFragment
!= null
&& (
151 mFragment
instanceof PreviewImageFragment
||
152 mFragment
instanceof PreviewMediaFragment
156 toHide
.add(R
.id
.action_rename_file
);
159 toShow
.add(R
.id
.action_rename_file
);
162 // R.id.action_remove_file
163 if ((downloading
|| uploading
) &&
164 (mFragment
!= null
&& mFragment
instanceof OCFileListFragment
)
166 toDisable
.add(R
.id
.action_remove_file
);
168 } else if (mFile
== null
|| downloading
|| uploading
) {
169 toHide
.add(R
.id
.action_remove_file
);
172 toShow
.add(R
.id
.action_remove_file
);
175 // R.id.action_open_file_with
176 if (mFile
== null
|| mFile
.isFolder() || !mFile
.isDown() || downloading
|| uploading
||
177 (mFragment
!= null
&& mFragment
instanceof OCFileListFragment
)) {
178 toHide
.add(R
.id
.action_open_file_with
);
181 toShow
.add(R
.id
.action_open_file_with
);
185 // R.id.action_cancel_download
186 if (mFile
== null
|| !downloading
|| mFile
.isFolder() ||
187 (mFragment
!= null
&& (
188 (mFragment
instanceof PreviewImageFragment
) ||
189 (mFragment
instanceof PreviewMediaFragment
)
193 toHide
.add(R
.id
.action_cancel_download
);
195 toShow
.add(R
.id
.action_cancel_download
);
198 // R.id.action_cancel_upload
199 if (mFile
== null
|| !uploading
|| mFile
.isFolder() ||
200 (mFragment
!= null
&& (
201 (mFragment
instanceof PreviewImageFragment
) ||
202 (mFragment
instanceof PreviewMediaFragment
)
206 toHide
.add(R
.id
.action_cancel_upload
);
208 toShow
.add(R
.id
.action_cancel_upload
);
211 // R.id.action_sync_file
212 if (mFile
== null
|| mFile
.isFolder() || !mFile
.isDown() || downloading
|| uploading
||
213 (mFragment
!= null
&& mFragment
instanceof PreviewMediaFragment
)
215 toHide
.add(R
.id
.action_sync_file
);
217 toShow
.add(R
.id
.action_sync_file
);
220 // R.id.action_share_file // TODO add check on SHARE available on server side?
222 toHide
.add(R
.id
.action_share_file
);
224 toShow
.add(R
.id
.action_share_file
);
227 // R.id.action_unshare_file // TODO add check on SHARE available on server side?
228 if (mFile
== null
|| !mFile
.isShareByLink()) {
229 toHide
.add(R
.id
.action_unshare_file
);
231 toShow
.add(R
.id
.action_unshare_file
);
235 // R.id.action_see_details
236 if (mFile
== null
|| mFile
.isFolder() || (mFragment
!= null
&& mFragment
instanceof FileDetailFragment
)) {
237 // TODO check dual pane when FileDetailFragment is shown
238 toHide
.add(R
.id
.action_see_details
);
240 toShow
.add(R
.id
.action_see_details
);
243 // R.id.action_send_file
244 boolean sendEnabled
= (mContext
!= null
&&
245 mContext
.getString(R
.string
.send_files_to_other_apps
).equalsIgnoreCase("on"));
246 if (mFile
!= null
&& sendEnabled
&& !mFile
.isFolder()) {
247 toShow
.add(R
.id
.action_send_file
);
249 toHide
.add(R
.id
.action_send_file
);