Skip to content

Commit 941a391

Browse files
maltzjatermenji
authored andcommitted
Non-collaborator restrictions in EditIssueActivity
Made it so that issue administration options only show up if the user is a collaborator on this repository Closes pockethub#419
1 parent 43922d4 commit 941a391

File tree

2 files changed

+96
-18
lines changed

2 files changed

+96
-18
lines changed

app/res/layout/issue_edit.xml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@
2424
android:layout_alignParentLeft="true"
2525
android:layout_alignParentTop="true" />
2626

27+
<ProgressBar
28+
android:id="@+id/pb_loading"
29+
style="@style/Spinner"
30+
android:layout_centerInParent="true"
31+
android:layout_width="64dp"
32+
android:layout_height="64dp" />
33+
2734
<ScrollView
35+
android:id="@+id/sv_issue_content"
2836
android:layout_width="match_parent"
2937
android:layout_height="match_parent"
30-
android:layout_below="@id/v_header_separator" >
38+
android:layout_below="@id/v_header_separator"
39+
android:visibility="gone" >
3140

3241
<LinearLayout
3342
android:layout_width="match_parent"
@@ -44,10 +53,16 @@
4453
style="@style/FormalSingleLineEditText"
4554
android:layout_width="match_parent" />
4655

56+
<!-- We initially hide many of these because we don't know if the
57+
the user is a collaborator, so we show them later as necessary
58+
-->
59+
4760
<TextView
61+
android:id="@+id/tv_labels_label"
4862
style="@style/HeaderTitleText"
4963
android:paddingTop="5dp"
50-
android:text="@string/labels" />
64+
android:text="@string/labels"
65+
android:visibility="gone" />
5166

5267
<LinearLayout
5368
android:id="@+id/ll_labels"
@@ -56,7 +71,8 @@
5671
android:background="@drawable/inset_background"
5772
android:gravity="center_vertical"
5873
android:orientation="horizontal"
59-
android:padding="10dp" >
74+
android:padding="10dp"
75+
android:visibility="gone" >
6076

6177
<TextView
6278
android:id="@+id/tv_labels"
@@ -66,9 +82,11 @@
6682
</LinearLayout>
6783

6884
<TextView
85+
android:id="@+id/tv_assignee_label"
6986
style="@style/HeaderTitleText"
7087
android:paddingTop="5dp"
71-
android:text="@string/assignee" />
88+
android:text="@string/assignee"
89+
android:visibility="gone" />
7290

7391
<LinearLayout
7492
android:id="@+id/ll_assignee"
@@ -77,7 +95,8 @@
7795
android:background="@drawable/inset_background"
7896
android:gravity="center_vertical"
7997
android:orientation="horizontal"
80-
android:padding="10dp" >
98+
android:padding="10dp"
99+
android:visibility="gone" >
81100

82101
<ImageView
83102
android:id="@+id/iv_assignee_avatar"
@@ -93,9 +112,11 @@
93112
</LinearLayout>
94113

95114
<TextView
115+
android:id="@+id/tv_milestone_label"
96116
style="@style/HeaderTitleText"
97117
android:paddingTop="5dp"
98-
android:text="@string/milestone" />
118+
android:text="@string/milestone"
119+
android:visibility="gone" />
99120

100121
<LinearLayout
101122
android:id="@+id/ll_milestone"
@@ -104,7 +125,8 @@
104125
android:background="@drawable/inset_background"
105126
android:gravity="center_vertical"
106127
android:orientation="vertical"
107-
android:padding="10dp" >
128+
android:padding="10dp"
129+
android:visibility="gone" >
108130

109131
<TextView
110132
android:id="@+id/tv_milestone"

app/src/main/java/com/github/mobile/ui/issue/EditIssueActivity.java

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
import static com.github.mobile.RequestCodes.ISSUE_ASSIGNEE_UPDATE;
2525
import static com.github.mobile.RequestCodes.ISSUE_LABELS_UPDATE;
2626
import static com.github.mobile.RequestCodes.ISSUE_MILESTONE_UPDATE;
27+
import android.accounts.Account;
2728
import android.content.Intent;
2829
import android.os.Bundle;
2930
import android.text.Editable;
3031
import android.text.TextUtils;
32+
import android.util.Log;
3133
import android.view.View;
3234
import android.view.View.OnClickListener;
3335
import android.widget.EditText;
@@ -43,8 +45,11 @@
4345
import com.github.mobile.R.layout;
4446
import com.github.mobile.R.menu;
4547
import com.github.mobile.R.string;
48+
import com.github.mobile.accounts.AccountUtils;
49+
import com.github.mobile.accounts.AuthenticatedUserTask;
4650
import com.github.mobile.core.issue.IssueUtils;
4751
import com.github.mobile.ui.DialogFragmentActivity;
52+
import com.github.mobile.ui.ProgressDialogTask;
4853
import com.github.mobile.ui.StyledText;
4954
import com.github.mobile.ui.TextWatcherAdapter;
5055
import com.github.mobile.util.AvatarLoader;
@@ -100,6 +105,8 @@ public static Intent createIntent(final Issue issue,
100105
return builder.toIntent();
101106
}
102107

108+
private static final String TAG = "EditIssueActivity";
109+
103110
private EditText titleText;
104111

105112
private EditText bodyText;
@@ -155,6 +162,8 @@ protected void onCreate(Bundle savedInstanceState) {
155162
assigneeText = finder.find(id.tv_assignee_name);
156163
labelsText = finder.find(id.tv_labels);
157164

165+
checkCollaboratorStatus();
166+
158167
Intent intent = getIntent();
159168

160169
if (savedInstanceState != null)
@@ -181,6 +190,64 @@ protected void onCreate(Bundle savedInstanceState) {
181190
actionBar.setSubtitle(repository.generateId());
182191
avatars.bind(actionBar, (User) intent.getSerializableExtra(EXTRA_USER));
183192

193+
titleText.addTextChangedListener(new TextWatcherAdapter() {
194+
195+
@Override
196+
public void afterTextChanged(Editable s) {
197+
updateSaveMenu(s);
198+
}
199+
});
200+
201+
updateSaveMenu();
202+
updateView();
203+
}
204+
205+
private void checkCollaboratorStatus() {
206+
new AuthenticatedUserTask<Boolean>(this) {
207+
208+
@Override
209+
public Boolean run(Account account) throws Exception {
210+
return collaboratorService.isCollaborator(repository, AccountUtils.getLogin(EditIssueActivity.this));
211+
}
212+
213+
@Override
214+
protected void onSuccess(Boolean isCollaborator) throws Exception {
215+
super.onSuccess(isCollaborator);
216+
217+
showMainContent();
218+
219+
if(isCollaborator)
220+
showCollaboratorOptions();
221+
}
222+
223+
@Override
224+
protected void onException(Exception e) throws RuntimeException {
225+
super.onException(e);
226+
227+
Log.d(TAG, "Error loading collaborators for issue editing", e);
228+
showMainContent();
229+
}
230+
231+
@Override
232+
public void execute() {
233+
super.execute();
234+
}
235+
236+
private void showMainContent() {
237+
finder.find(id.sv_issue_content).setVisibility(View.VISIBLE);
238+
finder.find(id.pb_loading).setVisibility(View.GONE);
239+
}
240+
}.execute();
241+
}
242+
243+
private void showCollaboratorOptions() {
244+
finder.find(id.tv_milestone_label).setVisibility(View.VISIBLE);
245+
finder.find(id.ll_milestone).setVisibility(View.VISIBLE);
246+
finder.find(id.tv_labels_label).setVisibility(View.VISIBLE);
247+
finder.find(id.ll_labels).setVisibility(View.VISIBLE);
248+
finder.find(id.tv_assignee_label).setVisibility(View.VISIBLE);
249+
finder.find(id.ll_assignee).setVisibility(View.VISIBLE);
250+
184251
findViewById(id.ll_milestone).setOnClickListener(new OnClickListener() {
185252

186253
@Override
@@ -215,17 +282,6 @@ public void onClick(View v) {
215282
labelsDialog.show(issue.getLabels());
216283
}
217284
});
218-
219-
titleText.addTextChangedListener(new TextWatcherAdapter() {
220-
221-
@Override
222-
public void afterTextChanged(Editable s) {
223-
updateSaveMenu(s);
224-
}
225-
});
226-
227-
updateSaveMenu();
228-
updateView();
229285
}
230286

231287
@Override

0 commit comments

Comments
 (0)