21
21
import static com .github .mobile .Intents .EXTRA_POSITION ;
22
22
import static com .github .mobile .Intents .EXTRA_REPOSITORIES ;
23
23
import static com .github .mobile .Intents .EXTRA_REPOSITORY ;
24
+ import android .accounts .Account ;
24
25
import android .content .Intent ;
25
26
import android .os .Bundle ;
26
27
27
28
import com .actionbarsherlock .app .ActionBar ;
29
+ import com .actionbarsherlock .view .Menu ;
28
30
import com .actionbarsherlock .view .MenuItem ;
29
31
import com .github .mobile .Intents .Builder ;
30
32
import com .github .mobile .R .id ;
31
33
import com .github .mobile .R .layout ;
32
34
import com .github .mobile .R .string ;
35
+ import com .github .mobile .accounts .AccountUtils ;
36
+ import com .github .mobile .accounts .AuthenticatedUserTask ;
33
37
import com .github .mobile .core .issue .IssueStore ;
34
38
import com .github .mobile .core .issue .IssueUtils ;
35
39
import com .github .mobile .core .repo .RefreshRepositoryTask ;
51
55
import org .eclipse .egit .github .core .RepositoryId ;
52
56
import org .eclipse .egit .github .core .RepositoryIssue ;
53
57
import org .eclipse .egit .github .core .User ;
58
+ import org .eclipse .egit .github .core .service .CollaboratorService ;
54
59
55
60
/**
56
61
* Activity to display a collection of issues or pull requests in a pager
@@ -164,8 +169,13 @@ public static Intent createIntent(Collection<? extends Issue> issues,
164
169
@ Inject
165
170
private IssueStore store ;
166
171
172
+ @ Inject
173
+ private CollaboratorService collaboratorService ;
174
+
167
175
private final AtomicReference <User > user = new AtomicReference <User >();
168
176
177
+ private boolean isCollaborator ;
178
+
169
179
private IssuesPagerAdapter adapter ;
170
180
171
181
private final UrlLauncher urlLauncher = new UrlLauncher (this );
@@ -218,6 +228,9 @@ protected void onSuccess(Repository fullRepository)
218
228
fullRepository .getOwner ());
219
229
}
220
230
}.execute ();
231
+
232
+ isCollaborator = false ;
233
+ checkCollaboratorStatus ();
221
234
}
222
235
223
236
private void updateTitle (final int position ) {
@@ -286,6 +299,14 @@ protected FragmentProvider getProvider() {
286
299
return adapter ;
287
300
}
288
301
302
+ @ Override
303
+ public boolean onPrepareOptionsMenu (Menu menu ) {
304
+ menu .findItem (id .m_edit ).setVisible (isCollaborator );
305
+ menu .findItem (id .m_state ).setVisible (isCollaborator );
306
+
307
+ return super .onPrepareOptionsMenu (menu );
308
+ }
309
+
289
310
@ Override
290
311
public boolean onOptionsItemSelected (MenuItem item ) {
291
312
switch (item .getItemId ()) {
@@ -312,4 +333,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
312
333
return super .onOptionsItemSelected (item );
313
334
}
314
335
}
336
+
337
+ private void checkCollaboratorStatus () {
338
+ new AuthenticatedUserTask <Boolean >(this ) {
339
+
340
+ @ Override
341
+ protected Boolean run (Account account ) throws Exception {
342
+ return collaboratorService .isCollaborator (
343
+ repo , AccountUtils .getLogin (IssuesViewActivity .this ));
344
+ }
345
+
346
+ @ Override
347
+ protected void onSuccess (Boolean collaborator ) throws Exception {
348
+ super .onSuccess (collaborator );
349
+
350
+ isCollaborator = collaborator ;
351
+ invalidateOptionsMenu ();
352
+ }
353
+ }.execute ();
354
+ }
315
355
}
0 commit comments